aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/settings/parameters
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-21 00:09:55 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-21 00:09:55 +0100
commitefe490fec1c7a94f004b496c7c97c82083fe44ec (patch)
treeffe7a8bb411a9208c3220247247081eb90ac4fc0 /src/jcgp/gui/settings/parameters
parent88314e71f908efcfc38da3b800319c171a6ccceb (diff)
Tooltips are looking strange, checking on a different machine
Diffstat (limited to 'src/jcgp/gui/settings/parameters')
-rw-r--r--src/jcgp/gui/settings/parameters/GUIDoubleParameter.java41
-rw-r--r--src/jcgp/gui/settings/parameters/GUIIntegerParameter.java32
-rw-r--r--src/jcgp/gui/settings/parameters/GUIParameter.java12
3 files changed, 39 insertions, 46 deletions
diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
index 29648ca..9a6ec4a 100644
--- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
@@ -1,12 +1,12 @@
package jcgp.gui.settings.parameters;
+import java.text.DecimalFormat;
+
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
-import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Control;
import javafx.scene.control.TextField;
-import javafx.scene.input.KeyEvent;
import jcgp.backend.resources.parameters.Parameter;
import jcgp.backend.resources.parameters.ParameterStatus;
import jcgp.gui.settings.SettingsPane;
@@ -23,6 +23,7 @@ import jcgp.gui.settings.SettingsPane;
public class GUIDoubleParameter extends GUIParameter<Number> {
private TextField textField;
+ private DecimalFormat decimalFormat;
/**
* This default-visibility constructor is intended for use
@@ -31,6 +32,8 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
*/
GUIDoubleParameter(Parameter<Number> parameter, SettingsPane sp) {
super(parameter, sp);
+ decimalFormat = new DecimalFormat();
+ decimalFormat.setMaximumFractionDigits(10);
}
@Override
@@ -38,23 +41,12 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
textField = new TextField(String.valueOf(parameter.get()));
textField.setStyle(VALID_PARAMETER_STYLE);
textField.setAlignment(Pos.CENTER_RIGHT);
-
+ textField.prefWidthProperty().bind(widthProperty().divide(2));
return textField;
}
@Override
protected void setControlListeners() {
- /* filter keypresses and ignore anything that is not a number
- * and any decimal point beyond the first ones */
- textField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
- @Override
- public void handle( KeyEvent t ) {
- char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1];
- if (!((ch >= '0' && ch <= '9') || (ch == '.' && !textField.getText().contains(".")))) {
- t.consume();
- }
- }
- });
/* pass the TextField value back to the parameter whenever it gets
* modified, provided it is not empty and the experiment isn't running */
textField.textProperty().addListener(new ChangeListener<String>() {
@@ -62,11 +54,17 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
public void changed(
ObservableValue<? extends String> observable,
String oldValue, String newValue) {
- if (!newValue.isEmpty() && !settingsPane.isExperimentRunning()) {
- parameter.set(Double.parseDouble(newValue));
- settingsPane.revalidateParameters();
+ if (!settingsPane.isExperimentRunning()) {
+ if (newValue.matches("([0-9]*[.]*[0-9]*)")) {
+ if (!newValue.isEmpty()) {
+ double value = Double.parseDouble(newValue);
+ parameter.set(value);
+ settingsPane.revalidateParameters();
+ }
+ } else {
+ refreshValue();
+ }
}
-
}
});
/* if the TextField loses focus and is empty, set it to the current
@@ -76,8 +74,8 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
public void changed(
ObservableValue<? extends Boolean> observable,
Boolean oldValue, Boolean newValue) {
- if (!newValue && textField.getText().isEmpty()) {
- textField.setText(String.valueOf(parameter.get()));
+ if (!newValue) {
+ refreshValue();
}
}
});
@@ -102,6 +100,7 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
@Override
public void refreshValue() {
- textField.setText(String.valueOf((parameter).get()));
+ System.out.println("setting text to: " + parameter.get().doubleValue());
+ textField.setText(decimalFormat.format(parameter.get().doubleValue()));
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
index da2c11f..ee266f3 100644
--- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
@@ -2,11 +2,9 @@ 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.Control;
import javafx.scene.control.TextField;
-import javafx.scene.input.KeyEvent;
import jcgp.backend.resources.parameters.Parameter;
import jcgp.backend.resources.parameters.ParameterStatus;
import jcgp.gui.settings.SettingsPane;
@@ -38,22 +36,13 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
textField = new TextField(String.valueOf(parameter.get()));
textField.setStyle(VALID_PARAMETER_STYLE);
textField.setAlignment(Pos.CENTER_RIGHT);
+ textField.prefWidthProperty().bind(widthProperty().divide(2));
return textField;
}
@Override
protected void setControlListeners() {
- /* filter keypresses and ignore anything that is not a number */
- textField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
- @Override
- public void handle( KeyEvent t ) {
- char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1];
- if (!(ch >= '0' && ch <= '9')) {
- t.consume();
- }
- }
- });
/* pass the TextField value back to the parameter whenever it gets
* modified, provided it is not empty and the experiment isn't running */
textField.textProperty().addListener(new ChangeListener<String>() {
@@ -61,9 +50,16 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
public void changed(
ObservableValue<? extends String> observable,
String oldValue, String newValue) {
- if (!newValue.isEmpty() && !settingsPane.isExperimentRunning()) {
- parameter.set(Double.parseDouble(newValue));
- settingsPane.revalidateParameters();
+ if (!settingsPane.isExperimentRunning()) {
+ if (newValue.matches("[0-9]*")) {
+ if (!newValue.isEmpty()) {
+ int value = Integer.parseInt(newValue);
+ parameter.set(value);
+ settingsPane.revalidateParameters();
+ }
+ } else {
+ refreshValue();
+ }
}
}
});
@@ -74,8 +70,8 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
public void changed(
ObservableValue<? extends Boolean> observable,
Boolean oldValue, Boolean newValue) {
- if (!newValue && textField.getText().isEmpty()) {
- textField.setText(String.valueOf(parameter.get()));
+ if (!newValue) {
+ refreshValue();
}
}
});
@@ -101,6 +97,6 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
@Override
public void refreshValue() {
- textField.setText(String.valueOf((parameter).get()));
+ textField.setText(String.valueOf(parameter.get()));
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java
index 159e709..7dd7231 100644
--- a/src/jcgp/gui/settings/parameters/GUIParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIParameter.java
@@ -7,10 +7,9 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.Control;
+import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
-import javafx.scene.layout.Priority;
-import javafx.scene.text.Text;
import jcgp.backend.resources.parameters.BooleanParameter;
import jcgp.backend.resources.parameters.DoubleParameter;
import jcgp.backend.resources.parameters.IntegerParameter;
@@ -46,7 +45,7 @@ public abstract class GUIParameter<T> extends HBox {
public static final String WARNING_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_SELECTION_COLOUR;
public static final String VALID_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_COLOUR;
- private Text name;
+ private Label name;
private Control valueControl;
protected SettingsPane settingsPane;
@@ -80,9 +79,9 @@ public abstract class GUIParameter<T> extends HBox {
setAlignment(Pos.CENTER_LEFT);
setSpacing(5);
- name = new Text(parameter.getName());
+ name = new Label(parameter.getName());
// set text width to half of the total width of the GUIParameter
- name.wrappingWidthProperty().bind(widthProperty().divide(2));
+ name.prefWidthProperty().bind(widthProperty().divide(2));
// the tooltip is the hover-over label containing status information, when appropriate
tooltip = new Tooltip();
@@ -90,7 +89,6 @@ public abstract class GUIParameter<T> extends HBox {
tooltip.setSkin(null);
valueControl = makeControl();
- setHgrow(valueControl, Priority.ALWAYS);
// if the parameter is a monitor, it should be permanently disabled
valueControl.setDisable(parameter.isMonitor());
@@ -177,7 +175,7 @@ public abstract class GUIParameter<T> extends HBox {
*/
public void validate() {
parameter.validate(parameter.get());
- refreshValue();
+ //refreshValue();
setValidityStyle();
}