From 9d24ea7759c58e7b1fd4b8c37acc7d16cb7e55fa Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 18 Nov 2014 19:26:18 +0000 Subject: Refactored handlers, separated into input, node and output files. Genes are less functional now, ChromosomePane will deal with hand-wired connections. --- src/jcgp/gui/handlers/GUIHandlers.java | 27 ---------------- src/jcgp/gui/handlers/InputHandlers.java | 31 ++++++++++++++++++ src/jcgp/gui/handlers/NodeHandlers.java | 54 +++++++++++++++++++++++++++++++ src/jcgp/gui/handlers/OutputHandlers.java | 39 ++++++++++++++++++++++ 4 files changed, 124 insertions(+), 27 deletions(-) delete mode 100644 src/jcgp/gui/handlers/GUIHandlers.java create mode 100644 src/jcgp/gui/handlers/InputHandlers.java create mode 100644 src/jcgp/gui/handlers/NodeHandlers.java create mode 100644 src/jcgp/gui/handlers/OutputHandlers.java (limited to 'src/jcgp/gui/handlers') diff --git a/src/jcgp/gui/handlers/GUIHandlers.java b/src/jcgp/gui/handlers/GUIHandlers.java deleted file mode 100644 index ca2a324..0000000 --- a/src/jcgp/gui/handlers/GUIHandlers.java +++ /dev/null @@ -1,27 +0,0 @@ -package jcgp.gui.handlers; - -import javafx.event.EventHandler; -import javafx.scene.input.MouseEvent; -import jcgp.gui.population.GUIGene; - -public class GUIHandlers { - - private static final EventHandler mouseEnteredHandler = new EventHandler() { - @Override - public void handle(MouseEvent event) { - ((GUIGene) event.getSource()).mouseEnter(); - } - }; - - private static final EventHandler mouseExitedHandler = new EventHandler() { - @Override - public void handle(MouseEvent event) { - ((GUIGene) event.getSource()).mouseExit(); - } - }; - - public static void addHandlers(GUIGene gene) { - gene.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler); - gene.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler); - } -} diff --git a/src/jcgp/gui/handlers/InputHandlers.java b/src/jcgp/gui/handlers/InputHandlers.java new file mode 100644 index 0000000..d0a8812 --- /dev/null +++ b/src/jcgp/gui/handlers/InputHandlers.java @@ -0,0 +1,31 @@ +package jcgp.gui.handlers; + +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; +import jcgp.gui.population.GUIGene.GUIGeneState; +import jcgp.gui.population.GUIInput; + +public final class InputHandlers { + + private static EventHandler mouseEnteredHandler = new EventHandler() { + @Override + public void handle(MouseEvent event) { + //((GUIGene) event.getSource()).mouseEnter(); + ((GUIInput) event.getSource()).setState(GUIGeneState.HOVER); + } + }; + + private static EventHandler mouseExitedHandler = new EventHandler() { + @Override + public void handle(MouseEvent event) { + //((GUIGene) event.getSource()).mouseExit(); + ((GUIInput) event.getSource()).setState(GUIGeneState.NEUTRAL); + } + }; + + public static void addHandlers(GUIInput input) { + input.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler); + input.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler); + } + +} 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 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); + + /* + * 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 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); + + /* + * 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); + } +} diff --git a/src/jcgp/gui/handlers/OutputHandlers.java b/src/jcgp/gui/handlers/OutputHandlers.java new file mode 100644 index 0000000..31d6380 --- /dev/null +++ b/src/jcgp/gui/handlers/OutputHandlers.java @@ -0,0 +1,39 @@ +package jcgp.gui.handlers; + +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; +import jcgp.backend.population.Gene; +import jcgp.gui.population.GUIConnection; +import jcgp.gui.population.GUIGene.GUIGeneState; +import jcgp.gui.population.GUIOutput; + +public final class OutputHandlers { + + private static EventHandler mouseEnteredHandler = new EventHandler() { + @Override + public void handle(MouseEvent event) { + // acquire the source, we can safely cast it to GUIOutput + GUIOutput source = (GUIOutput) event.getSource(); + + source.setState(GUIGeneState.HOVER); + ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.ACTIVE_HOVER); + } + }; + + private static EventHandler mouseExitedHandler = new EventHandler() { + @Override + public void handle(MouseEvent event) { + // acquire the source, we can safely cast it to GUIOutput + GUIOutput source = (GUIOutput) event.getSource(); + + source.setState(GUIGeneState.NEUTRAL); + ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.NEUTRAL); + } + }; + + public static void addHandlers(GUIOutput output) { + output.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler); + output.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler); + } + +} -- cgit v1.2.3