diff options
Diffstat (limited to 'src/jcgp/gui/population/GUIOutput.java')
-rw-r--r-- | src/jcgp/gui/population/GUIOutput.java | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java index a07fd90..b281833 100644 --- a/src/jcgp/gui/population/GUIOutput.java +++ b/src/jcgp/gui/population/GUIOutput.java @@ -1,42 +1,71 @@ 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.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; - - Circle socket = new Circle(-Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Paint.valueOf("white")); - socket.setId(String.valueOf(0)); + output.setGUIObject(this); + + // create input socket + Circle socket = new Circle(-Constants.NODE_RADIUS, 0, Constants.SOCKET_RADIUS, Constants.SOCKET_COLOUR); socket.setStroke(Paint.valueOf("black")); + socket.setId(String.valueOf(0)); + Position.connect(line, (GUIGene) ((Gene) output.getSource()).getGUIObject()); + getChildren().add(socket); - Label connectionLabel = new Label("S"); - connectionLabel.setStyle("-fx-background-color:rgb(255, 255, 255); -fx-border-color:rgba(0, 0, 0, 0.5);"); - connectionLabel.relocate(socket.getCenterX() + 5, socket.getCenterY() - 10); - connectionLabel.setVisible(false); - - getChildren().addAll(socket, connectionLabel); + // relocate output, add handlers + Position.place(this); + OutputHandlers.addHandlers(this); } - void setOutput(Output output2) { - + /** + * Associates this instance with a new output. + * + * @param output the new output. + */ + void setOutput(Output output) { + this.output = output; } - + + /** + * @return the {@code Output} instance associated with this object. + */ public Output getOutput() { return output; } + + /** + * @return this output's single connection line. + */ public Line getLine() { return line; } |