aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/settings
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-03 15:29:24 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-03 15:29:24 +0100
commit0dbf126fc524bc029d9f5803d849b7c8f43fe389 (patch)
tree35d7c23b371614388cbb7a4bc247374759b95a33 /src/jcgp/gui/settings
parent02fd2bc7059da416937beb1abe67e5ca60379030 (diff)
Visual feedback for parameters implemented.
Diffstat (limited to 'src/jcgp/gui/settings')
-rw-r--r--src/jcgp/gui/settings/SettingsPane.java58
-rw-r--r--src/jcgp/gui/settings/parameters/GUIBooleanParameter.java63
-rw-r--r--src/jcgp/gui/settings/parameters/GUIDoubleParameter.java89
-rw-r--r--src/jcgp/gui/settings/parameters/GUIIntegerParameter.java84
-rw-r--r--src/jcgp/gui/settings/parameters/GUIParameter.java21
5 files changed, 228 insertions, 87 deletions
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java
index 61011aa..41b1bba 100644
--- a/src/jcgp/gui/settings/SettingsPane.java
+++ b/src/jcgp/gui/settings/SettingsPane.java
@@ -1,9 +1,6 @@
package jcgp.gui.settings;
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;
@@ -37,11 +34,15 @@ public class SettingsPane extends AnchorPane {
private VBox bpPane, eaPane, mutatorPane, ffPane, nfPane;
private ArrayList<GUIParameter> parameters = new ArrayList<GUIParameter>();
+ private GUI gui;
+
private boolean dragging = false;
public SettingsPane(JCGP cgp, GUI gui) {
super();
+ this.gui = gui;
+
setResizeListeners();
mainContainer = new VBox(8);
@@ -84,8 +85,7 @@ public class SettingsPane extends AnchorPane {
bpPane.getChildren().add(header);
- GUIParameter rows = GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("rows"));
- parameters.add(rows);
+ 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")));
@@ -98,14 +98,13 @@ public class SettingsPane extends AnchorPane {
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("maxFitness")));
parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("seed")));
parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("report")));
bpPane.getChildren().addAll(parameters);
mainContainer.getChildren().add(bpPane);
-
-
}
private void initialiseEAParameters(final JCGP cgp) {
@@ -122,8 +121,9 @@ public class SettingsPane extends AnchorPane {
final VBox eaParameters = new VBox();
eaParameters.setSpacing(2);
+
if (cgp.getEvolutionaryAlgorithm().getLocalParameters() != null) {
- refreshParameters(cgp.getEvolutionaryAlgorithm().getLocalParameters().entrySet().iterator(), eaParameters);
+ refreshParameters(cgp.getEvolutionaryAlgorithm().getLocalParameters(), eaParameters);
}
eaCBox.setOnAction(new EventHandler<ActionEvent>() {
@@ -131,7 +131,7 @@ public class SettingsPane extends AnchorPane {
public void handle(ActionEvent event) {
cgp.setEvolutionaryAlgorithm(eaCBox.getSelectionModel().getSelectedIndex());
if (eaCBox.getSelectionModel().getSelectedItem().getLocalParameters() != null) {
- refreshParameters(eaCBox.getSelectionModel().getSelectedItem().getLocalParameters().entrySet().iterator(), eaParameters);
+ refreshParameters(eaCBox.getSelectionModel().getSelectedItem().getLocalParameters(), eaParameters);
}
}
});
@@ -156,7 +156,7 @@ public class SettingsPane extends AnchorPane {
final VBox mutatorParameters = new VBox();
mutatorParameters.setSpacing(2);
if (cgp.getEvolutionaryAlgorithm().getLocalParameters() != null) {
- refreshParameters(cgp.getMutator().getLocalParameters().entrySet().iterator(), mutatorParameters);
+ refreshParameters(cgp.getMutator().getLocalParameters(), mutatorParameters);
}
mutatorCBox.setOnAction(new EventHandler<ActionEvent>() {
@@ -164,7 +164,7 @@ public class SettingsPane extends AnchorPane {
public void handle(ActionEvent event) {
cgp.setEvolutionaryAlgorithm(mutatorCBox.getSelectionModel().getSelectedIndex());
if (mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters() != null) {
- refreshParameters(mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters().entrySet().iterator(), mutatorParameters);
+ refreshParameters(mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters(), mutatorParameters);
}
}
});
@@ -188,7 +188,7 @@ public class SettingsPane extends AnchorPane {
final VBox ffParameters = new VBox();
ffParameters.setSpacing(2);
if (cgp.getFitnessFunction().getLocalParameters() != null) {
- refreshParameters(cgp.getFitnessFunction().getLocalParameters().entrySet().iterator(), ffParameters);
+ refreshParameters(cgp.getFitnessFunction().getLocalParameters(), ffParameters);
}
ffCBox.setOnAction(new EventHandler<ActionEvent>() {
@@ -196,7 +196,7 @@ public class SettingsPane extends AnchorPane {
public void handle(ActionEvent event) {
cgp.setEvolutionaryAlgorithm(ffCBox.getSelectionModel().getSelectedIndex());
if (ffCBox.getSelectionModel().getSelectedItem().getLocalParameters() != null) {
- refreshParameters(ffCBox.getSelectionModel().getSelectedItem().getLocalParameters().entrySet().iterator(), ffParameters);
+ refreshParameters(ffCBox.getSelectionModel().getSelectedItem().getLocalParameters(), ffParameters);
}
}
});
@@ -244,8 +244,8 @@ public class SettingsPane extends AnchorPane {
@Override
public void handle(ActionEvent event) {
if (play.getText() == "Run") {
- if (applyChanges()) {
- gui.resetCGP();
+ if (isResetRequired()) {
+ resetExperiment();
}
play.setText("Pause");
} else {
@@ -260,8 +260,8 @@ public class SettingsPane extends AnchorPane {
step.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
- if (applyChanges()) {
- gui.resetCGP();
+ if (isResetRequired()) {
+ resetExperiment();
}
gui.step();
}
@@ -284,16 +284,15 @@ public class SettingsPane extends AnchorPane {
* @param cgp
* @param vb
*/
- private void refreshParameters(Iterator<Entry<String, Parameter>> it, VBox vb) {
+ private void refreshParameters(Parameter[] newParameters, VBox vb) {
parameters.removeAll(vb.getChildren());
vb.getChildren().clear();
- while (it.hasNext()) {
- Parameter parameter = ((Map.Entry<String, Parameter>) it.next()).getValue();
- GUIParameter gp = GUIParameter.create(parameter);
+ for (int i = 0; i < newParameters.length; i++) {
+ GUIParameter gp = GUIParameter.create(newParameters[i]);
parameters.add(gp);
vb.getChildren().add(gp);
- }
+ }
}
private void refreshFunctions(final FunctionSet fs, VBox vb) {
@@ -378,15 +377,22 @@ public class SettingsPane extends AnchorPane {
*
* @return true if the experiment needs to be reset, false otherwise.
*/
- private boolean applyChanges() {
+ private boolean isResetRequired() {
boolean reset = false;
-
for (GUIParameter parameter : parameters) {
- reset |= parameter.applyChange();
+ reset |= parameter.requiresReset();
}
-
+ System.out.println("reset: " + reset);
return reset;
}
+ private void resetExperiment() {
+ for (GUIParameter parameter : parameters) {
+ parameter.applyValue();
+ }
+ gui.reset();
+
+ }
+
}
diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
index 8acd6dd..da564f7 100644
--- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
@@ -1,46 +1,71 @@
package jcgp.gui.settings.parameters;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;
import jcgp.backend.parameters.BooleanParameter;
+import jcgp.backend.parameters.ParameterStatus;
+import jcgp.gui.GUI;
public class GUIBooleanParameter extends GUIParameter {
- GUIBooleanParameter(BooleanParameter parameter) {
+ private boolean originalValue;
+
+ GUIBooleanParameter(final BooleanParameter parameter) {
super();
this.parameter = parameter;
- value = new CheckBox(parameter.getName());
- ((CheckBox) value).setSelected(parameter.get());
+ originalValue = parameter.get();
+
+ valueControl = new CheckBox(parameter.getName());
+ ((CheckBox) valueControl).setSelected(parameter.get());
- value.setDisable(parameter.isMonitor());
+ valueControl.setDisable(parameter.isMonitor());
if (parameter.isMonitor()) {
makeLightBinding();
- System.out.println("light binding made for " + name);
+ } else {
+ ((CheckBox) valueControl).selectedProperty().addListener(new ChangeListener<Boolean>() {
+ @Override
+ public void changed(
+ 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);
+ }
+ }
+ });
}
- getChildren().add(value);
+ getChildren().add(valueControl);
}
@Override
public void refreshValue() {
- if (!((CheckBox) value).selectedProperty().isBound()) {
- ((CheckBox) value).setSelected(((BooleanParameter) parameter).get());
+ if (!((CheckBox) valueControl).selectedProperty().isBound()) {
+ ((CheckBox) valueControl).setSelected(((BooleanParameter) parameter).get());
}
-
}
-
+
@Override
- public boolean applyChange() {
- if (((CheckBox) value).isSelected() != ((BooleanParameter) parameter).get() && (!parameter.isMonitor())) {
- // apply value
- ((BooleanParameter) parameter).set(((CheckBox) value).isSelected());
- if (parameter.isCritical()) {
- return true;
- }
- }
- return false;
+ public boolean requiresReset() {
+ return parameter.isCritical() && ((BooleanParameter) parameter).get() != originalValue;
+ }
+
+ @Override
+ public void applyValue() {
+ originalValue = ((BooleanParameter) parameter).get();
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
index 4b74c6e..a1b4526 100644
--- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
@@ -1,51 +1,104 @@
package jcgp.gui.settings.parameters;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
+import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import jcgp.backend.parameters.DoubleParameter;
+import jcgp.backend.parameters.ParameterStatus;
import jcgp.gui.GUI;
public class GUIDoubleParameter extends GUIParameter {
- GUIDoubleParameter(DoubleParameter parameter) {
+ private double originalValue;
+
+ GUIDoubleParameter(final DoubleParameter parameter) {
super();
this.parameter = parameter;
+ originalValue = parameter.get();
+
name = new Text(parameter.getName());
- value = new TextField(String.valueOf(parameter.get()));
+ valueControl = new TextField(String.valueOf(parameter.get()));
+ valueControl.setStyle(GUI.VALID_PARAMETER_STYLE);
- ((TextField) value).setAlignment(Pos.CENTER_RIGHT);
+ ((TextField) valueControl).setAlignment(Pos.CENTER_RIGHT);
- setHgrow(value, Priority.ALWAYS);
+ setHgrow(valueControl, Priority.ALWAYS);
name.setWrappingWidth(GUI.WRAP_WIDTH);
- ((TextField) value).setEditable(!parameter.isMonitor());
+ ((TextField) valueControl).setEditable(!parameter.isMonitor());
+ // bind if monitor, else set changelistener
if (parameter.isMonitor()) {
makeLightBinding();
+ } else {
+ valueControl.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
+ public void handle( KeyEvent t ) {
+ char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1];
+ if (!((ch >= '0' && ch <= '9') || (ch == '.' && !((TextField) valueControl).getText().contains(".")))) {
+ t.consume();
+ }
+ }
+ });
+ ((TextField) valueControl).textProperty().addListener(new ChangeListener<String>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends String> observable,
+ 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);
+ }
+ }
+
+ }
+ });
+ valueControl.focusedProperty().addListener(new ChangeListener<Boolean>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends Boolean> observable,
+ Boolean oldValue, Boolean newValue) {
+ if (!newValue && ((TextField) valueControl).getText().isEmpty()) {
+ ((TextField) valueControl).setText(String.valueOf(parameter.get()));
+ }
+ }
+ });
}
- getChildren().addAll(name, value);
+
+ getChildren().addAll(name, valueControl);
}
@Override
public void refreshValue() {
- ((TextField) value).setText(String.valueOf(((DoubleParameter) parameter).get()));
+ ((TextField) valueControl).setText(String.valueOf(((DoubleParameter) parameter).get()));
}
-
+
@Override
- public boolean applyChange() {
- if (Double.valueOf(((TextField) value).getText()) != ((DoubleParameter) parameter).get() && (!parameter.isMonitor())) {
- // apply value
- ((DoubleParameter) parameter).set(Double.valueOf(((TextField) value).getText()));
- if (parameter.isCritical()) {
- return true;
- }
- }
- return false;
- }
+ public boolean requiresReset() {
+ return parameter.isCritical() && ((DoubleParameter) parameter).get() != originalValue;
+ }
+
+ @Override
+ public void applyValue() {
+ originalValue = ((DoubleParameter) parameter).get();
+ }
+
}
diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
index 70b78a6..bf1a61e 100644
--- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
@@ -1,49 +1,103 @@
package jcgp.gui.settings.parameters;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
+import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import jcgp.backend.parameters.IntegerParameter;
+import jcgp.backend.parameters.ParameterStatus;
import jcgp.gui.GUI;
public class GUIIntegerParameter extends GUIParameter {
- GUIIntegerParameter(IntegerParameter parameter) {
+ private int originalValue;
+
+ GUIIntegerParameter(final IntegerParameter parameter) {
super();
this.parameter = parameter;
+ originalValue = parameter.get();
+
name = new Text(parameter.getName());
- value = new TextField(String.valueOf(parameter.get()));
+ valueControl = new TextField(String.valueOf(parameter.get()));
+ valueControl.setStyle(GUI.VALID_PARAMETER_STYLE);
- ((TextField) value).setAlignment(Pos.CENTER_RIGHT);
+ ((TextField) valueControl).setAlignment(Pos.CENTER_RIGHT);
- setHgrow(value, Priority.ALWAYS);
+ setHgrow(valueControl, Priority.ALWAYS);
name.setWrappingWidth(GUI.WRAP_WIDTH);
- ((TextField) value).setEditable(!parameter.isMonitor());
-
+ ((TextField) valueControl).setEditable(!parameter.isMonitor());
+
+ // bind if monitor, else set listeners
if (parameter.isMonitor()) {
makeLightBinding();
+ } else {
+ valueControl.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
+ public void handle( KeyEvent t ) {
+ char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1];
+ if (!(ch >= '0' && ch <= '9')) {
+ t.consume();
+ }
+ }
+ });
+ ((TextField) valueControl).textProperty().addListener(new ChangeListener<String>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends String> observable,
+ 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);
+ }
+ }
+
+ }
+ });
+ valueControl.focusedProperty().addListener(new ChangeListener<Boolean>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends Boolean> observable,
+ Boolean oldValue, Boolean newValue) {
+ if (!newValue && ((TextField) valueControl).getText().isEmpty()) {
+ ((TextField) valueControl).setText(String.valueOf(parameter.get()));
+ }
+ }
+ });
}
- getChildren().addAll(name, value);
+ getChildren().addAll(name, valueControl);
}
@Override
public void refreshValue() {
- ((TextField) value).setText(String.valueOf(((IntegerParameter) parameter).get()));
+ ((TextField) valueControl).setText(String.valueOf(((IntegerParameter) parameter).get()));
}
@Override
- public boolean applyChange() {
- if (Integer.valueOf(((TextField) value).getText()) != ((IntegerParameter) parameter).get() && (!parameter.isMonitor())) {
- // apply value
- ((IntegerParameter) parameter).set(Integer.valueOf(((TextField) value).getText()));
- return parameter.isCritical();
- }
- return false;
+ public boolean requiresReset() {
+ return parameter.isCritical() && ((IntegerParameter) parameter).get() != originalValue;
+ }
+
+ @Override
+ public void applyValue() {
+ originalValue = ((IntegerParameter) parameter).get();
}
+
}
diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java
index a783d71..9d6f07a 100644
--- a/src/jcgp/gui/settings/parameters/GUIParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIParameter.java
@@ -7,6 +7,7 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.Control;
+import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import jcgp.backend.parameters.BooleanParameter;
@@ -18,13 +19,19 @@ public abstract class GUIParameter extends HBox {
protected Parameter parameter;
protected Text name;
- protected Control value;
+ protected Control valueControl;
+
+ protected Tooltip tooltip;
protected AtomicBoolean updateCheck = new AtomicBoolean(true);
protected GUIParameter() {
setAlignment(Pos.CENTER_LEFT);
setSpacing(5);
+
+ tooltip = new Tooltip();
+ tooltip.setStyle("-fx-background-color: white; -fx-border-color: black; .page-corner {-fx-background-color: transparent;}");
+ tooltip.setSkin(null);
}
protected final void makeLightBinding() {
@@ -48,6 +55,10 @@ public abstract class GUIParameter extends HBox {
public abstract void refreshValue();
+ public abstract boolean requiresReset();
+
+ public abstract void applyValue();
+
public static GUIParameter create(Parameter parameter) {
if (parameter instanceof IntegerParameter) {
return new GUIIntegerParameter((IntegerParameter) parameter);
@@ -59,12 +70,4 @@ public abstract class GUIParameter extends HBox {
throw new ClassCastException("No GUIParameter subclass exists for argument of type " + parameter.getClass());
}
}
-
- /**
- * Writes the GUI parameter value back to the resources parameter,
- * if any changes were made.
- *
- * @return true if the experiment needs to be reset, false otherwise.
- */
- public abstract boolean applyChange();
}