diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-24 17:16:51 +0000 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-03-24 17:16:51 +0000 |
commit | bc4fafb9d3c60993253f7e78c10338c901de653a (patch) | |
tree | b62e6cacc72c0c8ff645744fdaf2ca007f1fc891 /src/jcgp/gui/population/ChromosomePane.java | |
parent | a09124d93c3e31d4e25ffe6c2f0a7663c02c35ed (diff) |
Node grid all done and apparently stable.
Diffstat (limited to 'src/jcgp/gui/population/ChromosomePane.java')
-rw-r--r-- | src/jcgp/gui/population/ChromosomePane.java | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java index 546314e..0c7b3d2 100644 --- a/src/jcgp/gui/population/ChromosomePane.java +++ b/src/jcgp/gui/population/ChromosomePane.java @@ -5,8 +5,11 @@ import java.util.ArrayList; import javafx.scene.control.ScrollPane; import javafx.scene.layout.Pane; import javafx.scene.shape.Line; -import jcgp.CGP.Resources; +import jcgp.GUI; import jcgp.population.Chromosome; +import jcgp.population.Connection; +import jcgp.population.Input; +import jcgp.population.Node; public class ChromosomePane extends ScrollPane { @@ -19,7 +22,9 @@ public class ChromosomePane extends ScrollPane { private ArrayList<Line> connectionLines; - public ChromosomePane(Chromosome chromosome, Resources resources) { + private boolean target = false; + + public ChromosomePane(Chromosome chromosome) { super(); connectionLines = new ArrayList<Line>(); @@ -28,19 +33,19 @@ public class ChromosomePane extends ScrollPane { // generate the GUIGenes // inputs - guiInputs = new GUIInput[(int) resources.get("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) resources.get("rows")][(int) resources.get("columns")]; + 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) resources.get("arity")]; + 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); @@ -52,15 +57,15 @@ public class ChromosomePane extends ScrollPane { connectionLines.add(lines[l]); } // make the GUI elements - guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), resources, lines); + guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), lines); } content.getChildren().addAll(guiNodes[r]); } // outputs - guiOutputs = new GUIOutput[(int) resources.get("outputs")]; + guiOutputs = new GUIOutput[(int) GUI.resources.get("outputs")]; for (int i = 0; i < guiOutputs.length; i++) { - xPos = (((int) resources.get("columns") + 1) * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)); + 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); @@ -68,7 +73,7 @@ public class ChromosomePane extends ScrollPane { line.setVisible(false); connectionLines.add(line); // make the GUI elements - guiOutputs[i] = new GUIOutput(this, chromosome.getOutput(i), resources, line); + guiOutputs[i] = new GUIOutput(this, chromosome.getOutput(i), line); content.getChildren().addAll(guiOutputs[i]); } @@ -78,20 +83,41 @@ public class ChromosomePane extends ScrollPane { } - public GUINode getGuiNode(int row, int column) { - return guiNodes[row][column]; - } - - public GUIInput getGuiInput(int index) { - return guiInputs[index]; - } +// public GUINode getGuiNode(int row, int column) { +// return guiNodes[row][column]; +// } +// +// public GUIInput getGuiInput(int index) { +// return guiInputs[index]; +// } +// +// public GUIOutput getGuiOutput(int index) { +// return guiOutputs[index]; +// } - public GUIOutput getGuiOutput(int index) { - return guiOutputs[index]; + 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 Pane getContentPane() { return content; } + + + public boolean isTarget() { + return target; + } + + public void setTarget(boolean newValue) { + target = newValue; + } } |