From 36f4393bcc9e55afa2334baa33e603ce839741a1 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 1 May 2014 13:05:27 +0100 Subject: Did more commenting, implemented reflection and statistics --- src/jcgp/gui/settings/SettingsPane.java | 13 +++++----- .../settings/parameters/GUIBooleanParameter.java | 4 ++-- .../settings/parameters/GUIDoubleParameter.java | 4 ++-- .../settings/parameters/GUIIntegerParameter.java | 4 ++-- src/jcgp/gui/settings/parameters/GUIParameter.java | 28 ++++++++++++---------- src/jcgp/gui/settings/testcase/TestCaseTable.java | 15 +++++++----- 6 files changed, 37 insertions(+), 31 deletions(-) (limited to 'src/jcgp/gui/settings') diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index 7fc5621..b1322e4 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -24,7 +24,7 @@ import jcgp.backend.modules.es.EvolutionaryStrategy; import jcgp.backend.modules.mutator.Mutator; import jcgp.backend.modules.problem.Problem; import jcgp.backend.modules.problem.TestCaseProblem; -import jcgp.backend.resources.parameters.Parameter; +import jcgp.backend.parameters.Parameter; import jcgp.gui.GUI; import jcgp.gui.settings.parameters.GUIParameter; import jcgp.gui.settings.testcase.TestCaseTable; @@ -208,7 +208,9 @@ public class SettingsPane extends AnchorPane { public void handle(ActionEvent event) { jcgp.setProblem(problemCBox.getSelectionModel().getSelectedIndex()); refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); - testCaseTable.close(); + if (testCaseTable != null) { + testCaseTable.close(); + } gui.setEvaluating(false); refreshFunctions(); testCaseControlContainer.getChildren().clear(); @@ -358,12 +360,12 @@ public class SettingsPane extends AnchorPane { * @param cgp * @param vb */ - private void refreshParameters(Parameter[] newParameters, VBox vb) { + private void refreshParameters(ArrayList> newParameters, VBox vb) { parameters.removeAll(vb.getChildren()); vb.getChildren().clear(); if (newParameters != null) { - for (int i = 0; i < newParameters.length; i++) { - GUIParameter gp = GUIParameter.create(newParameters[i], this); + for (int i = 0; i < newParameters.size(); i++) { + GUIParameter gp = GUIParameter.create(newParameters.get(i), this); parameters.add(gp); vb.getChildren().add(gp); } @@ -406,7 +408,6 @@ public class SettingsPane extends AnchorPane { } /** - * * @return true if the experiment needs to be reset, false otherwise. */ public boolean isResetRequired() { diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java index cc7113d..eb669bb 100644 --- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java @@ -4,8 +4,8 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.control.CheckBox; import javafx.scene.control.Control; -import jcgp.backend.resources.parameters.BooleanParameter; -import jcgp.backend.resources.parameters.ParameterStatus; +import jcgp.backend.parameters.BooleanParameter; +import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; /** diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java index 777e739..16a4cd4 100644 --- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java @@ -7,8 +7,8 @@ import javafx.beans.value.ObservableValue; import javafx.geometry.Pos; import javafx.scene.control.Control; import javafx.scene.control.TextField; -import jcgp.backend.resources.parameters.Parameter; -import jcgp.backend.resources.parameters.ParameterStatus; +import jcgp.backend.parameters.Parameter; +import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; /** diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java index 6e8b3f1..e8a9183 100644 --- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java @@ -5,8 +5,8 @@ import javafx.beans.value.ObservableValue; import javafx.geometry.Pos; import javafx.scene.control.Control; import javafx.scene.control.TextField; -import jcgp.backend.resources.parameters.Parameter; -import jcgp.backend.resources.parameters.ParameterStatus; +import jcgp.backend.parameters.Parameter; +import jcgp.backend.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; /** diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index b675fb5..0a9149f 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -10,11 +10,11 @@ import javafx.scene.control.Control; import javafx.scene.control.Label; import javafx.scene.control.Tooltip; import javafx.scene.layout.HBox; -import jcgp.backend.resources.parameters.BooleanParameter; -import jcgp.backend.resources.parameters.DoubleParameter; -import jcgp.backend.resources.parameters.IntegerParameter; -import jcgp.backend.resources.parameters.Parameter; -import jcgp.backend.resources.parameters.ParameterStatus; +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.GUI; import jcgp.gui.settings.SettingsPane; @@ -63,11 +63,13 @@ public abstract class GUIParameter extends HBox { private T referenceValue; /** - * This protected constructor contains the common elements to all GUIParameters - * and should be invoked by any subclasses using super(). + * This protected template constructor contains the common elements to all + * GUIParameters and should be invoked by any subclasses using super(). It + * defers the creation of the parameter {@code Control} object to the subclass + * currently being built (which in turn is defined by the factory method). * - * @param parameter a Parameter for which to generate a GUIParameter - * @param sp a reference to the SettingsPane + * @param parameter a Parameter for which to generate a GUIParameter. + * @param sp a reference to the SettingsPane. */ protected GUIParameter(Parameter parameter, final SettingsPane settingsPane) { this.parameter = parameter; @@ -78,7 +80,7 @@ public abstract class GUIParameter extends HBox { setAlignment(Pos.CENTER_LEFT); setSpacing(5); - name = new Label(parameter.getName()); + name = new Label(parameter.toString()); // set text width to half of the total width of the GUIParameter name.prefWidthProperty().bind(widthProperty().divide(2)); @@ -107,9 +109,9 @@ public abstract class GUIParameter extends HBox { * Use this to create an appropriate GUIParameter from any instance of Parameter, * rather than manually downcasting the Parameter object every time. * - * @param parameter a Parameter for which to generate a GUIParameter - * @param sp a reference to the SettingsPane - * @return an appropriate instance of GUIParameter + * @param parameter a Parameter for which to generate a GUIParameter. + * @param sp a reference to the SettingsPane. + * @return an appropriate instance of GUIParameter. */ public static GUIParameter create(Parameter parameter, SettingsPane sp) { if (parameter instanceof IntegerParameter) { diff --git a/src/jcgp/gui/settings/testcase/TestCaseTable.java b/src/jcgp/gui/settings/testcase/TestCaseTable.java index d7b2e2b..d4c1ff9 100644 --- a/src/jcgp/gui/settings/testcase/TestCaseTable.java +++ b/src/jcgp/gui/settings/testcase/TestCaseTable.java @@ -16,6 +16,7 @@ import javafx.stage.WindowEvent; import javafx.util.Callback; import jcgp.backend.modules.problem.TestCaseProblem; import jcgp.backend.modules.problem.TestCaseProblem.TestCase; +import jcgp.backend.resources.Resources; import jcgp.gui.GUI; /** @@ -31,14 +32,16 @@ public class TestCaseTable extends Stage { public TestCaseTable(final TestCaseProblem testCaseProblem, final GUI gui) { super(); + Resources resources = gui.getExperiment().getResources(); + table = new TableView>(); ObservableList> testCaseList = testCaseProblem.getTestCases(); - ArrayList, String>> inputs = new ArrayList, String>>(testCaseProblem.getInputCount()); - ArrayList, String>> outputs = new ArrayList, String>>(testCaseProblem.getOutputCount()); + ArrayList, String>> inputs = new ArrayList, String>>(resources.inputs()); + ArrayList, String>> outputs = new ArrayList, String>>(resources.outputs()); TableColumn, String> tc; - for (int i = 0; i < testCaseProblem.getInputCount(); i++) { + for (int i = 0; i < resources.inputs(); i++) { tc = new TableColumn, String>("I: " + i); inputs.add(tc); final int index = i; @@ -49,10 +52,10 @@ public class TestCaseTable extends Stage { } }); tc.setSortable(false); - tc.prefWidthProperty().bind(table.widthProperty().divide(testCaseProblem.getInputCount() + testCaseProblem.getOutputCount())); + tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs())); } - for (int o = 0; o < testCaseProblem.getOutputCount(); o++) { + for (int o = 0; o < resources.outputs(); o++) { tc = new TableColumn, String>("O: " + o); outputs.add(tc); final int index = o; @@ -63,7 +66,7 @@ public class TestCaseTable extends Stage { } }); tc.setSortable(false); - tc.prefWidthProperty().bind(table.widthProperty().divide(testCaseProblem.getInputCount() + testCaseProblem.getOutputCount())); + tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs())); } table.getColumns().addAll(inputs); -- cgit v1.2.3