diff options
Diffstat (limited to 'src/jcgp/gui/population/ChromosomePane.java')
-rw-r--r-- | src/jcgp/gui/population/ChromosomePane.java | 90 |
1 files changed, 15 insertions, 75 deletions
diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java index bf9db72..7826dcc 100644 --- a/src/jcgp/gui/population/ChromosomePane.java +++ b/src/jcgp/gui/population/ChromosomePane.java @@ -6,20 +6,13 @@ import javafx.scene.control.ScrollPane; import javafx.scene.layout.Pane; import javafx.scene.shape.Line; import jcgp.backend.population.Chromosome; -import jcgp.backend.population.Gene; -import jcgp.backend.population.Input; import jcgp.backend.population.Node; -import jcgp.backend.population.Output; import jcgp.gui.GUI; -import jcgp.gui.constants.Position; -import jcgp.gui.handlers.InputHandlers; -import jcgp.gui.handlers.NodeHandlers; -import jcgp.gui.handlers.OutputHandlers; /** * This extension of {@code ScrollPane} contains a series of * nodes, inputs and outputs spread across a grid. It also contains - * all of the connection lines overlaid over the nodes, inputs and outputs. + * all of the connection lines laid over the nodes, inputs and outputs. * * * @author Eduardo Pedroni @@ -33,8 +26,6 @@ public class ChromosomePane extends ScrollPane { private Pane content; - private int rows, columns; - private boolean target = false; public ChromosomePane(Chromosome chromosome) { @@ -42,58 +33,39 @@ public class ChromosomePane extends ScrollPane { ArrayList<Line> connectionLines = new ArrayList<Line>(); - rows = GUI.resources.rows(); - columns = GUI.resources.columns(); + int rows = GUI.resources.rows(); + int columns = GUI.resources.columns(); content = new Pane(); content.setId("content pane for genes"); - // generate the GUIGenes /* * inputs */ guiInputs = new GUIInput[GUI.resources.inputs()]; for (int i = 0; i < guiInputs.length; i++) { - // get the backend input - Input input = chromosome.getInput(i); - // make the GUI elements - guiInputs[i] = new GUIInput(input); - // assign the GUI object to the associated backend element - input.setGUIObject(guiInputs[i]); - // position, handlers - Position.place(guiInputs[i]); - InputHandlers.addHandlers(guiInputs[i]); + guiInputs[i] = new GUIInput(chromosome.getInput(i)); } + // add inputs to content pane content.getChildren().addAll(guiInputs); /* * nodes */ guiNodes = new GUINode[rows][columns]; - //double angle, xPos, yPos; - for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { - // get the backend node - Node node = chromosome.getNode(r, c); // make the connection lines Line lines[] = new Line[GUI.resources.arity()]; for (int l = 0; l < lines.length; l++) { lines[l] = new Line(); - - Position.connect(lines[l], (GUIGene) ((Gene) node.getConnection(l)).getGUIObject()); - lines[l].setMouseTransparent(true); lines[l].setVisible(false); connectionLines.add(lines[l]); } - // make the GUI elements - guiNodes[r][c] = new GUINode(node, lines); - // assign the GUI object to the associated backend element - node.setGUIObject(guiNodes[r][c]); - // position, handlers - Position.place(guiNodes[r][c]); - NodeHandlers.addHandlers(guiNodes[r][c]); + // make the GUI element + guiNodes[r][c] = new GUINode(chromosome.getNode(r, c), lines); + // add node to content pane content.getChildren().add(guiNodes[r][c]); } } @@ -103,45 +75,24 @@ public class ChromosomePane extends ScrollPane { */ guiOutputs = new GUIOutput[GUI.resources.outputs()]; for (int i = 0; i < guiOutputs.length; i++) { - // get the backend output - Output output = chromosome.getOutput(i); - // make the GUI elements + // make the connection line Line line = new Line(); - Position.connect(line, (GUIGene) ((Gene) output.getSource()).getGUIObject()); line.setVisible(false); line.setMouseTransparent(true); - guiOutputs[i] = new GUIOutput(output, line); - // assign the GUI object to the associated backend element - output.setGUIObject(guiOutputs[i]); - // position, handlers - Position.place(guiOutputs[i]); - OutputHandlers.addHandlers(guiOutputs[i]); connectionLines.add(line); + // make the GUI element + guiOutputs[i] = new GUIOutput(chromosome.getOutput(i), line); } + // add outputs to content pane content.getChildren().addAll(guiOutputs); // add lines to the pane on top of genes content.getChildren().addAll(connectionLines); - setPrefWidth(620); + setPrefWidth(620); setContent(content); } - - /* - * does this work lol - */ - // protected 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(); - // } - // } - protected boolean isTarget() { return target; } @@ -151,8 +102,8 @@ public class ChromosomePane extends ScrollPane { } public void updateGenes(Chromosome chr) { - for (int r = 0; r < rows; r++) { - for (int c = 0; c < columns; c++) { + for (int r = 0; r < GUI.resources.rows(); r++) { + for (int c = 0; c < GUI.resources.columns(); c++) { guiNodes[r][c].setNode(chr.getNode(r, c)); } } @@ -186,15 +137,4 @@ public class ChromosomePane extends ScrollPane { // if the source was neither node nor output, something bad is happening throw new ClassCastException("Source was neither GUINode nor GUIOutput."); } - - // private GUIConnection getGUIConnection(Connection connection) { - // if (connection instanceof Input) { - // return guiInputs[((Input) connection).getIndex()]; - // } else if (connection instanceof Node) { - // return guiNodes[((Node) connection).getRow()][((Node) connection).getColumn()]; - // } else { - // // something bad happened! - // throw new ClassCastException(); - // } - // } } |