aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2014-10-10 13:22:16 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2014-10-10 13:22:16 +0200
commite145523a2ae686dd2a2ae7996639e6e8d14d992a (patch)
tree3ffaa3c13fc48f3c58b72a53bb6a6ca41bcf96da /src
parent952b6d502da5896b59ffecdb5fa6f9c56458a02c (diff)
Moved constants to a separate file, added a formal README
Diffstat (limited to 'src')
-rw-r--r--src/jcgp/gui/GUI.java57
-rw-r--r--src/jcgp/gui/console/ConsolePane.java8
-rw-r--r--src/jcgp/gui/constants/Constants.java116
-rw-r--r--src/jcgp/gui/dragresize/HorizontalDragResize.java4
-rw-r--r--src/jcgp/gui/dragresize/VerticalDragResize.java4
-rw-r--r--src/jcgp/gui/population/ChromosomePane.java11
-rw-r--r--src/jcgp/gui/population/FunctionSelector.java4
-rw-r--r--src/jcgp/gui/population/GUIGene.java15
-rw-r--r--src/jcgp/gui/population/GUIInput.java26
-rw-r--r--src/jcgp/gui/population/GUINode.java43
-rw-r--r--src/jcgp/gui/population/GUIOutput.java31
-rw-r--r--src/jcgp/gui/settings/SettingsPane.java9
-rw-r--r--src/jcgp/gui/settings/parameters/GUIBooleanParameter.java7
-rw-r--r--src/jcgp/gui/settings/parameters/GUIDoubleParameter.java9
-rw-r--r--src/jcgp/gui/settings/parameters/GUIIntegerParameter.java9
-rw-r--r--src/jcgp/gui/settings/parameters/GUIParameter.java8
16 files changed, 206 insertions, 155 deletions
diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java
index 8735ccd..d99bfbc 100644
--- a/src/jcgp/gui/GUI.java
+++ b/src/jcgp/gui/GUI.java
@@ -46,63 +46,6 @@ import jcgp.gui.settings.SettingsPane;
*
*/
public class GUI extends Application {
-
- /* Colours */
- /**
- * A string containing the hexadecimal colour used for representing neutrality.
- */
- public static final String NEUTRAL_COLOUR = "#FFFFFF";
- /**
- * A string containing the hexadecimal colour used for representing a hard highlight.
- * A "hard" select, for instance, happens when an output path is locked on the chromosome
- * pane.
- */
- public static final String HARD_HIGHLIGHT_COLOUR = "#5496FF";
- /**
- * A string containing the hexadecimal colour used for a medium highlight.
- * One example of such a selection is the colour applied to a node
- * when it is hovered over.
- */
- public static final String MEDIUM_HIGHLIGHT_COLOUR = "#75BAFF";
- /**
- * A string containing the hexadecimal colour used for a soft highlight.
- * When hovering over a node, its connections are soft-selected.
- */
- public static final String SOFT_HIGHLIGHT_COLOUR = "#C7DFFF";
-
- /**
- * A string containing the hexadecimal colour used for representing a good selection.
- * Ideally a shade of green, used for instance when a manual connection is valid.
- */
- public static final String GOOD_SELECTION_COLOUR = "#38C25B";
- /**
- * A string containing the hexadecimal colour used for representing a neutral selection.
- * Ideally a shade of yellow, used for instance when a manual connection is already the
- * current connection.
- */
- public static final String NEUTRAL_SELECTION_COLOUR = "#FFEF73";
- /**
- * A string containing the hexadecimal colour used for representing a bad selection.
- * Ideally a shade of red, use for instance when a manual connection is not valid.
- */
- public static final String BAD_SELECTION_COLOUR = "#FF5C5C";
-
- /* Sizes and distances */
- /**
- * The width or height of the area that can be clicked on
- * to drag-resize a pane.
- */
- public static final double RESIZE_MARGIN = 5.0;
- /**
- * The minimum width of the settings pane, to prevent it
- * from being resized beyond visibility.
- */
- public static final double SETTINGS_MIN_WIDTH = 200;
- /**
- * The minimum width of the console pane, to prevent it
- * from being resized beyond visibility.
- */
- public static final double CONSOLE_MIN_HEIGHT = 100;
/*
* Actual GUI elements
diff --git a/src/jcgp/gui/console/ConsolePane.java b/src/jcgp/gui/console/ConsolePane.java
index 1e07b7d..de193a5 100644
--- a/src/jcgp/gui/console/ConsolePane.java
+++ b/src/jcgp/gui/console/ConsolePane.java
@@ -13,7 +13,7 @@ import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import jcgp.backend.resources.Console;
-import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
/**
* Console pane used by the GUI to display CGP output messages.
@@ -92,13 +92,13 @@ public class ConsolePane extends AnchorPane implements Console {
clearConsole));
// anchor the text area so it resizes automatically
- AnchorPane.setTopAnchor(textArea, GUI.RESIZE_MARGIN);
+ AnchorPane.setTopAnchor(textArea, Constants.RESIZE_MARGIN);
AnchorPane.setBottomAnchor(textArea, 0.0);
AnchorPane.setRightAnchor(textArea, 0.0);
AnchorPane.setLeftAnchor(textArea, 0.0);
- setMinHeight(GUI.CONSOLE_MIN_HEIGHT);
- setPrefHeight(GUI.CONSOLE_MIN_HEIGHT);
+ setMinHeight(Constants.CONSOLE_MIN_HEIGHT);
+ setPrefHeight(Constants.CONSOLE_MIN_HEIGHT);
getChildren().add(textArea);
}
diff --git a/src/jcgp/gui/constants/Constants.java b/src/jcgp/gui/constants/Constants.java
new file mode 100644
index 0000000..350f8b1
--- /dev/null
+++ b/src/jcgp/gui/constants/Constants.java
@@ -0,0 +1,116 @@
+package jcgp.gui.constants;
+
+/**
+ * Holds the constants used in the GUI.
+ *
+ * @author Eduardo Pedroni
+ *
+ */
+public abstract class Constants {
+
+ /* Colours */
+ /**
+ * A string containing the hexadecimal colour used for representing neutrality.
+ */
+ public static final String NEUTRAL_COLOUR = "#FFFFFF";
+ /**
+ * A string containing the hexadecimal colour used for representing a hard highlight.
+ * A "hard" select, for instance, happens when an output path is locked on the chromosome
+ * pane.
+ */
+ public static final String HARD_HIGHLIGHT_COLOUR = "#5496FF";
+ /**
+ * A string containing the hexadecimal colour used for a medium highlight.
+ * One example of such a selection is the colour applied to a node
+ * when it is hovered over.
+ */
+ public static final String MEDIUM_HIGHLIGHT_COLOUR = "#75BAFF";
+ /**
+ * A string containing the hexadecimal colour used for a soft highlight.
+ * When hovering over a node, its connections are soft-selected.
+ */
+ public static final String SOFT_HIGHLIGHT_COLOUR = "#C7DFFF";
+ /**
+ * A string containing the hexadecimal colour used for representing a good selection.
+ * Ideally a shade of green, used for instance when a manual connection is valid.
+ */
+ public static final String GOOD_SELECTION_COLOUR = "#38C25B";
+ /**
+ * A string containing the hexadecimal colour used for representing a neutral selection.
+ * Ideally a shade of yellow, used for instance when a manual connection is already the
+ * current connection.
+ */
+ public static final String NEUTRAL_SELECTION_COLOUR = "#FFEF73";
+ /**
+ * A string containing the hexadecimal colour used for representing a bad selection.
+ * Ideally a shade of red, use for instance when a manual connection is not valid.
+ */
+ public static final String BAD_SELECTION_COLOUR = "#FF5C5C";
+
+
+
+ /* Sizes and distances */
+ /**
+ * The width or height of the area that can be clicked on
+ * to drag-resize a pane.
+ */
+ public static final double RESIZE_MARGIN = 5.0;
+ /**
+ * The minimum width of the settings pane, to prevent it
+ * from being resized beyond visibility.
+ */
+ public static final double SETTINGS_MIN_WIDTH = 200;
+ /**
+ * The minimum width of the console pane, to prevent it
+ * from being resized beyond visibility.
+ */
+ public static final double CONSOLE_MIN_HEIGHT = 100;
+ /**
+ * Radius used for the representation of nodes in the grid.
+ */
+ public static final double NODE_RADIUS = 35;
+ /**
+ * Spacing between each node.
+ */
+ public static final double SPACING = 15;
+ /**
+ * The angle across which the node's sockets are evently distributed.
+ */
+ public static final double THETA = Math.PI / 1.4;
+ /**
+ * The radius of the connection sockets, calculated as a function of
+ * NODE_RADIUS.
+ *
+ */
+ public static final double SOCKET_RADIUS = Math.sqrt(NODE_RADIUS) / 1.8;
+ /**
+ * Size of the text in each node.
+ */
+ public static final double NODE_TEXT = NODE_RADIUS / 2.5;
+
+
+ /* CSS Styles
+ * TODO extract to stylesheet?
+ */
+ /**
+ * The basic style of text boxes used in parameters.
+ */
+ public static final String BASE_TEXT_STYLE = "-fx-border-color: #C9C9C9; -fx-border-radius: 2; -fx-padding: 0; ";
+ /**
+ * The basic style of check boxes used in parameters.
+ */
+ public static final String BASE_CHECKBOX_STYLE = "-fx-padding: 0; ";
+ /**
+ * The style applied to invalid parameters, using BAD_SELECTION_COLOUR.
+ */
+ public static final String INVALID_PARAMETER_STYLE = "-fx-background-color: " + BAD_SELECTION_COLOUR;
+ /**
+ * The style applied to neutral parameters, using NEUTRAL_SELECTION_COLOUR.
+ */
+ public static final String WARNING_PARAMETER_STYLE = "-fx-background-color: " + NEUTRAL_SELECTION_COLOUR;
+ /**
+ * The style applied to valid parameters, using NEUTRAL_COLOUR.
+ */
+ public static final String VALID_PARAMETER_STYLE = "-fx-background-color: " + NEUTRAL_COLOUR;
+
+}
diff --git a/src/jcgp/gui/dragresize/HorizontalDragResize.java b/src/jcgp/gui/dragresize/HorizontalDragResize.java
index b618b74..e88eafd 100644
--- a/src/jcgp/gui/dragresize/HorizontalDragResize.java
+++ b/src/jcgp/gui/dragresize/HorizontalDragResize.java
@@ -4,7 +4,7 @@ import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Region;
-import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
/**
* This class adds horizontal drag resize functionality to any
@@ -125,7 +125,7 @@ public class HorizontalDragResize {
* @return true if the mouse position is in the draggable area.
*/
private boolean isInDraggableZone(MouseEvent event) {
- return event.getX() < (GUI.RESIZE_MARGIN);
+ return event.getX() < (Constants.RESIZE_MARGIN);
}
}
diff --git a/src/jcgp/gui/dragresize/VerticalDragResize.java b/src/jcgp/gui/dragresize/VerticalDragResize.java
index 06186c6..4f784e5 100644
--- a/src/jcgp/gui/dragresize/VerticalDragResize.java
+++ b/src/jcgp/gui/dragresize/VerticalDragResize.java
@@ -4,7 +4,7 @@ import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Region;
-import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
/**
* This class adds vertical drag resize functionality to any
@@ -126,7 +126,7 @@ public class VerticalDragResize {
* @return true if the mouse position is in the draggable area.
*/
private boolean isInDraggableZone(MouseEvent event) {
- return event.getY() < (GUI.RESIZE_MARGIN);
+ return event.getY() < (Constants.RESIZE_MARGIN);
}
}
diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java
index 1e04c37..3546011 100644
--- a/src/jcgp/gui/population/ChromosomePane.java
+++ b/src/jcgp/gui/population/ChromosomePane.java
@@ -11,6 +11,7 @@ import jcgp.backend.population.Input;
import jcgp.backend.population.Node;
import jcgp.backend.resources.Resources;
import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
/**
* This extension of {@code ScrollPane} contains a series of
@@ -69,9 +70,9 @@ public class ChromosomePane extends ScrollPane {
// make the connection lines
Line lines[] = new Line[resources.arity()];
for (int l = 0; l < lines.length; l++) {
- angle = ((((double) (l + 1)) / ((double) (lines.length + 1))) * GUIGene.THETA) - (GUIGene.THETA / 2);
- xPos = (-Math.cos(angle) * GUIGene.NODE_RADIUS) + (((c + 1) * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS);
- yPos = (Math.sin(angle) * GUIGene.NODE_RADIUS) + ((r * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS);
+ angle = ((((double) (l + 1)) / ((double) (lines.length + 1))) * Constants.THETA) - (Constants.THETA / 2);
+ xPos = (-Math.cos(angle) * Constants.NODE_RADIUS) + (((c + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
+ yPos = (Math.sin(angle) * Constants.NODE_RADIUS) + ((r * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
lines[l] = new Line(xPos, yPos, xPos, yPos);
lines[l].setMouseTransparent(true);
@@ -86,8 +87,8 @@ public class ChromosomePane extends ScrollPane {
// outputs
guiOutputs = new GUIOutput[resources.outputs()];
for (int i = 0; i < guiOutputs.length; i++) {
- xPos = ((resources.columns() + 1) * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING));
- yPos = (chromosome.getOutput(i).getIndex() * (2 * GUIGene.NODE_RADIUS + GUIGene.SPACING)) + GUIGene.NODE_RADIUS;
+ xPos = ((resources.columns() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING));
+ yPos = (chromosome.getOutput(i).getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS;
// make the line
Line line = new Line(xPos, yPos, xPos, yPos);
line.setMouseTransparent(true);
diff --git a/src/jcgp/gui/population/FunctionSelector.java b/src/jcgp/gui/population/FunctionSelector.java
index 0e6c6bb..ac7a2c2 100644
--- a/src/jcgp/gui/population/FunctionSelector.java
+++ b/src/jcgp/gui/population/FunctionSelector.java
@@ -5,7 +5,7 @@ import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import jcgp.backend.function.FunctionSet;
-import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
/**
* A menu class, exposes all of the allowed functions
@@ -46,7 +46,7 @@ public class FunctionSelector extends VBox {
l.addEventFilter(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
- ((Label) event.getSource()).setStyle("-fx-background-color: " + GUI.SOFT_HIGHLIGHT_COLOUR + "; -fx-border-color: #B0B0B0; -fx-border-width: 0 0 1 0; -fx-padding: 2");
+ ((Label) event.getSource()).setStyle("-fx-background-color: " + Constants.SOFT_HIGHLIGHT_COLOUR + "; -fx-border-color: #B0B0B0; -fx-border-width: 0 0 1 0; -fx-padding: 2");
}
});
l.addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java
index 9980d53..bae7647 100644
--- a/src/jcgp/gui/population/GUIGene.java
+++ b/src/jcgp/gui/population/GUIGene.java
@@ -8,17 +8,10 @@ import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import jcgp.backend.population.Connection;
+import jcgp.gui.constants.Constants;
public abstract class GUIGene extends Group {
- public static final double NODE_RADIUS = 35;
- public static final double SPACING = 15;
-
- public static final double THETA = Math.PI / 1.4;
- public static final double SOCKET_RADIUS = Math.sqrt(NODE_RADIUS) / 1.8;
-
- public static final double NODE_TEXT = NODE_RADIUS / 2.5;
-
public enum GUIGeneState {
NEUTRAL,
HOVER,
@@ -32,7 +25,7 @@ public abstract class GUIGene extends Group {
}
protected Text text = new Text();
- protected Circle mainCircle = new Circle(NODE_RADIUS, Paint.valueOf("white"));
+ protected Circle mainCircle = new Circle(Constants.NODE_RADIUS, Paint.valueOf("white"));
private GUIGeneState state = GUIGeneState.NEUTRAL;
@@ -44,8 +37,8 @@ public abstract class GUIGene extends Group {
text.setFont(Font.font("Arial", 12));
text.setTextOrigin(VPos.CENTER);
text.setTextAlignment(TextAlignment.CENTER);
- text.setWrappingWidth(NODE_RADIUS * 2);
- text.setX(-NODE_RADIUS);
+ text.setWrappingWidth(Constants.NODE_RADIUS * 2);
+ text.setX(-Constants.NODE_RADIUS);
text.setVisible(true);
mainCircle.setStroke(Paint.valueOf("black"));
diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java
index a48be51..8b55a58 100644
--- a/src/jcgp/gui/population/GUIInput.java
+++ b/src/jcgp/gui/population/GUIInput.java
@@ -7,7 +7,7 @@ import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import jcgp.backend.population.Connection;
import jcgp.backend.population.Input;
-import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
public class GUIInput extends GUIGene {
@@ -19,12 +19,12 @@ public class GUIInput extends GUIGene {
this.parent = parentRef;
this.input = input;
- relocate(NODE_RADIUS,
- (input.getIndex() * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS);
+ relocate(Constants.NODE_RADIUS,
+ (input.getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
updateText();
- Circle outputSocket = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white"));
+ Circle outputSocket = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
outputSocket.setId(String.valueOf(0));
outputSocket.setStroke(Paint.valueOf("black"));
@@ -126,38 +126,38 @@ public class GUIInput extends GUIGene {
if (locked > 0) {
setState(GUIGeneState.LOCKED_HOVER);
} else {
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
}
break;
case INVALID_TARGET:
- mainCircle.setFill(Paint.valueOf(GUI.BAD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.BAD_SELECTION_COLOUR));
break;
case LOCKED_HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
break;
case HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR));
break;
case INDIRECT_HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
break;
case NEUTRAL:
if (locked > 0) {
setState(GUIGeneState.HOVER);
} else {
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR));
}
break;
case NO_CHANGE_TARGET:
parent.setTarget(true);
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_SELECTION_COLOUR));
break;
case SOURCE:
- mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR));
break;
case VALID_TARGET:
parent.setTarget(true);
- mainCircle.setFill(Paint.valueOf(GUI.GOOD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.GOOD_SELECTION_COLOUR));
break;
default:
break;
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index 142d650..4d420ea 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -13,6 +13,7 @@ import jcgp.backend.population.Input;
import jcgp.backend.population.Node;
import jcgp.backend.resources.Resources;
import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
public class GUINode extends GUIGene {
@@ -32,8 +33,8 @@ public class GUINode extends GUIGene {
this.resources = gui.getExperiment().getResources();
// move the GUIGene to the right position
- relocate(((node.getColumn() + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS,
- (node.getRow() * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS);
+ relocate(((node.getColumn() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS,
+ (node.getRow() * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
// set the line ends correctly
updateLines();
@@ -42,7 +43,7 @@ public class GUINode extends GUIGene {
connectionNumber.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5); ");
connectionNumber.setVisible(false);
- Circle output = new Circle(NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white"));
+ Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
output.setStroke(Paint.valueOf("black"));
updateText();
@@ -50,11 +51,11 @@ public class GUINode extends GUIGene {
Circle[] sockets = new Circle[resources.arity()];
double angle, xPos, yPos;
for (int l = 0; l < sockets.length; l++) {
- angle = (((l + 1) / ((double) (resources.arity() + 1))) * THETA) - (THETA / 2);
- xPos = -Math.cos(angle) * NODE_RADIUS;
- yPos = Math.sin(angle) * NODE_RADIUS;
+ angle = (((l + 1) / ((double) (resources.arity() + 1))) * Constants.THETA) - (Constants.THETA / 2);
+ xPos = -Math.cos(angle) * Constants.NODE_RADIUS;
+ yPos = Math.sin(angle) * Constants.NODE_RADIUS;
- sockets[l] = new Circle(xPos, yPos, GUIGene.SOCKET_RADIUS, Paint.valueOf("white"));
+ sockets[l] = new Circle(xPos, yPos, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
sockets[l].setId(String.valueOf(l));
sockets[l].setStroke(Paint.valueOf("black"));
@@ -253,19 +254,19 @@ public class GUINode extends GUIGene {
if (locked > 0) {
setState(GUIGeneState.LOCKED_HOVER);
} else {
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
showLines(true);
}
setConnectionStates(GUIGeneState.ACTIVE_HOVER);
break;
case LOCKED_HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
break;
case INVALID_TARGET:
- mainCircle.setFill(Paint.valueOf(GUI.BAD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.BAD_SELECTION_COLOUR));
break;
case HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR));
showLines(true);
if (locked <= 0) {
setConnectionStates(GUIGeneState.INDIRECT_HOVER);
@@ -274,13 +275,13 @@ public class GUINode extends GUIGene {
}
break;
case INDIRECT_HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
break;
case NEUTRAL:
if (locked > 0) {
setState(GUIGeneState.HOVER);
} else {
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR));
showLines(false);
if (getState() == GUIGeneState.ACTIVE_HOVER) {
setConnectionStates(GUIGeneState.NEUTRAL);
@@ -289,14 +290,14 @@ public class GUINode extends GUIGene {
break;
case NO_CHANGE_TARGET:
parent.setTarget(true);
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_SELECTION_COLOUR));
break;
case SOURCE:
- mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.HARD_HIGHLIGHT_COLOUR));
break;
case VALID_TARGET:
parent.setTarget(true);
- mainCircle.setFill(Paint.valueOf(GUI.GOOD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.GOOD_SELECTION_COLOUR));
break;
default:
break;
@@ -355,12 +356,12 @@ public class GUINode extends GUIGene {
if (node.getConnection(index) instanceof Node) {
int row = ((Node) node.getConnection(index)).getRow(),
column = ((Node) node.getConnection(index)).getColumn();
- lines[index].setEndX(((column + 1) * (2 * NODE_RADIUS + SPACING)) + 2 * NODE_RADIUS);
- lines[index].setEndY((row * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS);
+ lines[index].setEndX(((column + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + 2 * Constants.NODE_RADIUS);
+ lines[index].setEndY((row * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
} else if (node.getConnection(index) instanceof Input) {
int inputIndex = ((Input) node.getConnection(index)).getIndex();
- lines[index].setEndX(2 * NODE_RADIUS);
- lines[index].setEndY(inputIndex * (2 * NODE_RADIUS + SPACING) + NODE_RADIUS);
+ lines[index].setEndX(2 * Constants.NODE_RADIUS);
+ lines[index].setEndY(inputIndex * (2 * Constants.NODE_RADIUS + Constants.SPACING) + Constants.NODE_RADIUS);
}
}
@@ -444,7 +445,7 @@ public class GUINode extends GUIGene {
@Override
public void setConnectionLine(GUIGene gene) {
- lines[connectionIndex].setEndX(gene.getLayoutX() + NODE_RADIUS);
+ lines[connectionIndex].setEndX(gene.getLayoutX() + Constants.NODE_RADIUS);
lines[connectionIndex].setEndY(gene.getLayoutY());
}
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java
index a3f5a28..d715138 100644
--- a/src/jcgp/gui/population/GUIOutput.java
+++ b/src/jcgp/gui/population/GUIOutput.java
@@ -12,6 +12,7 @@ import jcgp.backend.population.Input;
import jcgp.backend.population.Node;
import jcgp.backend.population.Output;
import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
public class GUIOutput extends GUIGene {
@@ -25,14 +26,14 @@ public class GUIOutput extends GUIGene {
this.output = output;
this.sourceLine = line;
- relocate(((gui.getExperiment().getResources().columns() + 1) * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS,
- (output.getIndex() * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS);
+ relocate(((gui.getExperiment().getResources().columns() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS,
+ (output.getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
// set the line ends correctly
updateLines();
updateText();
- Circle socket = new Circle(-NODE_RADIUS, 0, SOCKET_RADIUS, Paint.valueOf("white"));
+ Circle socket = new Circle(-Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
socket.setId(String.valueOf(0));
socket.setStroke(Paint.valueOf("black"));
@@ -193,32 +194,32 @@ public class GUIOutput extends GUIGene {
case ACTIVE_HOVER:
break;
case INVALID_TARGET:
- mainCircle.setFill(Paint.valueOf(GUI.BAD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.BAD_SELECTION_COLOUR));
break;
case HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.MEDIUM_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.MEDIUM_HIGHLIGHT_COLOUR));
sourceLine.setVisible(true);
if (!isLocked()) {
setConnectionStates(GUIGeneState.ACTIVE_HOVER);
}
break;
case INDIRECT_HOVER:
- mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.SOFT_HIGHLIGHT_COLOUR));
break;
case NEUTRAL:
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_COLOUR));
sourceLine.setVisible(false);
break;
case NO_CHANGE_TARGET:
- mainCircle.setFill(Paint.valueOf(GUI.NEUTRAL_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.NEUTRAL_SELECTION_COLOUR));
break;
case SOURCE:
- mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.HARD_HIGHLIGHT_COLOUR));
setConnectionStates(GUIGeneState.NEUTRAL);
setConnectionStates(GUIGeneState.INDIRECT_HOVER);
break;
case VALID_TARGET:
- mainCircle.setFill(Paint.valueOf(GUI.GOOD_SELECTION_COLOUR));
+ mainCircle.setFill(Paint.valueOf(Constants.GOOD_SELECTION_COLOUR));
break;
default:
break;
@@ -230,12 +231,12 @@ public class GUIOutput extends GUIGene {
if (output.getSource() instanceof Node) {
int row = ((Node) output.getSource()).getRow(),
column = ((Node) output.getSource()).getColumn();
- sourceLine.setEndX(((column + 1) * (2 * NODE_RADIUS + SPACING)) + 2 * NODE_RADIUS);
- sourceLine.setEndY((row * (2 * NODE_RADIUS + SPACING)) + NODE_RADIUS);
+ sourceLine.setEndX(((column + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + 2 * Constants.NODE_RADIUS);
+ sourceLine.setEndY((row * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
} else if (output.getSource() instanceof Input) {
int inputIndex = ((Input) output.getSource()).getIndex();
- sourceLine.setEndX(2 * NODE_RADIUS);
- sourceLine.setEndY(inputIndex * (2 * NODE_RADIUS + SPACING) + NODE_RADIUS);
+ sourceLine.setEndX(2 * Constants.NODE_RADIUS);
+ sourceLine.setEndY(inputIndex * (2 * Constants.NODE_RADIUS + Constants.SPACING) + Constants.NODE_RADIUS);
}
}
@@ -287,7 +288,7 @@ public class GUIOutput extends GUIGene {
@Override
public void setConnectionLine(GUIGene gene) {
- sourceLine.setEndX(gene.getLayoutX() + NODE_RADIUS);
+ sourceLine.setEndX(gene.getLayoutX() + Constants.NODE_RADIUS);
sourceLine.setEndY(gene.getLayoutY());
}
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java
index c59244b..bad42cd 100644
--- a/src/jcgp/gui/settings/SettingsPane.java
+++ b/src/jcgp/gui/settings/SettingsPane.java
@@ -26,6 +26,7 @@ import jcgp.backend.modules.problem.Problem;
import jcgp.backend.modules.problem.TestCaseProblem;
import jcgp.backend.parameters.Parameter;
import jcgp.gui.GUI;
+import jcgp.gui.constants.Constants;
import jcgp.gui.settings.parameters.GUIParameter;
import jcgp.gui.settings.testcase.TestCaseTable;
@@ -79,10 +80,10 @@ public class SettingsPane extends AnchorPane {
// make the overarching container
mainContainer = new VBox(8);
- mainContainer.setPadding(new Insets(5, GUI.RESIZE_MARGIN, 0, 2));
+ mainContainer.setPadding(new Insets(5, Constants.RESIZE_MARGIN, 0, 2));
- setMinWidth(GUI.SETTINGS_MIN_WIDTH);
- setPrefWidth(GUI.SETTINGS_MIN_WIDTH);
+ setMinWidth(Constants.SETTINGS_MIN_WIDTH);
+ setPrefWidth(Constants.SETTINGS_MIN_WIDTH);
// initialise all sub-divisions
initialiseBaseParameters(jcgp);
@@ -105,7 +106,7 @@ public class SettingsPane extends AnchorPane {
AnchorPane.setTopAnchor(scroll, 0.0);
AnchorPane.setBottomAnchor(scroll, 0.0);
AnchorPane.setRightAnchor(scroll, 0.0);
- AnchorPane.setLeftAnchor(scroll, GUI.RESIZE_MARGIN);
+ AnchorPane.setLeftAnchor(scroll, Constants.RESIZE_MARGIN);
// add the scroll pane, all done!
getChildren().add(scroll);
diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
index a13a52b..a1f03fe 100644
--- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java
@@ -6,6 +6,7 @@ import javafx.scene.control.CheckBox;
import javafx.scene.control.Control;
import jcgp.backend.parameters.BooleanParameter;
import jcgp.backend.parameters.ParameterStatus;
+import jcgp.gui.constants.Constants;
import jcgp.gui.settings.SettingsPane;
/**
@@ -59,16 +60,16 @@ public class GUIBooleanParameter extends GUIParameter<Boolean> {
protected void setValidityStyle() {
// update the Control's style and tooltip based on the status of the parameter
if (parameter.getStatus() == ParameterStatus.INVALID) {
- checkBox.setStyle(BASE_CHECKBOX_STYLE + INVALID_PARAMETER_STYLE);
+ checkBox.setStyle(Constants.BASE_CHECKBOX_STYLE + Constants.INVALID_PARAMETER_STYLE);
checkBox.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else if (parameter.getStatus() == ParameterStatus.WARNING
|| parameter.getStatus() == ParameterStatus.WARNING_RESET) {
- checkBox.setStyle(BASE_CHECKBOX_STYLE + WARNING_PARAMETER_STYLE);
+ checkBox.setStyle(Constants.BASE_CHECKBOX_STYLE + Constants.WARNING_PARAMETER_STYLE);
checkBox.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else {
- checkBox.setStyle(BASE_CHECKBOX_STYLE + VALID_PARAMETER_STYLE);
+ checkBox.setStyle(Constants.BASE_CHECKBOX_STYLE + Constants.VALID_PARAMETER_STYLE);
checkBox.setTooltip(null);
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
index 9f4ea28..feee34c 100644
--- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java
@@ -9,6 +9,7 @@ import javafx.scene.control.Control;
import javafx.scene.control.TextField;
import jcgp.backend.parameters.DoubleParameter;
import jcgp.backend.parameters.ParameterStatus;
+import jcgp.gui.constants.Constants;
import jcgp.gui.settings.SettingsPane;
/**
@@ -40,7 +41,7 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
decimalFormat = new DecimalFormat();
decimalFormat.setMaximumFractionDigits(10);
textField = new TextField(decimalFormat.format(parameter.get().doubleValue()));
- textField.setStyle(VALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.VALID_PARAMETER_STYLE);
textField.setAlignment(Pos.CENTER_RIGHT);
textField.prefWidthProperty().bind(widthProperty().divide(2));
return textField;
@@ -87,15 +88,15 @@ public class GUIDoubleParameter extends GUIParameter<Number> {
protected void setValidityStyle() {
// update the Control's style and tooltip based on the status of the parameter
if (parameter.getStatus() == ParameterStatus.INVALID) {
- textField.setStyle(BASE_TEXT_STYLE + INVALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.INVALID_PARAMETER_STYLE);
textField.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) {
- textField.setStyle(BASE_TEXT_STYLE + WARNING_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.WARNING_PARAMETER_STYLE);
textField.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else {
- textField.setStyle(BASE_TEXT_STYLE + VALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.VALID_PARAMETER_STYLE);
textField.setTooltip(null);
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
index d36c1b3..bcfbe50 100644
--- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java
@@ -7,6 +7,7 @@ import javafx.scene.control.Control;
import javafx.scene.control.TextField;
import jcgp.backend.parameters.IntegerParameter;
import jcgp.backend.parameters.ParameterStatus;
+import jcgp.gui.constants.Constants;
import jcgp.gui.settings.SettingsPane;
/**
@@ -35,7 +36,7 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
protected Control makeControl() {
// this uses a text field
textField = new TextField(String.valueOf(parameter.get()));
- textField.setStyle(VALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.VALID_PARAMETER_STYLE);
textField.setAlignment(Pos.CENTER_RIGHT);
textField.prefWidthProperty().bind(widthProperty().divide(2));
@@ -83,16 +84,16 @@ public class GUIIntegerParameter extends GUIParameter<Number> {
protected void setValidityStyle() {
// update the Control's style and tooltip based on the status of the parameter
if (parameter.getStatus() == ParameterStatus.INVALID) {
- textField.setStyle(BASE_TEXT_STYLE + INVALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.INVALID_PARAMETER_STYLE);
textField.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else if (parameter.getStatus() == ParameterStatus.WARNING
|| parameter.getStatus() == ParameterStatus.WARNING_RESET) {
- textField.setStyle(BASE_TEXT_STYLE + WARNING_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.WARNING_PARAMETER_STYLE);
textField.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else {
- textField.setStyle(BASE_TEXT_STYLE + VALID_PARAMETER_STYLE);
+ textField.setStyle(Constants.BASE_TEXT_STYLE + Constants.VALID_PARAMETER_STYLE);
textField.setTooltip(null);
}
}
diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java
index 9188aec..59aecf6 100644
--- a/src/jcgp/gui/settings/parameters/GUIParameter.java
+++ b/src/jcgp/gui/settings/parameters/GUIParameter.java
@@ -15,7 +15,6 @@ 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;
/**
@@ -39,13 +38,6 @@ import jcgp.gui.settings.SettingsPane;
*/
public abstract class GUIParameter<T> extends HBox {
- public static final String BASE_TEXT_STYLE = "-fx-border-color: #C9C9C9; -fx-border-radius: 2; -fx-padding: 0; ";
- public static final String BASE_CHECKBOX_STYLE = "-fx-padding: 0; ";
-
- public static final String INVALID_PARAMETER_STYLE = "-fx-background-color: " + GUI.BAD_SELECTION_COLOUR;
- public static final String WARNING_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_SELECTION_COLOUR;
- public static final String VALID_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_COLOUR;
-
private Label name;
private Control valueControl;