aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/settings/SettingsPane.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/settings/SettingsPane.java')
-rw-r--r--src/jcgp/gui/settings/SettingsPane.java109
1 files changed, 62 insertions, 47 deletions
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java
index 41b1bba..cb066b7 100644
--- a/src/jcgp/gui/settings/SettingsPane.java
+++ b/src/jcgp/gui/settings/SettingsPane.java
@@ -32,17 +32,16 @@ public class SettingsPane extends AnchorPane {
private VBox mainContainer;
private VBox bpPane, eaPane, mutatorPane, ffPane, nfPane;
- private ArrayList<GUIParameter> parameters = new ArrayList<GUIParameter>();
- private GUI gui;
+ private Button runPause;
+ private ArrayList<GUIParameter> parameters = new ArrayList<GUIParameter>();
+
private boolean dragging = false;
public SettingsPane(JCGP cgp, GUI gui) {
super();
-
- this.gui = gui;
-
+
setResizeListeners();
mainContainer = new VBox(8);
@@ -85,22 +84,22 @@ public class SettingsPane extends AnchorPane {
bpPane.getChildren().add(header);
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("rows")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("columns")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("inputs")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("outputs")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("levelsBack")));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("rows"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("columns"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("inputs"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("outputs"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("levelsBack"), this));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("popSize")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("generations")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("runs")));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("popSize"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("generations"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("runs"), this));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentGen")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentRun")));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentGen"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentRun"), this));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("maxFitness")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("seed")));
- parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("report")));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("maxFitness"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("seed"), this));
+ parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("report"), this));
bpPane.getChildren().addAll(parameters);
@@ -238,43 +237,41 @@ public class SettingsPane extends AnchorPane {
controls.setFillWidth(true);
final HBox flowButtons = new HBox(2);
- final Button play = new Button("Run");
-
- play.setOnAction(new EventHandler<ActionEvent>() {
+ runPause = new Button("Run");
+ runPause.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
- if (play.getText() == "Run") {
- if (isResetRequired()) {
- resetExperiment();
- }
- play.setText("Pause");
- } else {
- play.setText("Run");
- }
- gui.playPause();
+ gui.runPause();
}
});
Button step = new Button("Step");
-
step.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
- if (isResetRequired()) {
- resetExperiment();
- }
gui.step();
}
});
- flowButtons.getChildren().addAll(play, step);
+ Button reset = new Button("Reset");
+ reset.setOnAction(new EventHandler<ActionEvent>() {
+ @Override
+ public void handle(ActionEvent event) {
+ gui.reset();
+ }
+ });
+
+ flowButtons.getChildren().addAll(runPause, step, reset);
- HBox.setHgrow(play, Priority.ALWAYS);
- play.setMaxWidth(Double.MAX_VALUE);
+ HBox.setHgrow(runPause, Priority.ALWAYS);
+ runPause.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(step, Priority.ALWAYS);
step.setMaxWidth(Double.MAX_VALUE);
+ HBox.setHgrow(reset, Priority.ALWAYS);
+ reset.setMaxWidth(Double.MAX_VALUE);
+
controls.getChildren().add(flowButtons);
mainContainer.getChildren().add(controls);
@@ -288,11 +285,12 @@ public class SettingsPane extends AnchorPane {
parameters.removeAll(vb.getChildren());
vb.getChildren().clear();
for (int i = 0; i < newParameters.length; i++) {
- GUIParameter gp = GUIParameter.create(newParameters[i]);
+ GUIParameter gp = GUIParameter.create(newParameters[i], this);
parameters.add(gp);
vb.getChildren().add(gp);
}
+ revalidateParameters();
}
private void refreshFunctions(final FunctionSet fs, VBox vb) {
@@ -377,21 +375,38 @@ public class SettingsPane extends AnchorPane {
*
* @return true if the experiment needs to be reset, false otherwise.
*/
- private boolean isResetRequired() {
- boolean reset = false;
+ public boolean isResetRequired() {
for (GUIParameter parameter : parameters) {
- reset |= parameter.requiresReset();
+ if (parameter.requiresReset()) {
+ return true;
+ }
}
- System.out.println("reset: " + reset);
- return reset;
+ return false;
}
- private void resetExperiment() {
+ public boolean areParametersValid() {
for (GUIParameter parameter : parameters) {
- parameter.applyValue();
+ if (!parameter.isValid()) {
+ return false;
+ }
}
- gui.reset();
-
+ return true;
+ }
+
+ public void revalidateParameters() {
+ for (GUIParameter parameter : parameters) {
+ parameter.validate();
+ }
+ }
+
+ public void applyParameters() {
+ for (GUIParameter parameter : parameters) {
+ parameter.applyValue();
+ }
+ }
+
+ public Button getRunButton() {
+ return runPause;
}