aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/handlers')
-rw-r--r--src/jcgp/gui/handlers/GUIHandlers.java27
-rw-r--r--src/jcgp/gui/handlers/InputHandlers.java31
-rw-r--r--src/jcgp/gui/handlers/NodeHandlers.java54
-rw-r--r--src/jcgp/gui/handlers/OutputHandlers.java39
4 files changed, 124 insertions, 27 deletions
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<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent event) {
- ((GUIGene) event.getSource()).mouseEnter();
- }
- };
-
- private static final EventHandler<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() {
- @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<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ //((GUIGene) event.getSource()).mouseEnter();
+ ((GUIInput) event.getSource()).setState(GUIGeneState.HOVER);
+ }
+ };
+
+ private static EventHandler<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() {
+ @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<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);
+ }
+}
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<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() {
+ @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<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() {
+ @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);
+ }
+
+}