diff options
Diffstat (limited to 'src/jcgp/gui')
-rw-r--r-- | src/jcgp/gui/GUIConsole.java | 12 | ||||
-rw-r--r-- | src/jcgp/gui/SettingsPane.java | 266 | ||||
-rw-r--r-- | src/jcgp/gui/population/ChromosomePane.java | 106 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIGene.java | 1 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIInput.java | 1 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUINode.java | 11 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIOutput.java | 11 | ||||
-rw-r--r-- | src/jcgp/gui/settings/GUIBooleanParameter.java | 24 | ||||
-rw-r--r-- | src/jcgp/gui/settings/GUIDoubleParameter.java | 33 | ||||
-rw-r--r-- | src/jcgp/gui/settings/GUIIntegerParameter.java | 31 | ||||
-rw-r--r-- | src/jcgp/gui/settings/GUIParameter.java | 14 |
11 files changed, 23 insertions, 487 deletions
diff --git a/src/jcgp/gui/GUIConsole.java b/src/jcgp/gui/GUIConsole.java index a14a23b..15ef2f6 100644 --- a/src/jcgp/gui/GUIConsole.java +++ b/src/jcgp/gui/GUIConsole.java @@ -1,5 +1,10 @@ package jcgp.gui; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import javafx.application.Platform; import javafx.event.EventHandler; import javafx.scene.Cursor; import javafx.scene.control.TextArea; @@ -17,7 +22,12 @@ public class GUIConsole extends AnchorPane { textArea.setEditable(false); textArea.setWrapText(true); - //setStyle("-fx-border-width: 5 0 0 0; -fx-border-color: #D1D1D1"); +// System.setOut(new PrintStream(new OutputStream() { +// @Override +// public void write(final int b) throws IOException { +// textArea.appendText(String.valueOf((char) b)); +// } +// })); setResizeListeners(); diff --git a/src/jcgp/gui/SettingsPane.java b/src/jcgp/gui/SettingsPane.java deleted file mode 100644 index 594147f..0000000 --- a/src/jcgp/gui/SettingsPane.java +++ /dev/null @@ -1,266 +0,0 @@ -package jcgp.gui; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.geometry.Insets; -import javafx.scene.Cursor; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.VBox; -import javafx.scene.text.Font; -import javafx.scene.text.Text; -import jcgp.GUI; -import jcgp.JCGP; -import jcgp.function.FunctionSet; -import jcgp.gui.settings.GUIBooleanParameter; -import jcgp.gui.settings.GUIDoubleParameter; -import jcgp.gui.settings.GUIIntegerParameter; -import jcgp.gui.settings.GUIParameter; -import jcgp.modules.ea.EvolutionaryAlgorithm; -import jcgp.modules.fitness.FitnessFunction; -import jcgp.modules.mutator.Mutator; -import jcgp.parameters.BooleanParameter; -import jcgp.parameters.DoubleParameter; -import jcgp.parameters.IntegerParameter; -import jcgp.parameters.Parameter; - -public class SettingsPane extends AnchorPane { - - private VBox mainContainer, eas, mutators, ffs; - private boolean dragging = false; - - public SettingsPane(JCGP cgp) { - super(); - setResizeListeners(); - - //setStyle("-fx-border-width: 0 0 0 5; -fx-border-color: #D1D1D1"); - - mainContainer = new VBox(); - - AnchorPane.setTopAnchor(mainContainer, 0.0); - AnchorPane.setBottomAnchor(mainContainer, 0.0); - AnchorPane.setRightAnchor(mainContainer, 0.0); - AnchorPane.setLeftAnchor(mainContainer, GUI.RESIZE_MARGIN); - mainContainer.setPadding(new Insets(5, 0, 0, 0)); - mainContainer.setSpacing(6); - - setMinWidth(GUI.SETTINGS_WIDTH); - setPrefWidth(GUI.SETTINGS_WIDTH); - - makeBaseParameters(cgp); - makeEAParameters(cgp); - mainContainer.getChildren().add(eas); - - makeMutatorParameters(cgp); - mainContainer.getChildren().add(mutators); - - makeFitnessFunctionParameters(cgp); - mainContainer.getChildren().add(ffs); - - makeNodeFunctionParameters(cgp); - - getChildren().add(mainContainer); - } - - private void makeBaseParameters(JCGP cgp) { - VBox vb = new VBox(); - vb.setSpacing(2); - - Text header = new Text("Base Parameters"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - vb.getChildren().add(header); - - ArrayList<GUIParameter> gp = new ArrayList<GUIParameter>(); - - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("rows"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("columns"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("inputs"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("outputs"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("levelsBack"))); - - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("popSize"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("generations"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("runs"))); - - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("seed"))); - gp.add(new GUIIntegerParameter((IntegerParameter) cgp.getResources().getParameter("report"))); - gp.add(new GUIBooleanParameter((BooleanParameter) cgp.getResources().getParameter("debug"))); - - vb.getChildren().addAll(gp); - - mainContainer.getChildren().add(vb); - } - - private void makeEAParameters(JCGP cgp) { - eas = new VBox(); - eas.setSpacing(2); - - Text header = new Text("EA"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - eas.getChildren().add(header); - - ComboBox<EvolutionaryAlgorithm> eab = new ComboBox<EvolutionaryAlgorithm>(); - eab.getItems().addAll(cgp.getEvolutionaryAlgorithms()); - eab.getSelectionModel().select(cgp.getEvolutionaryAlgorithm()); - eab.prefWidthProperty().bind(mainContainer.widthProperty()); - eas.getChildren().add(eab); - - addParameters(cgp.getEvolutionaryAlgorithm().getLocalParameters().entrySet().iterator(), eas); - } - - private void makeMutatorParameters(JCGP cgp) { - mutators = new VBox(); - mutators.setSpacing(2); - - Text header = new Text("Mutator"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - mutators.getChildren().add(header); - - ComboBox<Mutator> mb = new ComboBox<Mutator>(); - mb.getItems().addAll(cgp.getMutators()); - mb.getSelectionModel().select(cgp.getMutator()); - mb.prefWidthProperty().bind(mainContainer.widthProperty()); - mutators.getChildren().add(mb); - - addParameters(cgp.getMutator().getLocalParameters().entrySet().iterator(), mutators); - } - - private void makeFitnessFunctionParameters(JCGP cgp) { - ffs = new VBox(); - ffs.setSpacing(2); - - Text header = new Text("Fitness Function"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - ffs.getChildren().add(header); - - ComboBox<FitnessFunction> ff = new ComboBox<FitnessFunction>(); - ff.getItems().addAll(cgp.getFitnessFunctions()); - ff.getSelectionModel().select(cgp.getFitnessFunction()); - ff.prefWidthProperty().bind(mainContainer.widthProperty()); - ffs.getChildren().add(ff); - - addParameters(cgp.getFitnessFunction().getLocalParameters().entrySet().iterator(), ffs); - } - - private void makeNodeFunctionParameters(JCGP cgp) { - VBox vb = new VBox(); - vb.setSpacing(2); - - Text header = new Text("Node Functions"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - vb.getChildren().add(header); - - ComboBox<FunctionSet> nf = new ComboBox<FunctionSet>(); - nf.getItems().addAll(cgp.getResources().getFunctionSets()); - nf.getSelectionModel().select(cgp.getResources().getFunctionSet()); - nf.prefWidthProperty().bind(mainContainer.widthProperty()); - vb.getChildren().add(nf); - - // TODO make this function re-usable - addFunctions(cgp.getResources().getFunctionSet(), vb); - - mainContainer.getChildren().add(vb); - } - - /** - * @param cgp - * @param vb - */ - private void addParameters(Iterator<Entry<String, Parameter>> it, VBox vb) { - while (it.hasNext()) { - Parameter parameter = ((Map.Entry<String, Parameter>) it.next()).getValue(); - if (parameter instanceof IntegerParameter) { - vb.getChildren().add(new GUIIntegerParameter((IntegerParameter) parameter)); - } else if (parameter instanceof DoubleParameter) { - vb.getChildren().add(new GUIDoubleParameter((DoubleParameter) parameter)); - } else if (parameter instanceof BooleanParameter) { - vb.getChildren().add(new GUIBooleanParameter((BooleanParameter) parameter)); - } - } - } - - private void addFunctions(final FunctionSet fs, VBox vb) { - CheckBox cb; - for (int i = 0; i < fs.getTotalFunctionCount(); i++) { - cb = new CheckBox(fs.getFunction(i).getName()); - cb.setId(String.valueOf(i)); - cb.setSelected(true); - final int index = i; - cb.setOnAction(new EventHandler<ActionEvent>() { - @Override - public void handle(ActionEvent event) { - if (((CheckBox) event.getSource()).isSelected()) { - fs.enableFunction(index); - } else { - fs.disableFunction(index); - } - } - }); - vb.getChildren().add(cb); - } - } - - private void setResizeListeners() { - setOnMousePressed(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(isInDraggableZone(event)) { - dragging = true; - } - } - }); - setOnMouseDragged(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(dragging) { - double newWidth = getWidth() - event.getX(); - if (newWidth >= getMinWidth()) { - setPrefWidth(newWidth); - } else { - setPrefWidth(getMinWidth()); - } - } - } - }); - setOnMouseMoved(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(isInDraggableZone(event) || dragging) { - setCursor(Cursor.H_RESIZE); - } - else { - setCursor(Cursor.DEFAULT); - } - } - }); - setOnMouseReleased(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - dragging = false; - setCursor(Cursor.DEFAULT); - } - }); - } - - private boolean isInDraggableZone(MouseEvent event) { - return event.getX() < (GUI.RESIZE_MARGIN); - } - -} 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<Line> connectionLines; - - private boolean target = false; - - public ChromosomePane(Chromosome chromosome) { - super(); - connectionLines = new ArrayList<Line>(); - - //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<Connection>() { - @Override - public void changed(ObservableValue<? extends Connection> observable, - Connection oldValue, Connection newValue) { - updateLines(); - } - }); - } @Override diff --git a/src/jcgp/gui/settings/GUIBooleanParameter.java b/src/jcgp/gui/settings/GUIBooleanParameter.java deleted file mode 100644 index 7b20c3b..0000000 --- a/src/jcgp/gui/settings/GUIBooleanParameter.java +++ /dev/null @@ -1,24 +0,0 @@ -package jcgp.gui.settings; - -import javafx.geometry.Pos; -import javafx.scene.control.CheckBox; -import jcgp.parameters.BooleanParameter; - -public class GUIBooleanParameter extends GUIParameter { - - public GUIBooleanParameter(BooleanParameter parameter) { - setAlignment(Pos.CENTER_LEFT); - setSpacing(5); - - this.parameter = parameter; - - value = new CheckBox(parameter.getName()); - ((CheckBox) value).setSelected(parameter.getValue()); - - value.setDisable(parameter.isManaged()); - - getChildren().add(value); - - } - -} diff --git a/src/jcgp/gui/settings/GUIDoubleParameter.java b/src/jcgp/gui/settings/GUIDoubleParameter.java deleted file mode 100644 index d61899b..0000000 --- a/src/jcgp/gui/settings/GUIDoubleParameter.java +++ /dev/null @@ -1,33 +0,0 @@ -package jcgp.gui.settings; - -import javafx.geometry.Pos; -import javafx.scene.control.TextField; -import javafx.scene.layout.Priority; -import javafx.scene.text.Text; -import jcgp.GUI; -import jcgp.parameters.DoubleParameter; - -public class GUIDoubleParameter extends GUIParameter { - - public GUIDoubleParameter(DoubleParameter parameter) { - setAlignment(Pos.CENTER_LEFT); - setSpacing(5); - - this.parameter = parameter; - - name = new Text(parameter.getName()); - value = new TextField(String.valueOf(parameter.getValue())); - - ((TextField) value).setAlignment(Pos.CENTER_RIGHT); - - setHgrow(value, Priority.ALWAYS); - - name.setWrappingWidth(GUI.WRAP_WIDTH); - - value.setDisable(parameter.isManaged()); - - getChildren().addAll(name, value); - - } - -} diff --git a/src/jcgp/gui/settings/GUIIntegerParameter.java b/src/jcgp/gui/settings/GUIIntegerParameter.java deleted file mode 100644 index b7a23a4..0000000 --- a/src/jcgp/gui/settings/GUIIntegerParameter.java +++ /dev/null @@ -1,31 +0,0 @@ -package jcgp.gui.settings; - -import javafx.geometry.Pos; -import javafx.scene.control.TextField; -import javafx.scene.layout.Priority; -import javafx.scene.text.Text; -import jcgp.GUI; -import jcgp.parameters.IntegerParameter; - -public class GUIIntegerParameter extends GUIParameter { - - public GUIIntegerParameter(IntegerParameter parameter) { - setAlignment(Pos.CENTER_LEFT); - setSpacing(5); - - this.parameter = parameter; - - name = new Text(parameter.getName()); - value = new TextField(String.valueOf(parameter.getValue())); - - ((TextField) value).setAlignment(Pos.CENTER_RIGHT); - - setHgrow(value, Priority.ALWAYS); - - name.setWrappingWidth(GUI.WRAP_WIDTH); - - value.setDisable(parameter.isManaged()); - - getChildren().addAll(name, value); - } -} diff --git a/src/jcgp/gui/settings/GUIParameter.java b/src/jcgp/gui/settings/GUIParameter.java deleted file mode 100644 index 0547758..0000000 --- a/src/jcgp/gui/settings/GUIParameter.java +++ /dev/null @@ -1,14 +0,0 @@ -package jcgp.gui.settings; - -import javafx.scene.control.Control; -import javafx.scene.layout.HBox; -import javafx.scene.text.Text; -import jcgp.parameters.Parameter; - -public abstract class GUIParameter extends HBox { - - protected Parameter parameter; - protected Text name; - protected Control value; - -} |