diff options
Diffstat (limited to 'src/jcgp/gui/population')
-rw-r--r-- | src/jcgp/gui/population/ChromosomePane.java | 21 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIGene.java | 2 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIInput.java | 3 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUINode.java | 74 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIOutput.java | 42 |
5 files changed, 55 insertions, 87 deletions
diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java index 0c7b3d2..7fa8a54 100644 --- a/src/jcgp/gui/population/ChromosomePane.java +++ b/src/jcgp/gui/population/ChromosomePane.java @@ -28,6 +28,8 @@ public class ChromosomePane extends ScrollPane { super(); connectionLines = new ArrayList<Line>(); + //setMouseTransparent(true); + content = new Pane(); content.setId("content pane for genes"); @@ -82,19 +84,6 @@ public class ChromosomePane extends ScrollPane { setContent(content); } - -// public GUINode getGuiNode(int row, int column) { -// return guiNodes[row][column]; -// } -// -// public GUIInput getGuiInput(int index) { -// return guiInputs[index]; -// } -// -// public GUIOutput getGuiOutput(int index) { -// return guiOutputs[index]; -// } - public GUIGene getGuiGene(Connection gene) { if (gene instanceof Input) { return guiInputs[((Input) gene).getIndex()]; @@ -107,11 +96,6 @@ public class ChromosomePane extends ScrollPane { } - public Pane getContentPane() { - return content; - } - - public boolean isTarget() { return target; } @@ -119,5 +103,4 @@ public class ChromosomePane extends ScrollPane { public void setTarget(boolean newValue) { target = newValue; } - } diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java index 1be662e..3addca7 100644 --- a/src/jcgp/gui/population/GUIGene.java +++ b/src/jcgp/gui/population/GUIGene.java @@ -27,7 +27,7 @@ public abstract class GUIGene extends Group { public static final double THETA = Math.PI / 1.4; public static final double SOCKET_RADIUS = Math.sqrt(NODE_RADIUS) / 1.8; - public static final double NODE_TEXT = 0; + public static final double NODE_TEXT = NODE_RADIUS / 2.5; protected Text text; protected Circle mainCircle; diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java index ac1a775..84e8a2a 100644 --- a/src/jcgp/gui/population/GUIInput.java +++ b/src/jcgp/gui/population/GUIInput.java @@ -18,7 +18,6 @@ import jcgp.population.Output; public class GUIInput extends GUIGene { - private Circle outputSocket; private Input input; public GUIInput(ChromosomePane parentRef, final Input input) { @@ -40,7 +39,7 @@ public class GUIInput extends GUIGene { text.setX(-NODE_RADIUS); text.setVisible(true); - outputSocket = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); + Circle outputSocket = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); outputSocket.setId(String.valueOf(0)); outputSocket.setStroke(Paint.valueOf("black")); diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index dd20006..eeacb9e 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -14,23 +14,14 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.GUI; -import jcgp.function.Function; import jcgp.population.Connection; import jcgp.population.Input; import jcgp.population.Node; -import jcgp.population.Output; public class GUINode extends GUIGene { - private Circle[] sockets; - private Circle output; - private Line[] lines; - - private Label connectionNumber; - private Node node; - private int connectionIndex = 0; public GUINode(ChromosomePane parentRef, final Node node, Line[] connectionLines) { @@ -39,7 +30,7 @@ public class GUINode extends GUIGene { this.parent = parentRef; this.node = node; this.lines = connectionLines; - + // move the GUIGene to the right position relocate(((node.getColumn() + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS, (node.getRow() * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS); @@ -47,32 +38,25 @@ public class GUINode extends GUIGene { // set the line ends correctly updateLines(); - connectionNumber = new Label(); + final Label connectionNumber = new Label(); connectionNumber.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5); "); connectionNumber.setVisible(false); - output = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); + Circle output = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white")); output.setStroke(Paint.valueOf("black")); mainCircle = new Circle(NODE_RADIUS, Paint.valueOf("white")); mainCircle.setStroke(Paint.valueOf("black")); text = new Text(node.getFunction().getName()); - this.node.functionProperty().addListener(new ChangeListener<Function>() { - @Override - public void changed(ObservableValue<? extends Function> observable, - Function oldValue, Function newValue) { - text.setText(newValue.getName()); - } - }); - text.setFont(Font.font("Arial", 12)); + text.setFont(Font.font("Arial", NODE_TEXT)); text.setTextOrigin(VPos.CENTER); text.setTextAlignment(TextAlignment.CENTER); text.setWrappingWidth(NODE_RADIUS * 2); text.setX(-NODE_RADIUS); text.setVisible(true); - sockets = new Circle[(int) GUI.resources.get("arity")]; + Circle[] sockets = new Circle[(int) GUI.resources.get("arity")]; double angle, xPos, yPos; for (int l = 0; l < sockets.length; l++) { angle = ((((double) (l + 1)) / ((double) ((int) GUI.resources.get("arity") + 1))) * THETA) - (THETA / 2); @@ -137,11 +121,15 @@ public class GUINode extends GUIGene { s.addEventFilter(MouseDragEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override - public void handle(MouseEvent event) { - if (event.isDragDetect()) { + public void handle(MouseEvent event) { + if (event.isStillSincePress()) { // mouse was released before dragging out of the socket updateLine(index); stateProperty.set(GUIGeneState.HOVER); + } else if (stateProperty.get() == GUIGeneState.SOURCE) { + // no connection has been made, fallback + resetState(); + updateLines(); } } }); @@ -157,19 +145,13 @@ public class GUINode extends GUIGene { // this happens even if we are the source of the drag if (isAllowed((GUIGene) event.getGestureSource(), (GUIGene) event.getSource())) { ((GUIGene) event.getGestureSource()).setConnectionLine((GUIGene) event.getSource()); - if (event.getGestureSource() instanceof GUINode) { - Connection source = ((GUINode) event.getGestureSource()).getChangingConnection(); - if (node == source) { - stateProperty.set(GUIGeneState.NO_CHANGE_TARGET); - return; - } - } else if (event.getGestureSource() instanceof GUIOutput) { - Output source = ((GUIOutput) event.getGestureSource()).getGene(); - if (((GUIGene) event.getSource()).getGene() == source.getSource()) { - ((GUIGene) event.getSource()).setState(GUIGeneState.NO_CHANGE_TARGET); - } + + Connection source = ((GUIGene) event.getGestureSource()).getChangingConnection(); + if (node == source) { + stateProperty.set(GUIGeneState.NO_CHANGE_TARGET); + } else { + stateProperty.set(GUIGeneState.TARGET); } - stateProperty.set(GUIGeneState.TARGET); } else { stateProperty.set(GUIGeneState.FORBIDDEN_TARGET); } @@ -289,7 +271,7 @@ public class GUINode extends GUIGene { case HOVER: mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR)); showLines(true); - if ((oldValue != GUIGeneState.LOCKED_HOVER || oldValue != GUIGeneState.SOURCE) && locked <= 0) { + if (locked <= 0) { setConnections(GUIGeneState.INDIRECT_HOVER); } else { setConnections(GUIGeneState.HOVER); @@ -326,16 +308,16 @@ public class GUINode extends GUIGene { } }); - for (int c = 0; c < lines.length; c++) { - final int i = c; - node.connections().get(c).addListener(new ChangeListener<Connection>() { - @Override - public void changed(ObservableValue<? extends Connection> observable, - Connection oldValue, Connection newValue) { - updateLine(i); - } - }); - } +// for (int c = 0; c < lines.length; c++) { +// final int i = c; +// node.connections().get(c).addListener(new ChangeListener<Connection>() { +// @Override +// public void changed(ObservableValue<? extends Connection> observable, +// Connection oldValue, Connection newValue) { +// updateLine(i); +// } +// }); +// } } 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 |