aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population
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/jcgp/gui/population
parent952b6d502da5896b59ffecdb5fa6f9c56458a02c (diff)
Moved constants to a separate file, added a formal README
Diffstat (limited to 'src/jcgp/gui/population')
-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
6 files changed, 63 insertions, 67 deletions
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());
}