aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUIGene.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/population/GUIGene.java')
-rw-r--r--src/jcgp/gui/population/GUIGene.java63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java
index 032d217..d6f9638 100644
--- a/src/jcgp/gui/population/GUIGene.java
+++ b/src/jcgp/gui/population/GUIGene.java
@@ -21,33 +21,55 @@ import jcgp.gui.constants.Constants;
*/
public abstract class GUIGene extends Group {
+ /**
+ * This {@code enum} type defines a finite list of all states
+ * a gene can take. Each state represents a particular steady
+ * situation, and has its own GUI appearance associated with it:
+ * a combination of connection line visibility, gene background colour
+ * and other visual characteristics.
+ *
+ * @author Eduardo Pedroni
+ *
+ */
public enum GUIGeneState {
+ /**
+ * No user interaction at all.
+ */
NEUTRAL,
+ /**
+ * User is simply hovering over the node.
+ */
HOVER,
+ /**
+ * User is hovering over a node connected to this one.
+ */
EXTENDED_HOVER,
+ /**
+ * User is hovering over an output connected to this gene.
+ */
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));
+ private Text text;
+ private Circle mainCircle;
/**
* Initialises the {@code Text} and {@code Circle} objects so that all genes are standardised.
*/
protected GUIGene() {
+ text = new Text();
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 = new Circle(Constants.NODE_RADIUS, Constants.NEUTRAL_COLOUR);
mainCircle.setStroke(Paint.valueOf("black"));
getChildren().addAll(mainCircle, text);
-
}
/**
@@ -59,26 +81,43 @@ public abstract class GUIGene extends Group {
text.setText(newText);
}
+ /**
+ * @return the gene's current state.
+ */
public GUIGeneState getState() {
return currentState;
}
- public void setState(GUIGeneState newState) {
+ /**
+ * Gene states are standardised: all gene subclasses behave the same way in each state.
+ * <br>
+ * This design choice was made for the sake of consistency. Rather than controlling the
+ * appearance of the genes with logic in the state transition method AND the mouse handlers,
+ * the states are now consistent across all types of gene. The mouse handlers implement
+ * whatever logic is necessary to determine the gene's new state given a certain user input,
+ * but the states themselves are the same for all genes.
+ * <br>
+ * The transition logic for each type of gene is defined in its respective handler class:
+ * {@code InputHandlers}, {@code NodeHandlers} and {@code OutputHandlers}.
+ *
+ * @param newState the gene's new state.
+ */
+ public final void setState(GUIGeneState newState) {
switch (newState) {
case NEUTRAL:
- mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR));
+ mainCircle.setFill(Constants.NEUTRAL_COLOUR);
setLinesVisible(false);
break;
case HOVER:
- mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Constants.MEDIUM_HIGHLIGHT_COLOUR);
setLinesVisible(true);
break;
case EXTENDED_HOVER:
- mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Constants.SOFT_HIGHLIGHT_COLOUR);
setLinesVisible(false);
break;
case ACTIVE_HOVER:
- mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Constants.SOFT_HIGHLIGHT_COLOUR);
setLinesVisible(true);
break;
@@ -88,5 +127,11 @@ public abstract class GUIGene extends Group {
currentState = newState;
}
+ /**
+ * For the sake of practicality, all {@code GUIGene} instances must implement this
+ * method. It sets the visibility of all of the gene's lines, if it has any.
+ *
+ * @param value the visibility value.
+ */
protected abstract void setLinesVisible(boolean value);
}