From aa9e74e7f67789f6353fc26e02ee8e68e40609a2 Mon Sep 17 00:00:00 2001
From: Eduardo Pedroni <ep625@york.ac.uk>
Date: Sun, 4 May 2014 19:23:52 +0100
Subject: Added more comments, minor refactorings

---
 src/jcgp/gui/GUI.java                              |  9 +++-
 src/jcgp/gui/dragresize/HorizontalDragResize.java  |  3 +-
 src/jcgp/gui/dragresize/VerticalDragResize.java    |  1 -
 src/jcgp/gui/population/GUIGene.java               |  3 --
 src/jcgp/gui/population/GUIInput.java              |  5 ---
 src/jcgp/gui/population/GUINode.java               | 12 +++---
 src/jcgp/gui/population/GUIOutput.java             |  5 ---
 src/jcgp/gui/settings/SettingsPane.java            |  4 +-
 .../settings/parameters/GUIBooleanParameter.java   |  6 +--
 .../settings/parameters/GUIDoubleParameter.java    | 11 +++--
 .../settings/parameters/GUIIntegerParameter.java   | 10 ++---
 src/jcgp/gui/settings/parameters/GUIParameter.java | 49 +++++++++++-----------
 12 files changed, 54 insertions(+), 64 deletions(-)

(limited to 'src/jcgp/gui')

diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java
index 62a159c..cd4778f 100644
--- a/src/jcgp/gui/GUI.java
+++ b/src/jcgp/gui/GUI.java
@@ -21,6 +21,13 @@ import jcgp.gui.population.GUINode;
 import jcgp.gui.population.PopulationPane;
 import jcgp.gui.settings.SettingsPane;
 
+/**
+ * Main class for the graphical user interface (GUI)
+ * 
+ * 
+ * @author Eduardo Pedroni
+ *
+ */
 public class GUI extends Application {
 	
 	/* Colours */
@@ -185,8 +192,8 @@ public class GUI extends Application {
 	public void reset() {
 		if (!running && settingsPane.areParametersValid()) {
 			setEvaluating(false);
-			settingsPane.applyParameters();
 			jcgp.reset();
+			settingsPane.applyParameters();
 			reDraw();
 		}
 	}
diff --git a/src/jcgp/gui/dragresize/HorizontalDragResize.java b/src/jcgp/gui/dragresize/HorizontalDragResize.java
index 3acfd4a..84c322f 100644
--- a/src/jcgp/gui/dragresize/HorizontalDragResize.java
+++ b/src/jcgp/gui/dragresize/HorizontalDragResize.java
@@ -7,10 +7,11 @@ import javafx.scene.layout.Region;
 import jcgp.gui.GUI;
 
 /**
+ * 
+ * Decorator pattern.
  * 
  * http://andrewtill.blogspot.co.uk/2012/12/dragging-to-resize-javafx-region.html
  * 
- *
  */
 public class HorizontalDragResize {
 	
diff --git a/src/jcgp/gui/dragresize/VerticalDragResize.java b/src/jcgp/gui/dragresize/VerticalDragResize.java
index 8d79a2e..9397e5d 100644
--- a/src/jcgp/gui/dragresize/VerticalDragResize.java
+++ b/src/jcgp/gui/dragresize/VerticalDragResize.java
@@ -10,7 +10,6 @@ import jcgp.gui.GUI;
  * 
  * http://andrewtill.blogspot.co.uk/2012/12/dragging-to-resize-javafx-region.html
  * 
- *
  */
 public class VerticalDragResize {
 	
diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java
index c41261d..3ace150 100644
--- a/src/jcgp/gui/population/GUIGene.java
+++ b/src/jcgp/gui/population/GUIGene.java
@@ -8,7 +8,6 @@ import javafx.scene.text.Font;
 import javafx.scene.text.Text;
 import javafx.scene.text.TextAlignment;
 import jcgp.backend.population.Connection;
-import jcgp.backend.population.Gene;
 
 public abstract class GUIGene extends Group {
 
@@ -83,8 +82,6 @@ public abstract class GUIGene extends Group {
 	
 	public abstract void updateLines();
 	
-	public abstract Gene getGene();
-	
 	public abstract void setChangingConnection(Connection newConnection);
 	
 	public abstract Connection getChangingConnection();
diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java
index 065c125..05372c4 100644
--- a/src/jcgp/gui/population/GUIInput.java
+++ b/src/jcgp/gui/population/GUIInput.java
@@ -165,11 +165,6 @@ public class GUIInput extends GUIGene {
 		
 	}
 
-	@Override
-	public Input getGene() {
-		return input;
-	}
-
 	/**
 	 * Set all connections to a given state.
 	 * 
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index 731db8f..6dfeaa4 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -319,7 +319,7 @@ public class GUINode extends GUIGene {
 				return true;
 			} else if (target instanceof GUINode) {
 				// target and source are nodes, let's look at levels back
-				Node t = ((GUINode) target).getGene(), s = ((GUINode) source).getGene();
+				Node t = ((GUINode) target).getNode(), s = ((GUINode) source).getNode();
 				if (s.getColumn() - t.getColumn() > 0 && s.getColumn() - t.getColumn() <= resources.levelsBack()) {
 					return true;
 				}
@@ -344,6 +344,10 @@ public class GUINode extends GUIGene {
 	}
 
 
+	public Node getNode() {
+		return node;
+	}
+
 	/**
 	 * Place the end of the specified line on the output of the associated connection. 
 	 * 
@@ -383,12 +387,6 @@ public class GUINode extends GUIGene {
 		}
 	}
 
-	@Override
-	public Node getGene() {
-		return node;
-	}
-
-
 	@Override
 	public void setConnections(GUIGeneState newState) {
 		for (int i = 0; i < lines.length; i++) {
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java
index 79159b9..29752cd 100644
--- a/src/jcgp/gui/population/GUIOutput.java
+++ b/src/jcgp/gui/population/GUIOutput.java
@@ -239,11 +239,6 @@ public class GUIOutput extends GUIGene {
 		}
 	}
 
-	@Override
-	public Output getGene() {
-		return output;
-	}
-
 	@Override
 	public void setConnections(GUIGeneState newState) {
 		parent.getGuiGene(output.getSource()).setState(newState);
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java
index e3d2096..802c1f1 100644
--- a/src/jcgp/gui/settings/SettingsPane.java
+++ b/src/jcgp/gui/settings/SettingsPane.java
@@ -235,7 +235,7 @@ public class SettingsPane extends AnchorPane {
 	}
 	
 	private Button makeLoadTestCaseButton() {
-		Button b = new Button("Load problem data");
+		Button b = new Button("Load data");
 		b.setOnAction(new EventHandler<ActionEvent>() {
 			@Override
 			public void handle(ActionEvent event) {
@@ -255,7 +255,7 @@ public class SettingsPane extends AnchorPane {
 	}
 
 	private Button makeTestCaseButton() {
-		Button b = new Button("Show test cases");
+		Button b = new Button("Show data1");
 		b.setOnAction(new EventHandler<ActionEvent>() {
 			@Override
 			public void handle(ActionEvent event) {
diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
index eb669bb..29f8e1f 100644
--- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
@@ -9,9 +9,9 @@ import jcgp.backend.parameters.ParameterStatus;
 import jcgp.gui.settings.SettingsPane;
 
 /**
- * This extension of GUIParameter uses a CheckBox to display
- * the value of a BooleanParameter. It cannot be constructed
- * directly - instead, use GUIParameter.create().
+ * This extension of @code{GUIParameter} uses a @code{CheckBox} to display
+ * the value of a @code{BooleanParameter}. It cannot be constructed
+ * directly - instead, use @code{GUIParameter.create()}.
  * <br><br>
  * See {@link GUIParameter} for more information.
  * 
diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
index 16a4cd4..c3c1f59 100644
--- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
@@ -12,9 +12,9 @@ import jcgp.backend.parameters.ParameterStatus;
 import jcgp.gui.settings.SettingsPane;
 
 /**
- * This extension of GUIParameter uses a TextField to display
- * the value of a DoubleParameter. It cannot be constructed
- * directly - instead, use GUIParameter.create().
+ * This extension of @code{GUIParameter} uses a @code{TextField} to display
+ * the value of a @code{DoubleParameter}. It cannot be constructed
+ * directly - instead, use @code{GUIParameter.create()}.
  * <br><br>
  * See {@link GUIParameter} for more information.
  * 
@@ -26,11 +26,11 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
 	private DecimalFormat decimalFormat;
 	
 	/**
-	 * This default-visibility constructor is intended for use
+	 * This protected constructor is intended for use
 	 * by the factory method only.
 	 * 
 	 */
-	GUIDoubleParameter(Parameter<Number> parameter, SettingsPane sp) {
+	protected GUIDoubleParameter(Parameter<Number> parameter, SettingsPane sp) {
 		super(parameter, sp);
 	}
 	
@@ -57,7 +57,6 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
 					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.isEmpty()) {
 							double value = Double.parseDouble(newValue);
diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
index e8a9183..5bf6d9c 100644
--- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
@@ -10,9 +10,9 @@ import jcgp.backend.parameters.ParameterStatus;
 import jcgp.gui.settings.SettingsPane;
 
 /**
- * This extension of GUIParameter uses a TextField to display
- * the value of a IntegerParameter. It cannot be constructed
- * directly - instead, use GUIParameter.create().
+ * This extension of @code{GUIParameter} uses a @code{TextField} to display
+ * the value of a @code{IntegerParameter}. It cannot be constructed
+ * directly - instead, use @code{GUIParameter.create()}.
  * <br><br>
  * See {@link GUIParameter} for more information.
  * 
@@ -23,11 +23,11 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
 	private TextField textField;
 	
 	/**
-	 * This default-visibility constructor is intended for use
+	 * This protected constructor is intended for use
 	 * by the factory method only.
 	 * 
 	 */
-	GUIIntegerParameter(Parameter<Number> parameter, SettingsPane sp) {
+	protected GUIIntegerParameter(Parameter<Number> parameter, SettingsPane sp) {
 		super(parameter, sp);
 	}
 
diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java
index 0a9149f..3009340 100644
--- a/src/jcgp/gui/settings/parameters/GUIParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIParameter.java
@@ -20,14 +20,16 @@ import jcgp.gui.settings.SettingsPane;
 
 /**
  * 
- * This is the base class for all GUIParameters. Using the factory method GUIParameter.create()
+ * This is the base class for all @code{GUIParameter}s. Using the factory method @code{GUIParameter.create()}
  * generates an appropriate instance of this class for the specified parameter.
  * <br><br>
- * GUIParameter is an HBox containing a Text for the parameter name and a Control for interaction.
- * It stores an instance of its associated Parameter object and also contains a Tooltip for 
+ * @code{GUIParameter} is an @code{HBox} containing a @code{Text} for the parameter name 
+ * and a @code{Control} for interaction.
+ * It stores an instance of its associated @code{Parameter} object and also contains a @code{Tooltip} for 
  * displaying status information.
  * <br><br>
- * Monitor parameters have their Control disabled so that no changed can be made via the GUI.
+ * Monitor parameters are updated automatically and have their @code{Control} disabled so
+ * that no changes 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.
  * 
@@ -64,12 +66,12 @@ public abstract class GUIParameter<T> extends HBox {
 	
 	/**
 	 * This protected template constructor contains the common elements to all
-	 * GUIParameters and should be invoked by any subclasses using super(). It
+	 * @code{GUIParameter}s and should be invoked by any subclasses using @code{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 @code{Parameter} for which to generate a @code{GUIParameter}.
+	 * @param sp a reference to the @code{SettingsPane}.
 	 */
 	protected GUIParameter(Parameter<T> parameter, final SettingsPane settingsPane) {
 		this.parameter = parameter;
@@ -105,13 +107,13 @@ public abstract class GUIParameter<T> extends HBox {
 	}
 	
 	/**
-	 * Factory method to create GUIParameters from Parameters. 
-	 * Use this to create an appropriate GUIParameter from any instance of Parameter,
-	 * rather than manually downcasting the Parameter object every time.
+	 * Factory method to create @code{GUIParameter}s from @code{Parameter}s. 
+	 * Use this to create an appropriate @code{GUIParameter} from any instance of @code{Parameter},
+	 * rather than manually downcasting the @code{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 @code{GUIParameter}.
+	 * @param sp a reference to the @code{SettingsPane}.
+	 * @return an appropriate instance of @code{GUIParameter}.
 	 */
 	public static GUIParameter<?> create(Parameter<?> parameter, SettingsPane sp) {
 		if (parameter instanceof IntegerParameter) {
@@ -171,7 +173,7 @@ public abstract class GUIParameter<T> extends HBox {
 	
 	/**
 	 * Force the parameter to validate its current value, and apply the associated
-	 * style to the GUIParameter.
+	 * style to the @code{GUIParameter}.
 	 */
 	public void validate() {
 		parameter.validate(parameter.get());
@@ -190,7 +192,7 @@ public abstract class GUIParameter<T> extends HBox {
 	}
 	
 	/**
-	 * Set the current parameter value as the reference value of the GUIParameter.
+	 * Set the current parameter value as the reference value of the @code{GUIParameter}.
 	 * The new reference value will be used to determine the validity of the parameter, 
 	 * should its value change.
 	 */
@@ -203,31 +205,28 @@ public abstract class GUIParameter<T> extends HBox {
 	 * GUIParameter() as necessary.
 	 */
 	/**
-	 * This method returns the Control object used to control the parameter.
+	 * This method returns the @code{Control} object used to control the parameter.
 	 * <br><br>
-	 * Implementations of GUIParameter must override this method and return 
-	 * a control appropriate to the type of parameter. This will typically be
-	 * done by referencing the protected field GUIParameter.parameter.
+	 * Implementations of @code{GUIParameter} must override this method and return 
+	 * a @code{Control} appropriate to the type of parameter. This will typically be
+	 * done by referencing the protected field @code{GUIParameter.parameter}.
 	 * 
 	 * @return the Control object to be added to the GUIParameter.
 	 */
 	protected abstract Control makeControl();
 	
 	/**
-	 * Adds the necessary handlers to the Control object in order to modify
+	 * Adds the necessary handlers to the @code{Control} object in order to modify
 	 * the underlying parameter. This will typically consist of filtering key
 	 * presses to ensure no invalid characters are inserted, applying the new 
 	 * value to the underlying parameter and revalidating the parameters to
 	 * reflect the changes made.
-	 * <br><br>
-	 * Note that changelisteners registered to the main content property of the
-	 * control should always call handleChange() to update the 
 	 */
 	protected abstract void setControlListeners();
 	
 	/**
-	 * This method is called to style the GUIParameter according to the status of
-	 * the parameter, which can be obtained with parameter.getStatus(). While the
+	 * This method is called to style the @code{GUIParameter} according to the status of
+	 * the parameter, which can be obtained with @code{parameter.getStatus()}. While the
 	 * subclass is free to style itself in any way, the CSS strings defined here 
 	 * (INVALID_PARAMETER_STYLE, WARNING_PARAMETER_STYLE, VALID_PARAMETER_STYLE)
 	 * provide a way to keep the GUI consistent.
-- 
cgit v1.2.3