diff options
Diffstat (limited to 'src/jcgp/gui')
-rw-r--r-- | src/jcgp/gui/console/GUIConsole.java | 1 | ||||
-rw-r--r-- | src/jcgp/gui/population/FunctionSelector.java | 2 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUINode.java | 4 | ||||
-rw-r--r-- | src/jcgp/gui/settings/SettingsPane.java | 56 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIBooleanParameter.java | 3 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIDoubleParameter.java | 7 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIIntegerParameter.java | 6 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIParameter.java | 4 |
8 files changed, 40 insertions, 43 deletions
diff --git a/src/jcgp/gui/console/GUIConsole.java b/src/jcgp/gui/console/GUIConsole.java index e77e222..de4b378 100644 --- a/src/jcgp/gui/console/GUIConsole.java +++ b/src/jcgp/gui/console/GUIConsole.java @@ -38,7 +38,6 @@ public class GUIConsole extends AnchorPane implements Console { @Override public Event dispatchEvent(Event event, EventDispatchChain tail) { if (event instanceof MouseEvent) { - //shot in the dark guess for OSX, might not work MouseEvent mouseEvent = (MouseEvent)event; if (mouseEvent.getButton() == MouseButton.SECONDARY || (mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.isControlDown())) { diff --git a/src/jcgp/gui/population/FunctionSelector.java b/src/jcgp/gui/population/FunctionSelector.java index 28eb54d..69d0d31 100644 --- a/src/jcgp/gui/population/FunctionSelector.java +++ b/src/jcgp/gui/population/FunctionSelector.java @@ -31,7 +31,7 @@ public class FunctionSelector extends VBox { for (int i = 0; i < fs.getAllowedFunctionCount(); i++) { final int index = i; - Label l = new Label(fs.getAllowedFunction(i).getName()); + Label l = new Label(fs.getAllowedFunction(i).toString()); l.setMaxWidth(Double.MAX_VALUE); l.setStyle("-fx-background-color: #FFFFFF; -fx-border-color: #A0A0A0; -fx-border-width: 0 0 1 0; -fx-padding: 2"); diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index f50edd3..731db8f 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -454,9 +454,9 @@ public class GUINode extends GUIGene { public void updateText() { if (parent.isEvaluating()) { - text.setText(node.getFunction().getName() + "\n" + value.toString()); + text.setText(node.getFunction() + "\n" + value.toString()); } else { - text.setText(node.getFunction().getName()); + text.setText(node.getFunction().toString()); } } 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(); } |