aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-24 08:14:12 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-24 08:14:12 +0000
commita09124d93c3e31d4e25ffe6c2f0a7663c02c35ed (patch)
treeffd47d8d16bbc20ac900db067f73146b66ae6e27 /src/jcgp/gui/population
parent0c288cc1952809294c8d70d86b9f41b04878ac2e (diff)
Going further into active path locking
Diffstat (limited to 'src/jcgp/gui/population')
-rw-r--r--src/jcgp/gui/population/GUIGene.java8
-rw-r--r--src/jcgp/gui/population/GUIInput.java14
-rw-r--r--src/jcgp/gui/population/GUINode.java48
-rw-r--r--src/jcgp/gui/population/GUIOutput.java39
4 files changed, 73 insertions, 36 deletions
diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java
index ef44110..830192c 100644
--- a/src/jcgp/gui/population/GUIGene.java
+++ b/src/jcgp/gui/population/GUIGene.java
@@ -34,6 +34,8 @@ public abstract class GUIGene extends Group {
protected ChromosomePane parent;
+ protected int locked = 0;
+
public SimpleObjectProperty<GUIGeneState> stateProperty() {
return stateProperty;
}
@@ -46,6 +48,12 @@ public abstract class GUIGene extends Group {
text.setVisible(value);
}
+ public boolean isLocked() {
+ return locked > 0;
+ }
+
+ public abstract void setLocked(boolean value);
+
public abstract Gene getGene();
public abstract void setConnections(GUIGeneState newState);
diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java
index 6f7a523..bf872dc 100644
--- a/src/jcgp/gui/population/GUIInput.java
+++ b/src/jcgp/gui/population/GUIInput.java
@@ -72,15 +72,6 @@ public class GUIInput extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -189,5 +180,10 @@ public class GUIInput extends GUIGene {
public void resetState() {
stateProperty.set(GUIGeneState.NEUTRAL);
+ }
+
+ @Override
+ public void setLocked(boolean value) {
+ locked += value ? 1 : -1;
}
}
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index 4350e52..c5ab43a 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -33,7 +33,7 @@ public class GUINode extends GUIGene {
private Node node;
private int connectionIndex;
-
+
public GUINode(ChromosomePane parentRef, final Node node, Resources resources, Line[] connectionLines) {
// store references
@@ -176,15 +176,6 @@ public class GUINode extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -244,8 +235,12 @@ public class GUINode extends GUIGene {
public void handle(MouseEvent event) {
// cursor has left this node without dragging, or it is dragging and this is the source
if (stateProperty.get() == GUIGeneState.HOVER) {
- stateProperty.set(GUIGeneState.NEUTRAL);
- setConnections(GUIGeneState.NEUTRAL);
+ if (isLocked()) {
+
+ } else {
+ stateProperty.set(GUIGeneState.NEUTRAL);
+ setConnections(GUIGeneState.NEUTRAL);
+ }
}
}
});
@@ -270,7 +265,10 @@ public class GUINode extends GUIGene {
case HOVER:
mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR));
showLines(true);
- setConnections(GUIGeneState.INDIRECT_HOVER);
+ if (!isLocked()) {
+ setConnections(GUIGeneState.INDIRECT_HOVER);
+ }
+
break;
case INDIRECT_HOVER:
mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
@@ -392,9 +390,13 @@ public class GUINode extends GUIGene {
public void setConnections(GUIGeneState newState) {
for (int i = 0; i < lines.length; i++) {
if (node.getConnection(i) instanceof Node) {
- parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setState(newState);
+ if (!parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).isLocked()) {
+ parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setState(newState);
+ }
} else if (node.getConnection(i) instanceof Input) {
- parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setState(newState);
+ if (!parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).isLocked()) {
+ parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setState(newState);
+ }
}
}
}
@@ -413,5 +415,19 @@ public class GUINode extends GUIGene {
stateProperty.set(GUIGeneState.NEUTRAL);
setConnections(GUIGeneState.NEUTRAL);
}
-
+
+
+ @Override
+ public void setLocked(boolean value) {
+ locked += value ? 1 : -1;
+ stateProperty.set(locked > 0 ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER);
+
+ for (int i = 0; i < lines.length; i++) {
+ if (node.getConnection(i) instanceof Node) {
+ parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setLocked(value);
+ } else if (node.getConnection(i) instanceof Input) {
+ parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setLocked(value);
+ }
+ }
+ }
}
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java
index 602a022..415d0fd 100644
--- a/src/jcgp/gui/population/GUIOutput.java
+++ b/src/jcgp/gui/population/GUIOutput.java
@@ -129,15 +129,6 @@ public class GUIOutput extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -179,13 +170,25 @@ public class GUIOutput extends GUIGene {
}
});
+ addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ setLocked(!isLocked());
+ }
+ });
+
addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// cursor has left this node without dragging, or it is dragging and this is the source
if (stateProperty.get() == GUIGeneState.HOVER) {
- stateProperty.set(GUIGeneState.NEUTRAL);
- setConnections(GUIGeneState.NEUTRAL);
+ if (isLocked()) {
+
+ } else {
+ stateProperty.set(GUIGeneState.NEUTRAL);
+ setConnections(GUIGeneState.NEUTRAL);
+ }
+
}
}
});
@@ -274,4 +277,18 @@ public class GUIOutput extends GUIGene {
stateProperty.set(GUIGeneState.NEUTRAL);
setConnections(GUIGeneState.NEUTRAL);
}
+
+ @Override
+ public void setLocked(boolean value) {
+ //stateProperty.set(GUIGeneState.HOVER);
+ locked += value ? 1 : -1;
+ setConnections(value ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER);
+
+ if (output.getSource() instanceof Node) {
+ parent.getGuiNode(((Node) output.getSource()).getRow(), ((Node) output.getSource()).getColumn()).setLocked(value);
+ } else if (output.getSource() instanceof Input) {
+ parent.getGuiInput(((Input) output.getSource()).getIndex()).setLocked(value);
+ }
+
+ }
}