aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUINode.java
blob: f8f2e2092a139a4ae35fd82fce2058c40bc3fbe2 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package jcgp.gui.population;

import javafx.scene.control.Label;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import jcgp.backend.population.Gene;
import jcgp.backend.population.Node;
import jcgp.gui.GUI;
import jcgp.gui.constants.Constants;

public class GUINode extends GUIGene implements GUIMutable, GUIConnection {

	private Node node;
	private Line[] lines;
	private Circle[] sockets;
	
	public GUINode(Node node, Line[] lines) {
		super();
		// store references
		this.node = node;
		this.lines = lines;
		
		Label connectionNumber = new Label();
		connectionNumber.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5);");
		connectionNumber.setVisible(false);

		Circle output = new Circle(Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
		output.setStroke(Paint.valueOf("black"));
		
		sockets = new Circle[GUI.resources.arity()];
		double angle, xPos, yPos;
		for (int l = 0; l < sockets.length; l++) {
			angle = (((l + 1) / ((double) (GUI.resources.arity() + 1))) * Constants.THETA) - (Constants.THETA / 2);
			xPos = -Math.cos(angle) * Constants.NODE_RADIUS;
			yPos = Math.sin(angle) * Constants.NODE_RADIUS;

			sockets[l] = new Circle(xPos, yPos, Constants.SOCKET_RADIUS, Paint.valueOf("white"));
			sockets[l].setId(String.valueOf(l));
			sockets[l].setStroke(Paint.valueOf("black"));
		}
		
		getChildren().addAll(sockets);
		getChildren().addAll(output, connectionNumber);
	}
	
	public Node getNode() {
		return node;
	}

	void setNode(Node node2) {
		// TODO Auto-generated method stub
		
	}
	
	public Line getLine(int index) {
		return lines[index];
	}
	
	public Line[] getLines() {
		return lines;
	}
	
	public Circle getSocket(int index) {
		return sockets[index];
	}
	
	public Circle[] getSockets() {
		return sockets;
	}

	@Override
	public void setStateRecursively(GUIGeneState state) {
		setState(state);
		for (int i = 0; i < GUI.resources.arity(); i++) {
			((GUIConnection) ((Gene) node.getConnection(i)).getGUIObject()).setStateRecursively(state);
		}
	}

	@Override
	protected void setLinesVisible(boolean value) {
		for (int i = 0; i < lines.length; i++) {
			lines[i].setVisible(value);
		}
	}
	
//	@Override
//	public void updateLines() {
//		for (int l = 0; l < connectionLines.length; l++) {
//			if (node.getConnection(l) instanceof Node) {
//				int row = ((Node) node.getConnection(l)).getRow(), 
//					column = ((Node) node.getConnection(l)).getColumn();
//				connectionLines[l].setEndX((((column + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + 2 * Constants.NODE_RADIUS) + Constants.SOCKET_RADIUS);
//				connectionLines[l].setEndY((row * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);		
//			} else if (node.getConnection(l) instanceof Input) {
//				int inputIndex = ((Input) node.getConnection(l)).getIndex();
//				connectionLines[l].setEndX(2 * Constants.NODE_RADIUS);
//				connectionLines[l].setEndY(inputIndex * (2 * Constants.NODE_RADIUS + Constants.SPACING) + Constants.NODE_RADIUS);
//			}
//		}
//	}
	
}