diff options
Diffstat (limited to 'src/jcgp/gui/handlers/NodeHandlers.java')
-rw-r--r-- | src/jcgp/gui/handlers/NodeHandlers.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/jcgp/gui/handlers/NodeHandlers.java b/src/jcgp/gui/handlers/NodeHandlers.java new file mode 100644 index 0000000..9d1f6a8 --- /dev/null +++ b/src/jcgp/gui/handlers/NodeHandlers.java @@ -0,0 +1,54 @@ +package jcgp.gui.handlers; + +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; +import jcgp.backend.population.Gene; +import jcgp.gui.GUI; +import jcgp.gui.population.GUIGene; +import jcgp.gui.population.GUIGene.GUIGeneState; +import jcgp.gui.population.GUINode; + +public final class NodeHandlers { + + 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); + + /* + * What have I done? Have I gone too far? + * Have I unleashed an evil beyond control? + * Will the gods of type casting ever forgive me? + */ + for (int i = 0; i < GUI.resources.arity(); i++) { + ((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.EXTENDED_HOVER); + } + } + }; + + private static EventHandler<MouseEvent> mouseExitedHandler = 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.NEUTRAL); + + /* + * Is this the end? Is there any hope for salvation? + * Am I damned beyond redemption? + */ + for (int i = 0; i < GUI.resources.arity(); i++) { + ((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.NEUTRAL); + } + } + }; + + public static void addHandlers(GUINode node) { + node.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler); + node.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler); + } +} |