diff options
Diffstat (limited to 'src/jcgp/gui/handlers/OutputHandlers.java')
-rw-r--r-- | src/jcgp/gui/handlers/OutputHandlers.java | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/jcgp/gui/handlers/OutputHandlers.java b/src/jcgp/gui/handlers/OutputHandlers.java index 7399e50..f72e430 100644 --- a/src/jcgp/gui/handlers/OutputHandlers.java +++ b/src/jcgp/gui/handlers/OutputHandlers.java @@ -7,55 +7,69 @@ import jcgp.gui.population.GUIConnection; import jcgp.gui.population.GUIGene.GUIGeneState; import jcgp.gui.population.GUIOutput; +/** + * Holds the handlers that define the behaviour of {@code GUIOutput}. + * <br><br> + * The handlers are instantiated here statically and added to {@code GUIOutput} + * instances using {@code OutputHandlers.addHandlers(...)}. This guarantees that + * all outputs behave the same way without instantiating a new set of handlers for + * each output instance. + * + * @author Eduardo Pedroni + * + */ public final class OutputHandlers { + /** + * Set the output to {@code GUIGeneState.HOVER} state, and recursively set its active genes + * to {@code GUIGeneState.ACTIVE_HOVER}. + */ private static EventHandler<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // acquire the source, we can safely cast it to GUIOutput GUIOutput source = (GUIOutput) event.getSource(); - //if (!source.isLocked()) { - source.setState(GUIGeneState.HOVER); - ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.ACTIVE_HOVER); - //} + source.setState(GUIGeneState.HOVER); + ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.ACTIVE_HOVER); } }; + /** + * Set the output and all of its active genes to {@code GUIGeneState.NEUTRAL} state. + */ private static EventHandler<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // acquire the source, we can safely cast it to GUIOutput GUIOutput source = (GUIOutput) event.getSource(); - - //if (!source.isLocked()) { - source.setState(GUIGeneState.NEUTRAL); - ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.NEUTRAL); - //} - + + source.setState(GUIGeneState.NEUTRAL); + ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.NEUTRAL); } }; + /** + * If the output is locked, unlock it and all of its associated genes recursively. If it is unlocked, + * lock it and its active genes. + */ private static EventHandler<MouseEvent> mouseClickHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // acquire the source, we can safely cast it to GUIOutput GUIOutput source = (GUIOutput) event.getSource(); - if (source.isLocked()) { - source.setLock(false); - ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setLockRecursively(false); - } else { - source.setLock(true); - ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setLockRecursively(true); - } - -// source.setState(GUIGeneState.HOVER); -// ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setStateRecursively(GUIGeneState.ACTIVE_HOVER); - + boolean lock = !source.isLocked(); + source.setLock(lock); + ((GUIConnection) ((Gene) source.getOutput().getSource()).getGUIObject()).setLockRecursively(lock); } }; + /** + * Adds all handlers to the specified output. + * + * @param output the {@code GUIOutput} to which the handlers will be added. + */ public static void addHandlers(GUIOutput output) { output.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler); output.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler); |