aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/handlers/NodeHandlers.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/handlers/NodeHandlers.java')
-rw-r--r--src/jcgp/gui/handlers/NodeHandlers.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/jcgp/gui/handlers/NodeHandlers.java b/src/jcgp/gui/handlers/NodeHandlers.java
index 8c9c465..10a334a 100644
--- a/src/jcgp/gui/handlers/NodeHandlers.java
+++ b/src/jcgp/gui/handlers/NodeHandlers.java
@@ -8,21 +8,38 @@ import jcgp.gui.population.GUIGene;
import jcgp.gui.population.GUIGene.GUIGeneState;
import jcgp.gui.population.GUINode;
+/**
+ * Holds the handlers that define the behaviour of {@code GUINode}.
+ * <br><br>
+ * The handlers are instantiated here statically and added to {@code GUINode}
+ * instances using {@code NodeHandlers.addHandlers(...)}. This guarantees that
+ * all nodes behave the same way without instantiating a new set of handlers for
+ * each node instance.
+ *
+ * @author Eduardo Pedroni
+ *
+ */
public final class NodeHandlers {
+ /**
+ * Set the node to {@code GUIGeneState.HOVER} state, and set its immediate connections to {@code GUIGeneState.EXTENDED_HOVER}.
+ */
private static EventHandler<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// acquire the source, we can safely cast it to GUINode
GUINode source = (GUINode) event.getSource();
+
source.setState(GUIGeneState.HOVER);
-
for (int i = 0; i < GUI.resources.arity(); i++) {
((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.EXTENDED_HOVER);
}
}
};
+ /**
+ * Set the node and its immediate connections to {@code GUIGeneState.NEUTRAL} state.
+ */
private static EventHandler<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
@@ -30,13 +47,17 @@ public final class NodeHandlers {
GUINode source = (GUINode) event.getSource();
source.setState(GUIGeneState.NEUTRAL);
-
for (int i = 0; i < GUI.resources.arity(); i++) {
((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.NEUTRAL);
}
}
};
+ /**
+ * Adds all handlers to the specified node.
+ *
+ * @param node the {@code GUINode} to which the handlers will be added.
+ */
public static void addHandlers(GUINode node) {
node.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler);
node.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler);