From a00b13c12e6fd9f91ee156d5db96e02853d2e410 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 24 Nov 2014 11:30:21 +0000 Subject: Fixed formatting, removed commented out code, added comments to handlers and locking stuff. --- src/jcgp/gui/population/GUIConnection.java | 6 ++++++ src/jcgp/gui/population/GUIGene.java | 24 +++++++++++++++++++++++- src/jcgp/gui/population/GUIInput.java | 6 ------ src/jcgp/gui/population/GUIMutable.java | 6 +----- src/jcgp/gui/population/GUIOutput.java | 15 +++++++-------- 5 files changed, 37 insertions(+), 20 deletions(-) (limited to 'src/jcgp/gui/population') diff --git a/src/jcgp/gui/population/GUIConnection.java b/src/jcgp/gui/population/GUIConnection.java index 3a0ad67..dc7fcc8 100644 --- a/src/jcgp/gui/population/GUIConnection.java +++ b/src/jcgp/gui/population/GUIConnection.java @@ -21,6 +21,12 @@ public interface GUIConnection { */ public void setStateRecursively(GUIGeneState state); + /** + * Add or remove a lock, but also recursively propagate that change + * all the way back to the inputs. + * + * @param value true to lock, false to unlock. + */ public void setLockRecursively(boolean value); } diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java index 02b87e7..f0fd568 100644 --- a/src/jcgp/gui/population/GUIGene.java +++ b/src/jcgp/gui/population/GUIGene.java @@ -14,7 +14,14 @@ import jcgp.gui.constants.Constants; *

* In practice, this is subclass of {@code javafx.scene.Group} containing a {@code Circle} * object and a {@code Text} object. Subclasses may add further elements to the group, for - * instance to display connection input and output sockets. + * instance to display connection input and output sockets. + *

+ * Genes also contain a locked property. When locked, some gene states behave slightly + * differently. This is used so genes remain highlighted even in the neutral state. The + * gene lock is in fact recursive; a gene can be locked multiple times and only unlocking + * it as many times will actually revert it back to its unlocked state. This allows multiple + * pathways to lock the same gene independently without affecting each other; the gene remains + * locked until no pathways are locking it. * * @author Eduardo Pedroni * @@ -55,6 +62,10 @@ public abstract class GUIGene extends Group { private Text text; private Circle mainCircle; + /** + * Recursive lock; lock == 0 means unlocked, lock > 0 means locked. + * Accessing using {@code setLock(...)}. + */ private int lock = 0; /** @@ -134,10 +145,21 @@ public abstract class GUIGene extends Group { */ protected abstract void setLinesVisible(boolean value); + /** + * @return true if the gene is locked, false otherwise. + */ public boolean isLocked() { return lock > 0; } + /** + * Locks or unlocks the gene once. Locked genes + * behave slightly differently in some states. + *
+ * Unlocking an already unlocked gene does nothing. + * + * @param value true to lock, false to unlock; + */ public void setLock(boolean value) { if (value) { lock++; diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java index d899585..3db7416 100644 --- a/src/jcgp/gui/population/GUIInput.java +++ b/src/jcgp/gui/population/GUIInput.java @@ -55,17 +55,11 @@ public class GUIInput extends GUIGene implements GUIConnection { this.input = input; } - /* (non-Javadoc) - * @see jcgp.gui.population.GUIConnection#setStateRecursively(jcgp.gui.population.GUIGene.GUIGeneState) - */ @Override public void setStateRecursively(GUIGeneState state) { setState(state); } - /* (non-Javadoc) - * @see jcgp.gui.population.GUIGene#setLinesVisible(boolean) - */ @Override protected void setLinesVisible(boolean value) {} diff --git a/src/jcgp/gui/population/GUIMutable.java b/src/jcgp/gui/population/GUIMutable.java index 61a8f48..b210672 100644 --- a/src/jcgp/gui/population/GUIMutable.java +++ b/src/jcgp/gui/population/GUIMutable.java @@ -9,8 +9,4 @@ package jcgp.gui.population; * @author Eduardo Pedroni * */ -public interface GUIMutable { - - - -} +public interface GUIMutable {} diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java index 9ffef1d..3bc81d9 100644 --- a/src/jcgp/gui/population/GUIOutput.java +++ b/src/jcgp/gui/population/GUIOutput.java @@ -46,6 +46,13 @@ public class GUIOutput extends GUIGene implements GUIMutable { OutputHandlers.addHandlers(this); } + /** + * @return the {@code Output} instance associated with this object. + */ + public Output getOutput() { + return output; + } + /** * Associates this instance with a new output. * @@ -55,14 +62,6 @@ public class GUIOutput extends GUIGene implements GUIMutable { this.output = output; } - /** - * @return the {@code Output} instance associated with this object. - */ - public Output getOutput() { - return output; - } - - /** * @return this output's single connection line. */ -- cgit v1.2.3