aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUIOutput.java
blob: 3bc81d9f454aa1d286a7c43b1ee9464229085b42 (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
package jcgp.gui.population;

import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import jcgp.backend.population.Gene;
import jcgp.backend.population.Output;
import jcgp.gui.constants.Constants;
import jcgp.gui.constants.Position;
import jcgp.gui.handlers.OutputHandlers;

/**
 * The GUI counterpart of {@link jcgp.backend.population.Output}. This is a 
 * subclass of {@code GUIGene} which represents a chromosome output.
 * 
 * @author Eduardo Pedroni
 */
public class GUIOutput extends GUIGene implements GUIMutable {

	private Output output;
	private Line line;

	/**
	 * Instantiate {@code GUIOutput} given an {@code Output} and the line needed
	 * to show its connection.
	 * 
	 * @param output the associated backend output.
	 * @param line the line used to display connection.
	 */
	public GUIOutput(final Output output, Line line) {
		super();
		// store references, associate with backend object
		this.output = output;
		this.line = line;
		output.setGUIObject(this);

		// create input socket
		Circle socket = new Circle(-Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Constants.SOCKET_PAINT);
		socket.setStroke(Paint.valueOf("black"));
		socket.setId(String.valueOf(0));
		Position.connect(line, (GUIGene) ((Gene) output.getSource()).getGUIObject());
		getChildren().add(socket);

		// relocate output, add handlers
		Position.place(this);
		OutputHandlers.addHandlers(this);
	}

	/**
	 * @return the {@code Output} instance associated with this object.
	 */
	public Output getOutput() {
		return output;
	}
	
	/**
	 * Associates this instance with a new output.
	 * 
	 * @param output the new output.
	 */
	void setOutput(Output output) {
		this.output = output;
	}

	/**
	 * @return this output's single connection line.
	 */
	public Line getLine() {
		return line;
	}

	@Override
	protected void setLinesVisible(boolean value) {
		line.setVisible(value);
	}
}