diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-04 17:14:44 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-04 17:14:44 +0100 |
commit | c7969623b44f375e30fa3f15dcd7581609276a0f (patch) | |
tree | d1743df21e685fed93b7a12dd91a524e44fa42bd /src/jcgp/gui/settings/parameters | |
parent | 0dbf126fc524bc029d9f5803d849b7c8f43fe389 (diff) |
Parameter validation refactored and fully functional.
Diffstat (limited to 'src/jcgp/gui/settings/parameters')
4 files changed, 98 insertions, 46 deletions
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; + } } |