From 9aac9892b5c827e70c4598e0e052d10aad40a2d9 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 21 May 2014 07:13:49 +0100 Subject: Did some more comments, almost there... --- src/jcgp/gui/settings/SettingsPane.java | 105 +++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 22 deletions(-) (limited to 'src/jcgp/gui/settings/SettingsPane.java') diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index d9d8825..c0939e9 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -29,34 +29,62 @@ import jcgp.gui.GUI; import jcgp.gui.settings.parameters.GUIParameter; import jcgp.gui.settings.testcase.TestCaseTable; +/** + * This is a fairly hefty class which encapsulates the entire right-hand + * control pane. It contains base parameters, module selectors and their + * associated parameters, flow controls and file loading/saving buttons. + *

+ * A single instance of this class is used in {@code GUI}. + * + * + * @author Eduardo Pedroni + * + */ public class SettingsPane extends AnchorPane { + /* + * The primary containers, these make up each section of the settings pane. + */ private VBox mainContainer; private VBox baseParameterPane, eaPane, mutatorPane, problemPane; private VBox nodeFunctions; + // all buttons private Button runPause = new Button("Run"), step = new Button("Step"), reset = new Button("Reset"); private Button loadParameters = new Button("Load parameters"), loadChromosome = new Button("Load chromosome"), saveChromosome = new Button("Save chromosome"); + // this is a list of parameters used for parameter validity checks private ArrayList> parameters = new ArrayList>(); + // the test case table stage private TestCaseTable testCaseTable; + // a reference to the parent GUI private GUI gui; private int currentArity; + /** + * Create a new instance of {@code SettingsPane} associated + * with the specified {@code GUI} object. + * + * @param gui a reference to this object's parent. + */ public SettingsPane(GUI gui) { super(); this.gui = gui; + + // acquire a reference to jcgp, for convenience final JCGP jcgp = gui.getExperiment(); + // make the overarching container mainContainer = new VBox(8); mainContainer.setPadding(new Insets(5, GUI.RESIZE_MARGIN, 0, 2)); setMinWidth(GUI.SETTINGS_MIN_WIDTH); setPrefWidth(GUI.SETTINGS_MIN_WIDTH); + // initialise all sub-divisions initialiseBaseParameters(jcgp); initialiseEAParameters(jcgp); @@ -67,19 +95,27 @@ public class SettingsPane extends AnchorPane { createControls(gui); + // prepare the scroll pane ScrollPane scroll = new ScrollPane(); scroll.setFitToWidth(true); scroll.setContent(mainContainer); scroll.setStyle("-fx-background-color: #FFFFFF"); + // anchor the scroll pane to itself, bearing in mind the resize margin AnchorPane.setTopAnchor(scroll, 0.0); AnchorPane.setBottomAnchor(scroll, 0.0); AnchorPane.setRightAnchor(scroll, 0.0); AnchorPane.setLeftAnchor(scroll, GUI.RESIZE_MARGIN); + // add the scroll pane, all done! getChildren().add(scroll); } + /** + * Creates the base parameters pane + * + * @param jcgp + */ private void initialiseBaseParameters(JCGP jcgp) { baseParameterPane = new VBox(2); @@ -367,53 +403,73 @@ public class SettingsPane extends AnchorPane { } /** - * @param cgp - * @param vb + * Builds {@code GUIParameter}s and adds them to the provided {@code VBox}. + * The parameters built are taken from the specified list. + * + * @param newParameters the list of parameters to add. + * @param container the container to add the parameters to. */ - private void refreshParameters(ArrayList> newParameters, VBox vb) { - parameters.removeAll(vb.getChildren()); - vb.getChildren().clear(); + private void refreshParameters(ArrayList> newParameters, VBox container) { + // remove what is currently in the container from the parameter list + parameters.removeAll(container.getChildren()); + // remove everything in the container + container.getChildren().clear(); + // if there are parameters to add, add them all if (newParameters != null) { for (int i = 0; i < newParameters.size(); i++) { - GUIParameter gp = GUIParameter.create(newParameters.get(i), this); - parameters.add(gp); - vb.getChildren().add(gp); + // factory method returns the right subtype of GUIParameter + GUIParameter guiParameter = GUIParameter.create(newParameters.get(i), this); + // make sure to add it to the parameter list as well + parameters.add(guiParameter); + container.getChildren().add(guiParameter); } } + // do a quick refresh just in case something is invalid revalidateParameters(); } /** * This method handles a problem type change by updating the list of allowed * node functions. + *

+ * It does so by creating new checkboxes for each function in the function set. */ private void refreshFunctions() { + // remove all current functions nodeFunctions.getChildren().clear(); - CheckBox cb; - final FunctionSet fs = gui.getExperiment().getResources().getFunctionSet(); - for (int i = 0; i < fs.getTotalFunctionCount(); i++) { - cb = new CheckBox(fs.getFunction(i).toString()); - cb.setId(String.valueOf(i)); - cb.setSelected(fs.isEnabled(fs.getFunction(i))); + CheckBox checkBox; + // get a reference to the function set + final FunctionSet functionSet = gui.getExperiment().getResources().getFunctionSet(); + for (int i = 0; i < functionSet.getTotalFunctionCount(); i++) { + // add a checkbox for each function + checkBox = new CheckBox(functionSet.getFunction(i).toString()); + checkBox.setId(String.valueOf(i)); + // make sure the selection matches the function set + checkBox.setSelected(functionSet.isEnabled(functionSet.getFunction(i))); final int index = i; - cb.setOnAction(new EventHandler() { + // set listener so function set gets updated if the checkboxes change + checkBox.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { if (((CheckBox) event.getSource()).isSelected()) { - fs.enableFunction(index); + functionSet.enableFunction(index); } else { - fs.disableFunction(index); + functionSet.disableFunction(index); } gui.updateFunctionSelector(); revalidateParameters(); } }); - nodeFunctions.getChildren().add(cb); - - gui.updateFunctionSelector(); + // add the new checkbox + nodeFunctions.getChildren().add(checkBox); } + // make sure function selector has all functions + gui.updateFunctionSelector(); } + /** + * @return true if the experiment is currently evolving something, false otherwise. + */ public boolean isExperimentRunning() { return gui.isWorking(); } @@ -450,6 +506,9 @@ public class SettingsPane extends AnchorPane { * Calls validate() on every parameter. This is called whenever a parameter changes, * so that other parameters update their status in case they were dependent on the * changed parameter. + *

+ * This also disables the controls if a reset is necessary, preventing the experiment + * from running until it has happened. */ public void revalidateParameters() { boolean disableControls = false; @@ -470,6 +529,8 @@ public class SettingsPane extends AnchorPane { /** * Calls applyValue() on every parameter. This is called when a reset occurs, so that * the new value will be used as a reference instead of the old reference value. + *

+ * It also closes the test case table, just in case. */ public void applyParameters() { for (GUIParameter parameter : parameters) { @@ -486,8 +547,8 @@ public class SettingsPane extends AnchorPane { * experiment, in order to prevent inappropriate operations if the experiment is * running or finished. * - * @param running true if the experiment is running - * @param finished true if the experiment is finished + * @param running true if the experiment is running. + * @param finished true if the experiment is finished. */ public void updateControls(boolean running, boolean finished) { baseParameterPane.setDisable(running); -- cgit v1.2.3