diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2014-11-15 23:30:20 +0000 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2014-11-15 23:30:20 +0000 |
commit | d0718fe4762f6a50ec851085cb5d0e6d39ccc1b0 (patch) | |
tree | 44ba8a6db7beb8000141ba33a8b5a7bbc2f90580 /src/jcgp/gui/population/GUINode.java | |
parent | 12ebe6f6375e7db31ba1bb2eba5e3b28b51c7a19 (diff) |
Added GUIConnection and GUIMutable, started reintroducing lines but positioning is not working correctly.
Diffstat (limited to 'src/jcgp/gui/population/GUINode.java')
-rw-r--r-- | src/jcgp/gui/population/GUINode.java | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index 7b59162..6b6bafc 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -1,19 +1,60 @@ package jcgp.gui.population; +import javafx.scene.control.Label; import javafx.scene.paint.Paint; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Line; +import jcgp.backend.population.Input; import jcgp.backend.population.Node; +import jcgp.gui.GUI; import jcgp.gui.constants.Constants; -public class GUINode extends GUIGene { +public abstract class GUINode extends GUIConnection implements GUIMutable { private Node node; + private Line[] connectionLines; - - public GUINode(final Node node) { + public GUINode(Node node, Line[] connectionLines) { super(); - // store references this.node = node; + this.connectionLines = connectionLines; + + 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); + + Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white")); + output.setStroke(Paint.valueOf("black")); + + Circle[] sockets = new Circle[GUI.resources.arity()]; + double angle, xPos, yPos; + for (int l = 0; l < sockets.length; l++) { + angle = (((l + 1) / ((double) (GUI.resources.arity() + 1))) * Constants.THETA) - (Constants.THETA / 2); + xPos = -Math.cos(angle) * Constants.NODE_RADIUS; + yPos = Math.sin(angle) * Constants.NODE_RADIUS; + + sockets[l] = new Circle(xPos, yPos, Constants.SOCKET_RADIUS, Paint.valueOf("white")); + sockets[l].setId(String.valueOf(l)); + sockets[l].setStroke(Paint.valueOf("black")); + } + + getChildren().addAll(sockets); + getChildren().addAll(output, connectionNumber); + + for (int l = 0; l < connectionLines.length; l++) { + if (node.getConnection(l) instanceof Node) { + int row = ((Node) node.getConnection(l)).getRow(), + column = ((Node) node.getConnection(l)).getColumn(); + connectionLines[l].setEndX(((column + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + 2 * Constants.NODE_RADIUS); + connectionLines[l].setEndY((row * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS); + } else if (node.getConnection(l) instanceof Input) { + int inputIndex = ((Input) node.getConnection(l)).getIndex(); + connectionLines[l].setEndX(2 * Constants.NODE_RADIUS); + connectionLines[l].setEndY(inputIndex * (2 * Constants.NODE_RADIUS + Constants.SPACING) + Constants.NODE_RADIUS); + } + } + } public Node getNode() { @@ -27,12 +68,26 @@ public class GUINode extends GUIGene { @Override public void mouseEnter() { - mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR)); + setState(GUIGeneState.HOVER); + for (int i = 0; i < GUI.resources.arity(); i++) { + getGUIConnection(node.getConnection(i)).setState(GUIGeneState.EXTENDED_HOVER); + } } @Override public void mouseExit() { - mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR)); + setState(GUIGeneState.NEUTRAL); + for (int i = 0; i < GUI.resources.arity(); i++) { + getGUIConnection(node.getConnection(i)).setState(GUIGeneState.NEUTRAL); + } + } + + @Override + public void activeHover(boolean value) { + setState(value ? GUIGeneState.EXTENDED_HOVER : GUIGeneState.NEUTRAL); + for (int i = 0; i < GUI.resources.arity(); i++) { + getGUIConnection(node.getConnection(i)).activeHover(value); + } } } |