From bc4fafb9d3c60993253f7e78c10338c901de653a Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 24 Mar 2014 17:16:51 +0000 Subject: Node grid all done and apparently stable. --- src/jcgp/gui/population/GUIInput.java | 116 ++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 27 deletions(-) (limited to 'src/jcgp/gui/population/GUIInput.java') diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java index bf872dc..ac1a775 100644 --- a/src/jcgp/gui/population/GUIInput.java +++ b/src/jcgp/gui/population/GUIInput.java @@ -12,8 +12,8 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.GUI; +import jcgp.population.Connection; import jcgp.population.Input; -import jcgp.population.Node; import jcgp.population.Output; public class GUIInput extends GUIGene { @@ -54,13 +54,13 @@ public class GUIInput extends GUIGene { public void handle(MouseDragEvent event) { // the drag has entered this node, react appropriately // this happens even if we are the source of the drag + ((GUIGene) event.getGestureSource()).setConnectionLine((GUIGene) event.getSource()); + if (event.getGestureSource() instanceof GUINode) { - Node source = ((GUINode) event.getGestureSource()).getGene(); - for (int i = 0; i < (int) GUI.resources.get("arity"); i++) { - if (input == source.getConnection(i)) { - stateProperty.set(GUIGeneState.NO_CHANGE_TARGET); - return; - } + Connection source = ((GUINode) event.getGestureSource()).getChangingConnection(); + if (input == source) { + stateProperty.set(GUIGeneState.NO_CHANGE_TARGET); + return; } } else if (event.getGestureSource() instanceof GUIOutput) { Output source = ((GUIOutput) event.getGestureSource()).getGene(); @@ -77,28 +77,45 @@ public class GUIInput extends GUIGene { public void handle(MouseDragEvent event) { // the drag has exited this node, react appropriately // this happens even if we are the source of the drag - if (stateProperty.get() == GUIGeneState.NO_CHANGE_TARGET) { - stateProperty.set(GUIGeneState.INDIRECT_HOVER); - } else { - stateProperty.set(GUIGeneState.NEUTRAL); + parent.setTarget(false); + if (event.isPrimaryButtonDown()) { + if (stateProperty.get() == GUIGeneState.NO_CHANGE_TARGET) { + stateProperty.set(GUIGeneState.INDIRECT_HOVER); + } else { + stateProperty.set(GUIGeneState.NEUTRAL); + ((GUIGene) event.getGestureSource()).setConnections(GUIGeneState.INDIRECT_HOVER); + } } } }); - + addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler() { @Override public void handle(MouseDragEvent event) { + GUIGene source = ((GUIGene) event.getGestureSource()); // set states to reflect the new situation - ((GUIGene) event.getGestureSource()).setState(GUIGeneState.NEUTRAL); - ((GUIGene) event.getGestureSource()).setConnections(GUIGeneState.NEUTRAL); - stateProperty.set(GUIGeneState.HOVER); + if (source.isLocked()) { + source.setState(GUIGeneState.HOVER); + source.setConnections(GUIGeneState.HOVER); + } else { + source.setState(GUIGeneState.NEUTRAL); + source.setConnections(GUIGeneState.NEUTRAL); + } + // the user released the drag gesture on this node, react appropriately - if (event.getGestureSource() instanceof GUINode) { - ((GUINode) event.getGestureSource()).setChangingConnection(input); - } else if (event.getGestureSource() instanceof GUIOutput) { - ((GUIOutput) event.getGestureSource()).getGene().setConnection(0, input); - } + if (source.isLocked()) { + // remove locks from the old connection, add the to the new + // note that the old connection may still have locks after this + parent.getGuiGene(source.getChangingConnection()).removeLocks(source.getLocks()); + source.setChangingConnection(input); + addLocks(source.getLocks()); + } else { + source.setChangingConnection(input); + } + + source.updateLines(); + stateProperty.set(GUIGeneState.HOVER); } }); @@ -107,7 +124,7 @@ public class GUIInput extends GUIGene { public void handle(MouseEvent event) { // cursor has entered this node without dragging, or it is dragging and this is the source if (stateProperty.get() == GUIGeneState.NEUTRAL) { - stateProperty.set(GUIGeneState.INDIRECT_HOVER); + stateProperty.set(GUIGeneState.HOVER); } } }); @@ -116,7 +133,7 @@ public class GUIInput extends GUIGene { @Override public void handle(MouseEvent event) { // cursor has left this node without dragging, or it is dragging and this is the source - if (stateProperty.get() == GUIGeneState.INDIRECT_HOVER) { + if (stateProperty.get() == GUIGeneState.HOVER) { stateProperty.set(GUIGeneState.NEUTRAL); setConnections(GUIGeneState.NEUTRAL); } @@ -129,27 +146,40 @@ public class GUIInput extends GUIGene { switch (newValue) { case ACTIVE_HOVER: - mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR)); + if (locked > 0) { + stateProperty().set(GUIGeneState.LOCKED_HOVER); + } else { + mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR)); + } break; case FORBIDDEN_TARGET: mainCircle.setFill(Paint.valueOf(GUI.BAD_SELECTION_COLOUR)); break; + case LOCKED_HOVER: + mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR)); + break; case HOVER: - mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR)); + mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR)); break; case INDIRECT_HOVER: mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR)); break; case NEUTRAL: - mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_COLOUR)); + if (locked > 0) { + stateProperty.set(GUIGeneState.HOVER); + } else { + mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_COLOUR)); + } break; case NO_CHANGE_TARGET: + parent.setTarget(true); mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_SELECTION_COLOUR)); break; case SOURCE: - mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR)); + mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR)); break; case TARGET: + parent.setTarget(true); mainCircle.setFill(Paint.valueOf(GUI.GOOD_SELECTION_COLOUR)); break; default: @@ -179,11 +209,43 @@ public class GUIInput extends GUIGene { @Override public void resetState() { stateProperty.set(GUIGeneState.NEUTRAL); - } @Override public void setLocked(boolean value) { locked += value ? 1 : -1; + stateProperty.set(locked > 0 ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER); + } + + @Override + public void setChangingConnection(Connection newConnection) { + // do nothing + } + + @Override + public Connection getChangingConnection() { + return null; + } + + @Override + public void addLocks(int value) { + locked += value; + stateProperty.set(locked > 0 ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER); + } + + @Override + public void updateLines() { + // nothing + } + + @Override + public void removeLocks(int value) { + locked -= value; + stateProperty.set(locked > 0 ? GUIGeneState.HOVER : GUIGeneState.NEUTRAL); + } + + @Override + public void setConnectionLine(GUIGene gene) { + // nothing } } -- cgit v1.2.3