blob: 9d1f6a8046cc7b39076031129b82db93c75d8ac0 (
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
|
package jcgp.gui.handlers;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import jcgp.backend.population.Gene;
import jcgp.gui.GUI;
import jcgp.gui.population.GUIGene;
import jcgp.gui.population.GUIGene.GUIGeneState;
import jcgp.gui.population.GUINode;
public final class NodeHandlers {
private static EventHandler<MouseEvent> mouseEnteredHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// acquire the source, we can safely cast it to GUINode
GUINode source = (GUINode) event.getSource();
source.setState(GUIGeneState.HOVER);
/*
* What have I done? Have I gone too far?
* Have I unleashed an evil beyond control?
* Will the gods of type casting ever forgive me?
*/
for (int i = 0; i < GUI.resources.arity(); i++) {
((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.EXTENDED_HOVER);
}
}
};
private static EventHandler<MouseEvent> mouseExitedHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// acquire the source, we can safely cast it to GUINode
GUINode source = (GUINode) event.getSource();
source.setState(GUIGeneState.NEUTRAL);
/*
* Is this the end? Is there any hope for salvation?
* Am I damned beyond redemption?
*/
for (int i = 0; i < GUI.resources.arity(); i++) {
((GUIGene) ((Gene) source.getNode().getConnection(i)).getGUIObject()).setState(GUIGeneState.NEUTRAL);
}
}
};
public static void addHandlers(GUINode node) {
node.addEventHandler(MouseEvent.MOUSE_ENTERED, mouseEnteredHandler);
node.addEventHandler(MouseEvent.MOUSE_EXITED, mouseExitedHandler);
}
}
|