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.java48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index 8e2d8a0..2b953c0 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -7,24 +7,29 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
+import jcgp.backend.function.Function;
import jcgp.backend.population.Connection;
import jcgp.backend.population.Input;
import jcgp.backend.population.Node;
+import jcgp.backend.resources.Resources;
import jcgp.gui.GUI;
public class GUINode extends GUIGene {
private Line[] lines;
private Node node;
+ private Resources resources;
private int connectionIndex = 0;
+
- public GUINode(ChromosomePane parentRef, final Node node, Line[] connectionLines) {
+ public GUINode(ChromosomePane parentRef, final Node node, Line[] connectionLines, final GUI gui) {
super();
// store references
this.parent = parentRef;
this.node = node;
this.lines = connectionLines;
+ this.resources = gui.getExperiment().getResources();
// move the GUIGene to the right position
relocate(((node.getColumn() + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS,
@@ -40,12 +45,12 @@ public class GUINode extends GUIGene {
Circle output = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white"));
output.setStroke(Paint.valueOf("black"));
- text.setText(node.getFunction().getName());
+ updateText();
- Circle[] sockets = new Circle[GUI.resources.arity()];
+ Circle[] sockets = new Circle[resources.arity()];
double angle, xPos, yPos;
for (int l = 0; l < sockets.length; l++) {
- angle = (((l + 1) / ((double) (GUI.resources.arity() + 1))) * THETA) - (THETA / 2);
+ angle = (((l + 1) / ((double) (resources.arity() + 1))) * THETA) - (THETA / 2);
xPos = -Math.cos(angle) * NODE_RADIUS;
yPos = Math.sin(angle) * NODE_RADIUS;
@@ -128,7 +133,7 @@ public class GUINode extends GUIGene {
addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
- GUI.functionSelector.relocateAndShow(event, (GUINode) event.getSource());
+ gui.bringFunctionSelector(event, (GUINode) event.getSource());
}
});
@@ -189,17 +194,16 @@ public class GUINode extends GUIGene {
// the user released the drag gesture on this node, react appropriately
if (isAllowed((GUIGene) event.getGestureSource(), (GUIGene) event.getSource())) {
if (source.isLocked()) {
- // remove locks from the old connection, add the to the new
+ // remove locks from the old connection, add the to setConnethe new
// note that the old connection may still have locks after this
parent.getGuiGene(source.getChangingConnection()).removeLocks(source.getLocks());
- source.setChangingConnection(node);
addLocks(source.getLocks());
} else {
if (source instanceof GUIOutput) {
source.resetState();
}
- source.setChangingConnection(node);
}
+ source.setChangingConnection(node);
}
source.updateLines();
@@ -316,7 +320,7 @@ public class GUINode extends GUIGene {
} else if (target instanceof GUINode) {
// target and source are nodes, let's look at levels back
Node t = ((GUINode) target).getGene(), s = ((GUINode) source).getGene();
- if (s.getColumn() - t.getColumn() > 0 && s.getColumn() - t.getColumn() <= GUI.resources.levelsBack()) {
+ if (s.getColumn() - t.getColumn() > 0 && s.getColumn() - t.getColumn() <= resources.levelsBack()) {
return true;
}
return false;
@@ -395,6 +399,9 @@ public class GUINode extends GUIGene {
@Override
public void setChangingConnection(Connection newConnection) {
node.setConnection(connectionIndex, newConnection);
+ if (parent.isEvaluating()) {
+ parent.evaluate(node.getColumn());
+ }
}
@@ -445,7 +452,26 @@ public class GUINode extends GUIGene {
lines[connectionIndex].setEndY(gene.getLayoutY());
}
- public void updateFunction() {
- text.setText(node.getFunction().getName());
+ public void updateText() {
+ if (parent.isEvaluating()) {
+ text.setText(node.getFunction().getName() + "\nValue: " + value.toString());
+ } else {
+ text.setText(node.getFunction().getName());
+ }
+ }
+
+ public void calculate() {
+ value = node.getValue();
+ }
+
+ public void setFunction(Function function) {
+ node.setFunction(function);
+ if (parent.isEvaluating()) {
+ calculate();
+ parent.evaluate(node.getColumn());
+ } else {
+ updateText();
+ }
+
}
}