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 mouseEnteredHandler = new EventHandler() { @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); } } }; private static EventHandler mouseExitedHandler = new EventHandler() { @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); 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); } }