From 04b35ccdad6e18701ede823e333118b0b22907c2 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 30 Mar 2014 21:07:37 +0100 Subject: Running into some issues with running the CGP loop in the background with bindings. --- src/jcgp/gui/population/ChromosomePane.java | 106 ---------------------------- src/jcgp/gui/population/GUIGene.java | 1 + src/jcgp/gui/population/GUIInput.java | 1 + src/jcgp/gui/population/GUINode.java | 11 ++- src/jcgp/gui/population/GUIOutput.java | 11 +-- 5 files changed, 12 insertions(+), 118 deletions(-) delete mode 100644 src/jcgp/gui/population/ChromosomePane.java (limited to 'src/jcgp/gui/population') diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java deleted file mode 100644 index 7fa8a54..0000000 --- a/src/jcgp/gui/population/ChromosomePane.java +++ /dev/null @@ -1,106 +0,0 @@ -package jcgp.gui.population; - -import java.util.ArrayList; - -import javafx.scene.control.ScrollPane; -import javafx.scene.layout.Pane; -import javafx.scene.shape.Line; -import jcgp.GUI; -import jcgp.population.Chromosome; -import jcgp.population.Connection; -import jcgp.population.Input; -import jcgp.population.Node; - - -public class ChromosomePane extends ScrollPane { - - private GUINode[][] guiNodes; - private GUIInput[] guiInputs; - private GUIOutput[] guiOutputs; - - private Pane content; - - private ArrayList connectionLines; - - private boolean target = false; - - public ChromosomePane(Chromosome chromosome) { - super(); - connectionLines = new ArrayList(); - - //setMouseTransparent(true); - - content = new Pane(); - content.setId("content pane for genes"); - - // generate the GUIGenes - // inputs - guiInputs = new GUIInput[(int) GUI.resources.get("inputs")]; - for (int i = 0; i < guiInputs.length; i++) { - // make the GUI elements - guiInputs[i] = new GUIInput(this, chromosome.getInput(i)); - content.getChildren().addAll(guiInputs[i]); - } - // nodes - guiNodes = new GUINode[(int) GUI.resources.get("rows")][(int) GUI.resources.get("columns")]; - double angle, xPos, yPos; - for (int r = 0; r < guiNodes.length; r++) { - for (int c = 0; c < guiNodes[r].length; c++) { - // make the connection lines - Line lines[] = new Line[(int) GUI.resources.get("arity")]; - for (int l = 0; l < lines.length; l++) { - angle = ((((double) (l + 1)) / ((double) (lines.length + 1))) * GUIGene.THETA) - (GUIGene.THETA / 2); - xPos = (-Math.cos(angle) * GUIGene.NODE_RADIUS) + (((c + 1) * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS); - yPos = (Math.sin(angle) * GUIGene.NODE_RADIUS) + ((r * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS); - - lines[l] = new Line(xPos, yPos, xPos, yPos); - lines[l].setMouseTransparent(true); - lines[l].setVisible(false); - connectionLines.add(lines[l]); - } - // make the GUI elements - guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), lines); - } - content.getChildren().addAll(guiNodes[r]); - } - - // outputs - guiOutputs = new GUIOutput[(int) GUI.resources.get("outputs")]; - for (int i = 0; i < guiOutputs.length; i++) { - xPos = (((int) GUI.resources.get("columns") + 1) * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)); - yPos = (chromosome.getOutput(i).getIndex() * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS; - // make the line - Line line = new Line(xPos, yPos, xPos, yPos); - line.setMouseTransparent(true); - line.setVisible(false); - connectionLines.add(line); - // make the GUI elements - guiOutputs[i] = new GUIOutput(this, chromosome.getOutput(i), line); - content.getChildren().addAll(guiOutputs[i]); - } - - content.getChildren().addAll(connectionLines); - setPrefWidth(620); - setContent(content); - } - - public GUIGene getGuiGene(Connection gene) { - if (gene instanceof Input) { - return guiInputs[((Input) gene).getIndex()]; - } else if (gene instanceof Node) { - return guiNodes[((Node) gene).getRow()][((Node) gene).getColumn()]; - } else { - // something bad happened! - throw new ClassCastException(); - } - - } - - public boolean isTarget() { - return target; - } - - public void setTarget(boolean newValue) { - target = newValue; - } -} diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java index 3addca7..a37eb19 100644 --- a/src/jcgp/gui/population/GUIGene.java +++ b/src/jcgp/gui/population/GUIGene.java @@ -4,6 +4,7 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Group; import javafx.scene.shape.Circle; import javafx.scene.text.Text; +import jcgp.gui.ChromosomePane; import jcgp.population.Connection; import jcgp.population.Gene; diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java index 84e8a2a..30ce4ac 100644 --- a/src/jcgp/gui/population/GUIInput.java +++ b/src/jcgp/gui/population/GUIInput.java @@ -12,6 +12,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.GUI; +import jcgp.gui.ChromosomePane; import jcgp.population.Connection; import jcgp.population.Input; import jcgp.population.Output; diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index eeacb9e..6fc84da 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -14,6 +14,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.GUI; +import jcgp.gui.ChromosomePane; import jcgp.population.Connection; import jcgp.population.Input; import jcgp.population.Node; @@ -56,10 +57,10 @@ public class GUINode extends GUIGene { text.setX(-NODE_RADIUS); text.setVisible(true); - Circle[] sockets = new Circle[(int) GUI.resources.get("arity")]; + Circle[] sockets = new Circle[GUI.resources.getInt("arity")]; double angle, xPos, yPos; for (int l = 0; l < sockets.length; l++) { - angle = ((((double) (l + 1)) / ((double) ((int) GUI.resources.get("arity") + 1))) * THETA) - (THETA / 2); + angle = ((((double) (l + 1)) / ((GUI.resources.getDouble("arity") + 1))) * THETA) - (THETA / 2); xPos = -Math.cos(angle) * NODE_RADIUS; yPos = Math.sin(angle) * NODE_RADIUS; @@ -335,7 +336,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() <= (int) GUI.resources.get("levelsBack")) { + if (s.getColumn() - t.getColumn() > 0 && s.getColumn() - t.getColumn() <= GUI.resources.getInt("levelsBack")) { return true; } return false; @@ -462,4 +463,8 @@ public class GUINode extends GUIGene { lines[connectionIndex].setEndX(gene.getLayoutX() + NODE_RADIUS); lines[connectionIndex].setEndY(gene.getLayoutY()); } + + public void updateFunction() { + text.setText(node.getFunction().getName()); + } } diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java index 57042eb..16d95f0 100644 --- a/src/jcgp/gui/population/GUIOutput.java +++ b/src/jcgp/gui/population/GUIOutput.java @@ -14,6 +14,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import jcgp.GUI; +import jcgp.gui.ChromosomePane; import jcgp.population.Connection; import jcgp.population.Input; import jcgp.population.Node; @@ -31,7 +32,7 @@ public class GUIOutput extends GUIGene { this.output = output; this.sourceLine = line; - relocate((((int) GUI.resources.get("columns") + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS, + relocate(((GUI.resources.getInt("columns") + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS, (output.getIndex() * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS); // set the line ends correctly @@ -242,14 +243,6 @@ public class GUIOutput extends GUIGene { } }); - output.sourceProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, - Connection oldValue, Connection newValue) { - updateLines(); - } - }); - } @Override -- cgit v1.2.3