2016-06-20 13:25:01 -04:00
|
|
|
package cl.cromer.estructuras;
|
|
|
|
|
|
|
|
import javafx.animation.Animation;
|
|
|
|
import javafx.animation.PauseTransition;
|
|
|
|
import javafx.animation.SequentialTransition;
|
|
|
|
import javafx.scene.Scene;
|
2016-06-26 23:34:33 -04:00
|
|
|
import javafx.scene.layout.Pane;
|
2016-06-20 13:25:01 -04:00
|
|
|
import javafx.scene.layout.StackPane;
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
import javafx.scene.shape.Circle;
|
2016-06-25 14:14:17 -04:00
|
|
|
import javafx.scene.shape.Line;
|
2016-06-26 13:03:04 -04:00
|
|
|
import javafx.scene.shape.Polygon;
|
2016-06-20 13:25:01 -04:00
|
|
|
import javafx.scene.shape.Rectangle;
|
|
|
|
import javafx.scene.text.Text;
|
|
|
|
import javafx.util.Duration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Esta clase es para trabajar con graficos.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @author Chris Cromer
|
|
|
|
*/
|
|
|
|
public class Grafico {
|
2016-06-23 21:31:27 -04:00
|
|
|
/**
|
|
|
|
* Tipo de dibujo rectuangular.
|
|
|
|
*/
|
|
|
|
static final public int RECTANGULO = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tipo de dibujo circular.
|
|
|
|
*/
|
|
|
|
static final public int CIRCULO = 1;
|
2016-06-29 00:33:19 -04:00
|
|
|
/**
|
|
|
|
* La escena donde está cosas graficas.
|
|
|
|
*/
|
|
|
|
final private Scene scene;
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Contiene la animación de destacar.
|
|
|
|
*/
|
|
|
|
private SequentialTransition blinkTransition;
|
|
|
|
/**
|
|
|
|
* El valor de cual caja está destacado actualmente
|
|
|
|
*/
|
|
|
|
private int destacado;
|
|
|
|
/**
|
|
|
|
* El tipo de objeto que está destacado.
|
|
|
|
*/
|
2016-06-23 21:31:27 -04:00
|
|
|
private int tipo;
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* El color original de fondo para volver cuando no es destacado.
|
|
|
|
*/
|
|
|
|
private Color destacadoBG;
|
|
|
|
/**
|
|
|
|
* El color original de text para volver cuando no es destacado.
|
|
|
|
*/
|
|
|
|
private Color destacadoFG;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Graficar una escena.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param scene La scene a destacar.
|
|
|
|
*/
|
|
|
|
public Grafico(Scene scene) {
|
|
|
|
this.scene = scene;
|
|
|
|
destacado = -1;
|
|
|
|
}
|
|
|
|
|
2016-06-26 13:03:04 -04:00
|
|
|
/**
|
|
|
|
* Crear una flecha que apunta por abajo.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-26 13:03:04 -04:00
|
|
|
* @return StackPane: Devolver el stackpane que contiene la flecha.
|
|
|
|
*/
|
|
|
|
public static StackPane crearFlechaAbajo() {
|
|
|
|
Polygon polygon = new Polygon();
|
|
|
|
polygon.getPoints().addAll(
|
2016-06-29 00:33:19 -04:00
|
|
|
0.0, 0.0,
|
|
|
|
10.0, 0.0,
|
|
|
|
5.0, 10.0
|
2016-06-26 13:03:04 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
StackPane stackPane = new StackPane();
|
|
|
|
stackPane.getChildren().addAll(polygon);
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crear una flecha que apunta por arriba.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-26 13:03:04 -04:00
|
|
|
* @return StackPane: Devolver el stackpane que contiene la flecha.
|
|
|
|
*/
|
|
|
|
public static StackPane crearFlechaArriba() {
|
|
|
|
Polygon polygon = new Polygon();
|
|
|
|
polygon.getPoints().addAll(
|
2016-06-29 00:33:19 -04:00
|
|
|
5.0, 0.0,
|
|
|
|
0.0, 10.0,
|
|
|
|
10.0, 10.0
|
2016-06-26 13:03:04 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
StackPane stackPane = new StackPane();
|
|
|
|
stackPane.getChildren().addAll(polygon);
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
2016-06-25 14:14:17 -04:00
|
|
|
/**
|
2016-06-26 23:34:33 -04:00
|
|
|
* Crear una linea vertical.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-25 14:14:17 -04:00
|
|
|
* @return StackPane: Devolver el stackpane que contiene la linea vertical.
|
|
|
|
*/
|
|
|
|
public static StackPane crearLineaVertical() {
|
|
|
|
Line line = new Line();
|
|
|
|
line.setStartX(20);
|
|
|
|
line.setEndX(20);
|
|
|
|
line.setStartY(0);
|
|
|
|
line.setEndY(20);
|
|
|
|
|
|
|
|
StackPane stackPane = new StackPane();
|
|
|
|
stackPane.getChildren().addAll(line);
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
2016-06-26 23:34:33 -04:00
|
|
|
/**
|
|
|
|
* Crear la linea circular con flecha.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-26 23:34:33 -04:00
|
|
|
* @param cajas int: La cantidad de cajas que están.
|
|
|
|
* @return StackPane: Devolver el stackpane que contiene la linea horizontal.
|
|
|
|
*/
|
|
|
|
public static Pane crearLineaCircular(int cajas) {
|
|
|
|
int height = (cajas - 1) * (40 + 20 + 10);
|
|
|
|
height = height + 20 + 10;
|
|
|
|
|
|
|
|
Line top = new Line();
|
|
|
|
top.setStartY(20);
|
|
|
|
top.setEndY(20);
|
|
|
|
top.setStartX(0);
|
|
|
|
top.setEndX(20);
|
|
|
|
|
|
|
|
Polygon flechaDerecha = new Polygon();
|
|
|
|
flechaDerecha.getPoints().addAll(
|
2016-06-29 00:33:19 -04:00
|
|
|
10.0, 15.0,
|
|
|
|
20.0, 20.0,
|
|
|
|
10.0, 25.0
|
2016-06-26 23:34:33 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
Line vertical = new Line();
|
|
|
|
vertical.setStartY(20);
|
|
|
|
vertical.setEndY(height);
|
|
|
|
|
|
|
|
Line bottom = new Line();
|
|
|
|
bottom.setStartY(height);
|
|
|
|
bottom.setEndY(height);
|
|
|
|
bottom.setStartX(0);
|
|
|
|
bottom.setEndX(20);
|
|
|
|
|
|
|
|
|
|
|
|
Pane stackPane = new Pane();
|
|
|
|
stackPane.getChildren().addAll(top, flechaDerecha, vertical, bottom);
|
|
|
|
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Crear un rectangulo con texto adentro.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param colores Colores: Los colores para dar color al rectangulo.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param label String: El texto por el ID de fxml.
|
2016-06-20 13:25:01 -04:00
|
|
|
* @return StackPane: Devolver el stackpane que contiene el rectangulo y texto.
|
|
|
|
*/
|
|
|
|
public static StackPane crearCaja(Colores colores, String label) {
|
|
|
|
Rectangle rectangle = new Rectangle();
|
|
|
|
rectangle.setHeight(40);
|
|
|
|
rectangle.setWidth(40);
|
|
|
|
rectangle.setFill(colores.getFondo());
|
|
|
|
rectangle.setStroke(Color.BLACK);
|
|
|
|
rectangle.setId("border_" + label);
|
|
|
|
Text text = new Text();
|
|
|
|
text.setId("caja_" + label);
|
|
|
|
text.setStroke(colores.getTexto());
|
|
|
|
|
|
|
|
StackPane stackPane = new StackPane();
|
|
|
|
stackPane.getChildren().addAll(rectangle, text);
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crear un rectangulo con texto adentro.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param colores Colores: Los colores para dar color al rectangulo.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param label String: El texto por el ID de fxml.
|
|
|
|
* @param texto String: El texto a colocar dentro el rectangulo.
|
2016-06-20 13:25:01 -04:00
|
|
|
* @return StackPane: Devolver el stackpane que contiene el rectangulo y texto.
|
|
|
|
*/
|
|
|
|
public static StackPane crearCaja(Colores colores, String label, String texto) {
|
|
|
|
Rectangle rectangle = new Rectangle();
|
|
|
|
rectangle.setHeight(40);
|
|
|
|
rectangle.setWidth(40);
|
|
|
|
rectangle.setFill(colores.getFondo());
|
|
|
|
rectangle.setStroke(Color.BLACK);
|
|
|
|
rectangle.setId("border_" + label);
|
|
|
|
Text text = new Text();
|
|
|
|
text.setId("caja_" + label);
|
|
|
|
text.setStroke(colores.getTexto());
|
|
|
|
text.setText(texto);
|
|
|
|
|
|
|
|
StackPane stackPane = new StackPane();
|
2016-06-25 14:14:17 -04:00
|
|
|
stackPane.getChildren().addAll(rectangle, text);
|
|
|
|
return stackPane;
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:28:09 -04:00
|
|
|
/**
|
|
|
|
* Crear un animacion de transicion usando colores que cambian.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
|
|
|
* @param rectangle Rectangle: El objeto que desea animar.
|
|
|
|
* @param text Text: El texto que desea animar.
|
2016-06-28 12:13:08 -04:00
|
|
|
* @param colorBackground Color: Color del fondo de destacar.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param colorText Color: Color del texto.
|
2016-06-20 13:28:09 -04:00
|
|
|
* @return PauseTransition: La transition creado con los elementos y colores.
|
|
|
|
*/
|
2016-06-29 00:33:19 -04:00
|
|
|
private static PauseTransition createPauseTransition(Rectangle rectangle, Text text, Color colorBackground, Color colorText) {
|
2016-06-20 13:28:09 -04:00
|
|
|
PauseTransition changeColor = new PauseTransition(new Duration(100));
|
|
|
|
changeColor.setOnFinished(actionEvent -> {
|
|
|
|
rectangle.setFill(colorBackground);
|
|
|
|
text.setStroke(colorText);
|
|
|
|
});
|
2016-06-29 00:33:19 -04:00
|
|
|
return changeColor;
|
2016-06-20 13:28:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crear un animacion de transicion usando colores que cambian.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
|
|
|
* @param circle Circle: El objeto que desea animar.
|
|
|
|
* @param text Text: El texto que desea animar.
|
2016-06-28 12:13:08 -04:00
|
|
|
* @param colorBackground Color: Color del fondo de destacar.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param colorText Color: Color del texto.
|
2016-06-20 13:28:09 -04:00
|
|
|
* @return PauseTransition: La transition creado con los elementos y colores.
|
|
|
|
*/
|
2016-06-29 00:33:19 -04:00
|
|
|
private static PauseTransition createPauseTransition(Circle circle, Text text, Color colorBackground, Color colorText) {
|
2016-06-20 13:28:09 -04:00
|
|
|
PauseTransition changeColor = new PauseTransition(new Duration(100));
|
|
|
|
changeColor.setOnFinished(actionEvent -> {
|
|
|
|
circle.setFill(colorBackground);
|
|
|
|
text.setStroke(colorText);
|
|
|
|
});
|
2016-06-29 00:33:19 -04:00
|
|
|
return changeColor;
|
2016-06-20 13:28:09 -04:00
|
|
|
}
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Destacar un elemento
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param valor int: El indice a destacar.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param tipo int: El tipo de objeto a destacar, {@value #RECTANGULO} o {@value #CIRCULO}
|
2016-06-20 13:25:01 -04:00
|
|
|
*/
|
2016-06-28 12:13:08 -04:00
|
|
|
public void destacar(int valor, int tipo) {
|
2016-06-23 21:31:27 -04:00
|
|
|
if (tipo != RECTANGULO && tipo != CIRCULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-06-23 21:31:27 -04:00
|
|
|
else {
|
|
|
|
this.tipo = tipo;
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
destacado = valor;
|
|
|
|
Colores colores = new Colores();
|
|
|
|
Rectangle rectangle = null;
|
|
|
|
Circle circle = null;
|
2016-06-23 21:31:27 -04:00
|
|
|
if (this.tipo == RECTANGULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
rectangle = (Rectangle) scene.lookup("#border_" + String.valueOf(valor));
|
|
|
|
destacadoBG = (Color) rectangle.getFill();
|
|
|
|
}
|
2016-06-23 21:31:27 -04:00
|
|
|
else if (this.tipo == CIRCULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
circle = (Circle) scene.lookup("#border_" + String.valueOf(valor));
|
|
|
|
destacadoBG = (Color) circle.getFill();
|
|
|
|
}
|
|
|
|
Text text = (Text) scene.lookup("#caja_" + String.valueOf(valor));
|
|
|
|
destacadoFG = (Color) text.getStroke();
|
|
|
|
PauseTransition changeColor[] = new PauseTransition[Colores.MAX_COLORS];
|
|
|
|
for (int i = 0; i < Colores.MAX_COLORS; i++) {
|
2016-06-23 21:31:27 -04:00
|
|
|
if (this.tipo == RECTANGULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
changeColor[i] = createPauseTransition(rectangle, text, colores.getFondo(), colores.getTexto());
|
|
|
|
}
|
2016-06-23 21:31:27 -04:00
|
|
|
else if (this.tipo == CIRCULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
changeColor[i] = createPauseTransition(circle, text, colores.getFondo(), colores.getTexto());
|
|
|
|
}
|
|
|
|
colores.siguinteColor();
|
|
|
|
}
|
|
|
|
blinkTransition = new SequentialTransition(changeColor);
|
|
|
|
blinkTransition.setCycleCount(Animation.INDEFINITE);
|
|
|
|
blinkTransition.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remover el efecto de destacar.
|
|
|
|
*/
|
|
|
|
public void removerDestacar() {
|
|
|
|
if (destacado != -1) {
|
|
|
|
blinkTransition.stop();
|
2016-06-23 21:31:27 -04:00
|
|
|
if (tipo == RECTANGULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
Rectangle rectangle = (Rectangle) scene.lookup("#border_" + String.valueOf(destacado));
|
|
|
|
rectangle.setFill(destacadoBG);
|
|
|
|
}
|
2016-06-23 21:31:27 -04:00
|
|
|
else if (tipo == CIRCULO) {
|
2016-06-20 13:25:01 -04:00
|
|
|
Circle circle = (Circle) scene.lookup("#border_" + String.valueOf(destacado));
|
|
|
|
circle.setFill(destacadoBG);
|
|
|
|
}
|
|
|
|
Text text = (Text) scene.lookup("#caja_" + String.valueOf(destacado));
|
|
|
|
text.setStroke(destacadoFG);
|
|
|
|
destacado = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|