diff options
Diffstat (limited to 'src/jcgp/gui/population/GUIOutput.java')
-rw-r--r-- | src/jcgp/gui/population/GUIOutput.java | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java index 87d420e..57042eb 100644 --- a/src/jcgp/gui/population/GUIOutput.java +++ b/src/jcgp/gui/population/GUIOutput.java @@ -21,10 +21,6 @@ import jcgp.population.Output; public class GUIOutput extends GUIGene { - private Circle socket; - - private Label connectionLabel; - private Line sourceLine; private Output output; @@ -52,11 +48,11 @@ public class GUIOutput extends GUIGene { text.setX(-NODE_RADIUS); text.setVisible(true); - socket = new Circle(-NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); + Circle socket = new Circle(-NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); socket.setId(String.valueOf(0)); socket.setStroke(Paint.valueOf("black")); - connectionLabel = new Label("S"); + final Label connectionLabel = new Label("S"); connectionLabel.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5); "); connectionLabel.relocate(socket.getCenterX() + 5, socket.getCenterY() - 10); connectionLabel.setVisible(false); @@ -100,19 +96,27 @@ public class GUIOutput extends GUIGene { socket.addEventFilter(MouseDragEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { - sourceLine.setEndX(event.getX() + ((Circle) event.getSource()).getParent().getLayoutX()); - sourceLine.setEndY(event.getY() + ((Circle) event.getSource()).getParent().getLayoutY()); + if (!parent.isTarget()) { + sourceLine.setEndX(event.getX() + ((Circle) event.getSource()).getParent().getLayoutX()); + sourceLine.setEndY(event.getY() + ((Circle) event.getSource()).getParent().getLayoutY()); + } + } }); socket.addEventFilter(MouseDragEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { - if (event.isDragDetect()) { + if (event.isStillSincePress()) { // mouse was released before dragging out of the socket updateLines(); stateProperty.set(GUIGeneState.HOVER); + } else if (stateProperty.get() == GUIGeneState.SOURCE) { + // no connection has been made, fallback + resetState(); + updateLines(); } + } }); @@ -185,14 +189,9 @@ public class GUIOutput 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.HOVER) { - if (isLocked()) { - - } else { - stateProperty.set(GUIGeneState.NEUTRAL); - setConnections(GUIGeneState.NEUTRAL); - } - + if (stateProperty.get() == GUIGeneState.HOVER && !isLocked()) { + stateProperty.set(GUIGeneState.NEUTRAL); + setConnections(GUIGeneState.NEUTRAL); } } }); @@ -279,8 +278,13 @@ public class GUIOutput extends GUIGene { @Override public void resetState() { - stateProperty.set(GUIGeneState.NEUTRAL); - setConnections(GUIGeneState.NEUTRAL); + if (locked > 0) { + stateProperty.set(GUIGeneState.HOVER); + setConnections(GUIGeneState.HOVER); + } else { + stateProperty.set(GUIGeneState.NEUTRAL); + setConnections(GUIGeneState.NEUTRAL); + } } @Override |