aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUIGene.java
blob: 3d9cffb8f9c6108e01aa5d4a2bef8454f4a80c5e (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package jcgp.gui.population;

import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import jcgp.backend.population.Connection;

public abstract class GUIGene extends Group {

	public static final double NODE_RADIUS = 35;
	public static final double SPACING = 15;
	
	public static final double THETA = Math.PI / 1.4;
	public static final double SOCKET_RADIUS = Math.sqrt(NODE_RADIUS) / 1.8;
	
	public static final double NODE_TEXT = NODE_RADIUS / 2.5;
	
	public enum GUIGeneState {
		NEUTRAL,
		HOVER,
		INDIRECT_HOVER,
		ACTIVE_HOVER,
		LOCKED_HOVER,
		SOURCE,
		TARGET,
		NO_CHANGE_TARGET,
		FORBIDDEN_TARGET
	}
	
	protected Text text = new Text();
	protected Circle mainCircle = new Circle(NODE_RADIUS, Paint.valueOf("white"));
	
	private GUIGeneState state = GUIGeneState.NEUTRAL;

	protected ChromosomePane parent;
	
	protected int locked = 0;

	public GUIGene() {
		text.setFont(Font.font("Arial", 12));
		text.setTextOrigin(VPos.CENTER);
		text.setTextAlignment(TextAlignment.CENTER);
		text.setWrappingWidth(NODE_RADIUS * 2);
		text.setX(-NODE_RADIUS);
		text.setVisible(true);
		
		mainCircle.setStroke(Paint.valueOf("black"));
	}
	
	public void setState(GUIGeneState newState) {
		state = newState;
	}
	
	public GUIGeneState getState() {
		return state;
	}

	public boolean isLocked() {
		return locked > 0;
	}
	
	public int getLocks() {
		return locked;
	}
	
	abstract void setLocked(boolean value);
	
	public abstract void addLocks(int value);
	
	public abstract void removeLocks(int value);
	
	public abstract void updateLines();
	
	public abstract void setChangingConnection(Connection newConnection);
	
	public abstract Connection getChangingConnection();

	public abstract void setConnections(GUIGeneState newState);

	public abstract void resetState();
	
	public abstract void setConnectionLine(GUIGene gene);
	
	public abstract void updateText();
}