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.CGP.Resources; import jcgp.population.Chromosome; public class ChromosomePane extends ScrollPane { private GUINode[][] guiNodes; private GUIInput[] guiInputs; private GUIOutput[] guiOutputs; private Pane content; private ArrayList connectionLines; public ChromosomePane(Chromosome chromosome, Resources resources) { super(); connectionLines = new ArrayList(); content = new Pane(); content.setId("content pane for genes"); // generate the GUIGenes // inputs guiInputs = new GUIInput[(int) 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")]; 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")]; 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), resources, lines); } content.getChildren().addAll(guiNodes[r]); } // outputs guiOutputs = new GUIOutput[(int) resources.get("outputs")]; for (int i = 0; i < guiOutputs.length; i++) { xPos = (((int) 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), resources, line); content.getChildren().addAll(guiOutputs[i]); } content.getChildren().addAll(connectionLines); setPrefWidth(620); setContent(content); } 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 Pane getContentPane() { return content; } }