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; } @Override public Line[] getLines() { return new Line[] {line}; } @Override protected void setLinesVisible(boolean value) { line.setVisible(value); } @Override public GUIConnection[] getConnections() { return new GUIConnection[] {(GUIConnection) output.getGUIObject()}; } }