Estructuras_de_Datos/src/cl/cromer/estructuras/Colores.java

207 lines
3.7 KiB
Java
Raw Normal View History

2016-06-20 13:25:01 -04:00
package cl.cromer.estructuras;
import javafx.scene.paint.Color;
2016-07-11 01:12:51 -04:00
import java.util.Random;
import java.util.prefs.Preferences;
2016-07-11 01:12:51 -04:00
2016-06-20 13:25:01 -04:00
/**
2016-07-16 16:28:25 -04:00
* Rotación y generación de colores.
2016-06-29 00:33:19 -04:00
*
2016-06-20 13:25:01 -04:00
* @author Chris Cromer
*/
public class Colores {
2016-07-03 11:28:26 -04:00
/**
* Cuantos colores estan definidos en esta clase.
*/
static final public int MAX_COLORS = 7;
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* El color actual en forma numerica.
*/
private int color;
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* El color de texto actual.
*/
private Color texto;
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* El color de fondo actual.
*/
private Color fondo;
2016-06-20 13:25:01 -04:00
2016-07-04 11:38:26 -04:00
/**
* El color de border actual.
*/
private Color border;
2016-07-03 11:28:26 -04:00
/**
* Inicializar el primer color.
*/
public Colores() {
siguinteColor();
}
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* Cambiar el color al siguinte. Si no hay, voler al primer.
*/
public void siguinteColor() {
int colorsToUse;
Preferences preferences = (Preferences) Main.stage.getUserData();
if (preferences != null) {
colorsToUse = preferences.getInt("colors", MAX_COLORS);
}
else {
colorsToUse = MAX_COLORS;
}
if (colorsToUse <= color) {
color = 0;
}
2016-07-03 11:28:26 -04:00
switch (color) {
case 1:
color = 2;
texto = Color.WHITE;
fondo = Color.RED;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
case 2:
color = 3;
texto = Color.BLACK;
fondo = Color.WHITE;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
case 3:
color = 4;
texto = Color.BLACK;
fondo = Color.PINK;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
case 4:
color = 5;
texto = Color.BLACK;
fondo = Color.YELLOW;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
case 5:
color = 6;
2016-07-11 01:12:51 -04:00
texto = Color.WHITE;
2016-07-03 11:28:26 -04:00
fondo = Color.GREEN;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
case 6:
color = 7;
texto = Color.BLACK;
fondo = Color.ORANGE;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
break;
default:
color = 1;
texto = Color.WHITE;
fondo = Color.BLUE;
2016-07-04 11:38:26 -04:00
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
}
2016-07-16 16:28:25 -04:00
}
/**
* Cambiar el color al siguinte. Si no hay, voler al primer.
*/
public void colorAleatorio() {
Random random = new Random();
int maximo = MAX_COLORS;
int minimo = 1;
int rango = maximo - minimo + 1;
int color = random.nextInt(rango) + minimo;
2016-07-11 01:12:51 -04:00
2016-07-16 16:28:25 -04:00
switch (color) {
case 1:
this.color = 2;
texto = Color.WHITE;
fondo = Color.RED;
border = Color.BLACK;
break;
case 2:
this.color = 3;
texto = Color.BLACK;
fondo = Color.WHITE;
border = Color.BLACK;
break;
case 3:
this.color = 4;
texto = Color.BLACK;
fondo = Color.PINK;
border = Color.BLACK;
break;
case 4:
this.color = 5;
texto = Color.BLACK;
fondo = Color.YELLOW;
border = Color.BLACK;
break;
case 5:
this.color = 6;
texto = Color.WHITE;
fondo = Color.GREEN;
border = Color.BLACK;
break;
case 6:
this.color = 7;
texto = Color.BLACK;
fondo = Color.ORANGE;
border = Color.BLACK;
break;
default:
this.color = 1;
texto = Color.WHITE;
fondo = Color.BLUE;
border = Color.BLACK;
}
2016-07-11 01:12:51 -04:00
}
2016-07-16 16:28:25 -04:00
/**
* Generar colores al azar.
*/
public void randomColorGenrator() {
2016-07-11 01:12:51 -04:00
int r = (int)(Math.random() * 256);
int g = (int)(Math.random() * 256);
int b = (int)(Math.random() * 256);
fondo = Color.rgb(r, g, b);
// Generate a text color that doesn't conflict
double a = 1 - (0.299 * r + 0.587 * g + 0.114 * b) / 255;
texto = (a > 0.5)?Color.WHITE: Color.BLACK;
border = Color.BLACK;
2016-07-03 11:28:26 -04:00
}
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* Devolver el color del texto actual.
*
* @return Color: Color del texto.
*/
public Color getTexto() {
return texto;
}
2016-06-20 13:25:01 -04:00
2016-07-03 11:28:26 -04:00
/**
* Devolver el color del fondo actual.
*
* @return Color: Color del fondo.
*/
public Color getFondo() {
return fondo;
}
2016-07-04 11:38:26 -04:00
/**
* Devolver el color del border actual.
*
* @return Color: Color del border.
*/
public Color getBorder() {
return border;
}
2016-06-20 13:25:01 -04:00
}