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.Gene; import jcgp.backend.population.Node; import jcgp.gui.GUI; import jcgp.gui.constants.Constants; public class GUINode extends GUIGene implements GUIMutable, GUIConnection { private Node node; private Line[] lines; private Circle[] sockets; public GUINode(Node node, Line[] lines) { super(); // store references this.node = node; this.lines = lines; 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")); 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); } public Node getNode() { return node; } void setNode(Node node2) { // TODO Auto-generated method stub } public Line getLine(int index) { return lines[index]; } public Line[] getLines() { return lines; } public Circle getSocket(int index) { return sockets[index]; } public Circle[] getSockets() { return sockets; } @Override public void setStateRecursively(GUIGeneState state) { setState(state); for (int i = 0; i < GUI.resources.arity(); i++) { ((GUIConnection) ((Gene) node.getConnection(i)).getGUIObject()).setStateRecursively(state); } } @Override protected void setLinesVisible(boolean value) { for (int i = 0; i < lines.length; i++) { lines[i].setVisible(value); } } // @Override // public void updateLines() { // 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) + Constants.SOCKET_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); // } // } // } }