diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-25 19:38:16 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-25 19:38:16 +0100 |
commit | b0c0698e5503c2506217117bf144fde31e6f6601 (patch) | |
tree | 11a6e20fb565f1e75fb25852e757e4a37e4c313b /src/jcgp/gui/settings | |
parent | 9ac2848be66c39acdc291dc3b48b91178acc1a05 (diff) |
Commented lots of packages.
Diffstat (limited to 'src/jcgp/gui/settings')
5 files changed, 37 insertions, 39 deletions
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index 302e96d..7fc5621 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -126,17 +126,13 @@ public class SettingsPane extends AnchorPane { final VBox eaParameters = new VBox(2); - if (jcgp.getEvolutionaryStrategy().getLocalParameters() != null) { - refreshParameters(jcgp.getEvolutionaryStrategy().getLocalParameters(), eaParameters); - } + refreshParameters(jcgp.getEvolutionaryStrategy().getLocalParameters(), eaParameters); eaCBox.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { jcgp.setEvolutionaryStrategy(eaCBox.getSelectionModel().getSelectedIndex()); - if (eaCBox.getSelectionModel().getSelectedItem().getLocalParameters() != null) { - refreshParameters(eaCBox.getSelectionModel().getSelectedItem().getLocalParameters(), eaParameters); - } + refreshParameters(eaCBox.getSelectionModel().getSelectedItem().getLocalParameters(), eaParameters); } }); @@ -157,17 +153,13 @@ public class SettingsPane extends AnchorPane { mutatorCBox.prefWidthProperty().bind(mainContainer.widthProperty()); final VBox mutatorParameters = new VBox(2); - if (jcgp.getEvolutionaryStrategy().getLocalParameters() != null) { - refreshParameters(jcgp.getMutator().getLocalParameters(), mutatorParameters); - } + refreshParameters(jcgp.getMutator().getLocalParameters(), mutatorParameters); mutatorCBox.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { jcgp.setMutator(mutatorCBox.getSelectionModel().getSelectedIndex()); - if (mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters() != null) { - refreshParameters(mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters(), mutatorParameters); - } + refreshParameters(mutatorCBox.getSelectionModel().getSelectedItem().getLocalParameters(), mutatorParameters); } }); @@ -189,22 +181,22 @@ public class SettingsPane extends AnchorPane { final VBox problemParameters = new VBox(2); problemParameters.setPadding(new Insets(0, 0, 4, 0)); - if (jcgp.getProblem().getLocalParameters() != null) { - refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); - } + refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); final HBox testCaseControlContainer = new HBox(2); final Button showTestCaseButton = makeTestCaseButton(); - final Button loadTestCaseButton = makeLoadTestCaseButton(); + final Button loadProblemDataButton = makeLoadTestCaseButton(); HBox.setHgrow(showTestCaseButton, Priority.ALWAYS); showTestCaseButton.setMaxWidth(Double.MAX_VALUE); - HBox.setHgrow(loadTestCaseButton, Priority.ALWAYS); - loadTestCaseButton.setMaxWidth(Double.MAX_VALUE); + HBox.setHgrow(loadProblemDataButton, Priority.ALWAYS); + loadProblemDataButton.setMaxWidth(Double.MAX_VALUE); if (jcgp.getProblem() instanceof TestCaseProblem<?>) { - testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadTestCaseButton); + testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadProblemDataButton); remakeTestCaseTable(); + } else { + testCaseControlContainer.getChildren().add(loadProblemDataButton); } nodeFunctions = new VBox(2); @@ -215,16 +207,16 @@ public class SettingsPane extends AnchorPane { @Override public void handle(ActionEvent event) { jcgp.setProblem(problemCBox.getSelectionModel().getSelectedIndex()); - if (jcgp.getProblem().getLocalParameters() != null) { - refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); - } + refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); testCaseTable.close(); gui.setEvaluating(false); refreshFunctions(); testCaseControlContainer.getChildren().clear(); if (jcgp.getProblem() instanceof TestCaseProblem) { - testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadTestCaseButton); + testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadProblemDataButton); remakeTestCaseTable(); + } else { + testCaseControlContainer.getChildren().add(loadProblemDataButton); } gui.reset(); } @@ -236,17 +228,17 @@ public class SettingsPane extends AnchorPane { } private Button makeLoadTestCaseButton() { - Button b = new Button("Load test cases"); + Button b = new Button("Load problem data"); b.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { FileChooser fc = new FileChooser(); - fc.setTitle("Open test case file..."); + fc.setTitle("Open problem file..."); fc.getExtensionFilters().add(new ExtensionFilter("CGP " + gui.getExperiment().getProblem() + " files", "*" + ((TestCaseProblem<?>) gui.getExperiment().getProblem()).getFileExtension())); fc.getExtensionFilters().add(new ExtensionFilter("All files", "*.*")); File chrFile = fc.showOpenDialog(gui.getStage()); if (chrFile != null) { - gui.getExperiment().loadTestCases(chrFile); + gui.getExperiment().loadProblemData(chrFile); remakeTestCaseTable(); gui.reDraw(); } @@ -369,10 +361,12 @@ public class SettingsPane extends AnchorPane { private void refreshParameters(Parameter<?>[] newParameters, VBox vb) { parameters.removeAll(vb.getChildren()); vb.getChildren().clear(); - for (int i = 0; i < newParameters.length; i++) { - GUIParameter<?> gp = GUIParameter.create(newParameters[i], this); - parameters.add(gp); - vb.getChildren().add(gp); + if (newParameters != null) { + for (int i = 0; i < newParameters.length; i++) { + GUIParameter<?> gp = GUIParameter.create(newParameters[i], this); + parameters.add(gp); + vb.getChildren().add(gp); + } } revalidateParameters(); } @@ -386,7 +380,7 @@ public class SettingsPane extends AnchorPane { CheckBox cb; final FunctionSet fs = gui.getExperiment().getResources().getFunctionSet(); for (int i = 0; i < fs.getTotalFunctionCount(); i++) { - cb = new CheckBox(fs.getFunction(i).getName()); + cb = new CheckBox(fs.getFunction(i).toString()); cb.setId(String.valueOf(i)); cb.setSelected(fs.isEnabled(fs.getFunction(i))); final int index = i; diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java index e708c53..cc7113d 100644 --- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java @@ -62,7 +62,8 @@ public class GUIBooleanParameter extends GUIParameter<Boolean> { checkBox.setStyle(BASE_CHECKBOX_STYLE + INVALID_PARAMETER_STYLE); checkBox.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); - } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { + } else if (parameter.getStatus() == ParameterStatus.WARNING + || parameter.getStatus() == ParameterStatus.WARNING_RESET) { checkBox.setStyle(BASE_CHECKBOX_STYLE + WARNING_PARAMETER_STYLE); checkBox.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java index f177ffa..777e739 100644 --- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java @@ -36,6 +36,7 @@ public class GUIDoubleParameter extends GUIParameter<Number> { @Override protected Control makeControl() { + // we use a text field, and a formatting class to enforce decimals decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(10); textField = new TextField(decimalFormat.format(parameter.get().doubleValue())); @@ -48,14 +49,16 @@ public class GUIDoubleParameter extends GUIParameter<Number> { @Override protected void setControlListeners() { /* pass the TextField value back to the parameter whenever it gets - * modified, provided it is not empty and the experiment isn't running */ + * modified, provided it is not empty, the experiment isn't running + * and it matches the double-precision regex filter */ textField.textProperty().addListener(new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { if (!settingsPane.isExperimentRunning()) { - if (newValue.matches("([0-9]*[.]*[0-9]*)")) { + //if (newValue.matches("([0-9]*[.]?[0-9]*)")) { + if (newValue.matches("^[-+]?[0-9]*\\.?[0-9]+$")) { if (!newValue.isEmpty()) { double value = Double.parseDouble(newValue); parameter.set(value); diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java index e1b0b75..6e8b3f1 100644 --- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java @@ -33,6 +33,7 @@ public class GUIIntegerParameter extends GUIParameter<Number> { @Override protected Control makeControl() { + // this uses a text field textField = new TextField(String.valueOf(parameter.get())); textField.setStyle(VALID_PARAMETER_STYLE); textField.setAlignment(Pos.CENTER_RIGHT); @@ -44,7 +45,8 @@ public class GUIIntegerParameter extends GUIParameter<Number> { @Override protected void setControlListeners() { /* pass the TextField value back to the parameter whenever it gets - * modified, provided it is not empty and the experiment isn't running */ + * modified, provided it is not empty, the experiment isn't running + * and it matches the integer regex pattern */ textField.textProperty().addListener(new ChangeListener<String>() { @Override public void changed( @@ -98,7 +100,7 @@ public class GUIIntegerParameter extends GUIParameter<Number> { @Override public void refreshValue() { if (!textField.isFocused()) { - textField.setText(String.valueOf(parameter.get())); + textField.setText(parameter.get().toString()); } } } diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index 79762ff..b675fb5 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -30,9 +30,8 @@ import jcgp.gui.settings.SettingsPane; * Monitor parameters have their Control disabled so that no changed can be made via the GUI. * Non-monitor parameters are updated automatically as well, but may be changed by the user * if the program is not evolving. - * <br><br> - * For more information on how parameters work in JCGP, see {@link Parameter}. * + * @see Parameter * @author Eduardo Pedroni * @param <T> the parameter data type */ @@ -174,7 +173,6 @@ public abstract class GUIParameter<T> extends HBox { */ public void validate() { parameter.validate(parameter.get()); - //refreshValue(); setValidityStyle(); } |