From 9d24ea7759c58e7b1fd4b8c37acc7d16cb7e55fa Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 18 Nov 2014 19:26:18 +0000 Subject: Refactored handlers, separated into input, node and output files. Genes are less functional now, ChromosomePane will deal with hand-wired connections. --- src/jcgp/gui/population/GUINode.java | 78 ++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'src/jcgp/gui/population/GUINode.java') diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index 6b6bafc..f8f2e20 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -4,21 +4,22 @@ 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.Gene; import jcgp.backend.population.Node; import jcgp.gui.GUI; import jcgp.gui.constants.Constants; -public abstract class GUINode extends GUIConnection implements GUIMutable { +public class GUINode extends GUIGene implements GUIMutable, GUIConnection { private Node node; - private Line[] connectionLines; + private Line[] lines; + private Circle[] sockets; - public GUINode(Node node, Line[] connectionLines) { + public GUINode(Node node, Line[] lines) { super(); // store references this.node = node; - this.connectionLines = connectionLines; + 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);"); @@ -27,7 +28,7 @@ public abstract class GUINode extends GUIConnection implements GUIMutable { 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()]; + 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); @@ -41,20 +42,6 @@ public abstract class GUINode extends GUIConnection implements GUIMutable { 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() { @@ -65,29 +52,52 @@ public abstract class GUINode extends GUIConnection implements GUIMutable { // TODO Auto-generated method stub } - - @Override - public void mouseEnter() { - setState(GUIGeneState.HOVER); - for (int i = 0; i < GUI.resources.arity(); i++) { - getGUIConnection(node.getConnection(i)).setState(GUIGeneState.EXTENDED_HOVER); - } + + 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 mouseExit() { - setState(GUIGeneState.NEUTRAL); + public void setStateRecursively(GUIGeneState state) { + setState(state); for (int i = 0; i < GUI.resources.arity(); i++) { - getGUIConnection(node.getConnection(i)).setState(GUIGeneState.NEUTRAL); + ((GUIConnection) ((Gene) node.getConnection(i)).getGUIObject()).setStateRecursively(state); } } @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); + 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); +// } +// } +// } + } -- cgit v1.2.3