package jcgp.gui.population; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.paint.Paint; import javafx.scene.shape.Circle; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.gui.constants.Constants; /** * Defines the general behaviour of the visual representation of each chromosome gene. *

* In practice, this is subclass of {@code javafx.scene.Group} containing a {@code Circle} * object and a {@code Text} object. Subclasses may add further elements to the group, for * instance to display connection input and output sockets. * * @author Eduardo Pedroni * */ public abstract class GUIGene extends Group { public enum GUIGeneState { NEUTRAL, HOVER, EXTENDED_HOVER, ACTIVE_HOVER } private GUIGeneState currentState = GUIGeneState.NEUTRAL; private Text text = new Text(); private Circle mainCircle = new Circle(Constants.NODE_RADIUS, Paint.valueOf(Constants.NEUTRAL_COLOUR)); /** * Initialises the {@code Text} and {@code Circle} objects so that all genes are standardised. */ protected GUIGene() { text.setFont(Font.font("Arial", 12)); text.setTextOrigin(VPos.CENTER); text.setTextAlignment(TextAlignment.CENTER); text.setWrappingWidth(Constants.NODE_RADIUS * 2); text.setX(-Constants.NODE_RADIUS); text.setVisible(true); mainCircle.setStroke(Paint.valueOf("black")); getChildren().addAll(mainCircle, text); } /** * Sets the gene's text field. * * @param newText the text string to be displayed. */ public void setText(String newText) { text.setText(newText); } public GUIGeneState getState() { return currentState; } public void setState(GUIGeneState newState) { switch (newState) { case NEUTRAL: mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR)); setLinesVisible(false); break; case HOVER: mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR)); setLinesVisible(true); break; case EXTENDED_HOVER: mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR)); setLinesVisible(false); break; case ACTIVE_HOVER: mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR)); setLinesVisible(true); break; default: break; } currentState = newState; } protected abstract void setLinesVisible(boolean value); }