aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/handlers/OutputHandlers.java
blob: 7399e503b9a8249af93beb0ad7215ad4234843d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package jcgp.gui.handlers;

import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import jcgp.backend.population.Gene;
import jcgp.gui.population.GUIConnection;
import jcgp.gui.population.GUIGene.GUIGeneState;
import jcgp.gui.population.GUIOutput;

public final class OutputHandlers {

	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);
			//}
		}
	};

	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);
			//}

		}
	};

	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);
			
		}
	};

	public static void addHandlers(GUIOutput output) {
		output.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler);
		output.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler);
		output.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseClickHandler);
	}

}