diff options
Diffstat (limited to 'src/jcgp/gui/settings')
-rw-r--r-- | src/jcgp/gui/settings/SettingsPane.java | 109 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIBooleanParameter.java | 43 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIDoubleParameter.java | 41 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIIntegerParameter.java | 42 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIParameter.java | 18 |
5 files changed, 160 insertions, 93 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; } diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java index da564f7..fc66e7d 100644 --- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java @@ -6,12 +6,13 @@ import javafx.scene.control.CheckBox; import jcgp.backend.parameters.BooleanParameter; import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.GUI; +import jcgp.gui.settings.SettingsPane; public class GUIBooleanParameter extends GUIParameter { private boolean originalValue; - GUIBooleanParameter(final BooleanParameter parameter) { + GUIBooleanParameter(final BooleanParameter parameter, final SettingsPane sp) { super(); this.parameter = parameter; @@ -32,18 +33,8 @@ public class GUIBooleanParameter extends GUIParameter { ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { parameter.set(newValue); - if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else if (parameter.getStatus() == ParameterStatus.WARNING) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); - valueControl.setTooltip(null); - } + setValidityStyle(); + sp.revalidateParameters(); } }); } @@ -60,7 +51,8 @@ public class GUIBooleanParameter extends GUIParameter { @Override public boolean requiresReset() { - return parameter.isCritical() && ((BooleanParameter) parameter).get() != originalValue; + return (parameter.isCritical() && ((BooleanParameter) parameter).get() != originalValue) + || parameter.getStatus() == ParameterStatus.WARNING_RESET; } @Override @@ -68,4 +60,27 @@ public class GUIBooleanParameter extends GUIParameter { originalValue = ((BooleanParameter) parameter).get(); } + /** + * @param parameter + */ + private void setValidityStyle() { + if (parameter.getStatus() == ParameterStatus.INVALID) { + valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { + valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else { + valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setTooltip(null); + } + } + + @Override + public void validate() { + ((BooleanParameter) parameter).validate(((BooleanParameter) parameter).get()); + setValidityStyle(); + } } diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java index a1b4526..190f4b7 100644 --- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java @@ -11,12 +11,13 @@ import javafx.scene.text.Text; import jcgp.backend.parameters.DoubleParameter; import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.GUI; +import jcgp.gui.settings.SettingsPane; public class GUIDoubleParameter extends GUIParameter { private double originalValue; - GUIDoubleParameter(final DoubleParameter parameter) { + GUIDoubleParameter(final DoubleParameter parameter, final SettingsPane sp) { super(); this.parameter = parameter; @@ -54,18 +55,8 @@ public class GUIDoubleParameter extends GUIParameter { String oldValue, String newValue) { if (!newValue.isEmpty()) { parameter.set(Double.parseDouble(newValue)); - if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else if (parameter.getStatus() == ParameterStatus.WARNING) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); - valueControl.setTooltip(null); - } + setValidityStyle(); + sp.revalidateParameters(); } } @@ -93,7 +84,8 @@ public class GUIDoubleParameter extends GUIParameter { @Override public boolean requiresReset() { - return parameter.isCritical() && ((DoubleParameter) parameter).get() != originalValue; + return (parameter.isCritical() && ((DoubleParameter) parameter).get() != originalValue) + || parameter.getStatus() == ParameterStatus.WARNING_RESET; } @Override @@ -101,4 +93,25 @@ public class GUIDoubleParameter extends GUIParameter { originalValue = ((DoubleParameter) parameter).get(); } + @Override + public void validate() { + ((DoubleParameter) parameter).validate(((DoubleParameter) parameter).get()); + setValidityStyle(); + } + + private void setValidityStyle() { + if (parameter.getStatus() == ParameterStatus.INVALID) { + valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { + valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else { + valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setTooltip(null); + } + } + } diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java index bf1a61e..a2040d7 100644 --- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java @@ -11,12 +11,13 @@ import javafx.scene.text.Text; import jcgp.backend.parameters.IntegerParameter; import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.GUI; +import jcgp.gui.settings.SettingsPane; public class GUIIntegerParameter extends GUIParameter { private int originalValue; - GUIIntegerParameter(final IntegerParameter parameter) { + GUIIntegerParameter(final IntegerParameter parameter, final SettingsPane sp) { super(); this.parameter = parameter; @@ -54,18 +55,8 @@ public class GUIIntegerParameter extends GUIParameter { String oldValue, String newValue) { if (!newValue.isEmpty()) { parameter.set(Integer.parseInt(newValue)); - if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else if (parameter.getStatus() == ParameterStatus.WARNING) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); - valueControl.setTooltip(tooltip); - tooltip.setText(parameter.getStatus().getDetails()); - } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); - valueControl.setTooltip(null); - } + setValidityStyle(); + sp.revalidateParameters(); } } @@ -92,7 +83,9 @@ public class GUIIntegerParameter extends GUIParameter { @Override public boolean requiresReset() { - return parameter.isCritical() && ((IntegerParameter) parameter).get() != originalValue; + // true if critical and the value has changed, or it requires a reset anyway + return (parameter.isCritical() && ((IntegerParameter) parameter).get() != originalValue) + || parameter.getStatus() == ParameterStatus.WARNING_RESET; } @Override @@ -100,4 +93,25 @@ public class GUIIntegerParameter extends GUIParameter { originalValue = ((IntegerParameter) parameter).get(); } + @Override + public void validate() { + ((IntegerParameter) parameter).validate(((IntegerParameter) parameter).get()); + setValidityStyle(); + } + + private void setValidityStyle() { + if (parameter.getStatus() == ParameterStatus.INVALID) { + valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { + valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setTooltip(tooltip); + tooltip.setText(parameter.getStatus().getDetails()); + } else { + valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setTooltip(null); + } + } + } diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index 9d6f07a..da2fe86 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -14,6 +14,8 @@ import jcgp.backend.parameters.BooleanParameter; import jcgp.backend.parameters.DoubleParameter; import jcgp.backend.parameters.IntegerParameter; import jcgp.backend.parameters.Parameter; +import jcgp.backend.parameters.ParameterStatus; +import jcgp.gui.settings.SettingsPane; public abstract class GUIParameter extends HBox { @@ -59,15 +61,23 @@ public abstract class GUIParameter extends HBox { public abstract void applyValue(); - public static GUIParameter create(Parameter parameter) { + public abstract void validate(); + + public static GUIParameter create(Parameter parameter, SettingsPane sp) { if (parameter instanceof IntegerParameter) { - return new GUIIntegerParameter((IntegerParameter) parameter); + return new GUIIntegerParameter((IntegerParameter) parameter, sp); } else if (parameter instanceof DoubleParameter) { - return new GUIDoubleParameter((DoubleParameter) parameter); + return new GUIDoubleParameter((DoubleParameter) parameter, sp); } else if (parameter instanceof BooleanParameter) { - return new GUIBooleanParameter((BooleanParameter) parameter); + return new GUIBooleanParameter((BooleanParameter) parameter, sp); } else { throw new ClassCastException("No GUIParameter subclass exists for argument of type " + parameter.getClass()); } } + + public boolean isValid() { + return parameter.getStatus() == ParameterStatus.VALID + || parameter.getStatus() == ParameterStatus.WARNING + || parameter.getStatus() == ParameterStatus.WARNING_RESET; + } } |