aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/constants/Position.java
blob: a13d21e273a7beab307e6d0d858fad9edcfa175b (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
package jcgp.gui.constants;

import javafx.scene.shape.Line;
import jcgp.gui.GUI;
import jcgp.gui.population.GUIGene;
import jcgp.gui.population.GUIInput;
import jcgp.gui.population.GUINode;
import jcgp.gui.population.GUIOutput;

public final class Position {
	
	public static void place(GUIInput input) {
		input.relocate(0,
				input.getInput().getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING));
	}
	
	public static void place(GUINode node) {
		// TODO cut down method calls
		double xOffset = ((node.getNode().getColumn() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING));
		double yOffset = node.getNode().getRow() * (2 * Constants.NODE_RADIUS + Constants.SPACING);
		node.relocate(xOffset, yOffset);
		
		for (int i = 0; i < GUI.resources.arity(); i++) {
			node.getLine(i).setStartX(node.getSocket(i).getCenterX() + xOffset + Constants.NODE_RADIUS + Constants.SOCKET_RADIUS);
			node.getLine(i).setStartY(node.getSocket(i).getCenterY() + yOffset + Constants.NODE_RADIUS);
		}
	}
	
	public static void place(GUIOutput output) {
		output.relocate(((GUI.resources.columns() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)),
				output.getOutput().getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING));
		output.getLine().setStartX(output.getLayoutX() - Constants.NODE_RADIUS);
		output.getLine().setStartY(output.getLayoutY());
	}
	
	public static void connect(Line line, GUIGene target) {
		line.setEndX(target.getLayoutX() + Constants.NODE_RADIUS);
		line.setEndY(target.getLayoutY());
	}
}