aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUINode.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/population/GUINode.java')
-rw-r--r--src/jcgp/gui/population/GUINode.java98
1 files changed, 63 insertions, 35 deletions
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index f8f2e20..230d167 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -1,6 +1,5 @@
package jcgp.gui.population;
-import javafx.scene.control.Label;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
@@ -8,63 +7,109 @@ import jcgp.backend.population.Gene;
import jcgp.backend.population.Node;
import jcgp.gui.GUI;
import jcgp.gui.constants.Constants;
+import jcgp.gui.constants.Position;
+import jcgp.gui.handlers.NodeHandlers;
+/**
+ * The GUI counterpart of {@link jcgp.backend.population.Node}. This is a
+ * subclass of {@code GUIGene} which represents a chromosome node.
+ *
+ * @author Eduardo Pedroni
+ */
public class GUINode extends GUIGene implements GUIMutable, GUIConnection {
private Node node;
private Line[] lines;
private Circle[] sockets;
+ /**
+ * Instantiate {@code GUINode} given a {@code Node} and the lines needed
+ * to show its connections.
+ *
+ * @param node the associated backend node.
+ * @param lines the lines used to display connections.
+ */
public GUINode(Node node, Line[] lines) {
super();
- // store references
+ // store references, associate with node
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);
+ node.setGUIObject(this);
- Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
+ // create the output socket
+ Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Constants.SOCKET_COLOUR);
output.setStroke(Paint.valueOf("black"));
+ // create input sockets
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] = new Circle(Constants.SOCKET_RADIUS, Constants.SOCKET_COLOUR);
sockets[l].setStroke(Paint.valueOf("black"));
+ sockets[l].setId(String.valueOf(l));
+ // relocate them
+ Position.placeSocket(l, sockets[l]);
+ Position.connect(lines[l], (GUIGene) ((Gene) node.getConnection(l)).getGUIObject());
}
+ // add elements
getChildren().addAll(sockets);
- getChildren().addAll(output, connectionNumber);
+ getChildren().add(output);
+
+ // relocate node, add handlers
+ Position.place(this);
+ NodeHandlers.addHandlers(this);
}
+ /**
+ * @return the {@code Node} instance associated with this object.
+ */
public Node getNode() {
return node;
}
- void setNode(Node node2) {
- // TODO Auto-generated method stub
-
+ /**
+ * Associates this instance with a new node.
+ *
+ * @param node the new node.
+ */
+ void setNode(Node node) {
+ this.node = node;
}
+ /**
+ * Returns one of this object's connection lines. Lines are
+ * indexed in the same order as sockets and the connections
+ * they represent.
+ *
+ * @param index the line to return.
+ * @return the indexed line object.
+ */
public Line getLine(int index) {
return lines[index];
}
+ /**
+ * @return the entire {@code Line} array.
+ */
public Line[] getLines() {
return lines;
}
+ /**
+ * Returns one of this object's connection sockets. They are
+ * indexed in the same order as lines and the connections
+ * they represent.
+ *
+ * @param index the socket to return.
+ * @return the indexed socket object.
+ */
public Circle getSocket(int index) {
return sockets[index];
}
+ /**
+ * @return the entire {@code Socket} array.
+ */
public Circle[] getSockets() {
return sockets;
}
@@ -83,21 +128,4 @@ public class GUINode extends GUIGene implements GUIMutable, GUIConnection {
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);
-// }
-// }
-// }
-
}