diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java index dbdad173..c6d20caa 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/GraphPaneController.java @@ -929,6 +929,7 @@ private void drawAnnotationBox(GraphNode node, IViewGraphNode viewNode, } drawnChildNodes.add(viewAnnotation); viewAnnotation.addLabel(drawnChildNodes); + viewAnnotation.addArrow(drawnChildNodes); } } diff --git a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewAnnotation.java b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewAnnotation.java index 01eb1eb3..3254c893 100644 --- a/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewAnnotation.java +++ b/PL2/PL2-gui/src/main/java/nl/tudelft/pl2016gr2/gui/view/graph/ViewAnnotation.java @@ -2,6 +2,8 @@ import javafx.scene.Node; import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.shape.Rectangle; import nl.tudelft.pl2016gr2.gui.view.selection.AnnotationDescription; import nl.tudelft.pl2016gr2.gui.view.selection.ISelectable; @@ -11,6 +13,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.Objects; /** * This is an annotation indicator object which can be added to a IViewGraphNode to indicate that it @@ -22,7 +25,13 @@ public class ViewAnnotation extends Rectangle implements ISelectable { private static final double MINIMUM_LABEL_WIDTH = 10.0; private static final double MINIMUM_LABEL_HEIGHT = 12.0; + private static final double MINIMUM_ARROW_WIDTH = 25.0; + private static final Image RIGHT_ARROW = new Image( + ViewAnnotation.class.getClassLoader().getResourceAsStream("images/arrow-right.png")); + private static final Image LEFT_ARROW = new Image( + ViewAnnotation.class.getClassLoader().getResourceAsStream("images/arrow-left.png")); private final Annotation annotation; + private boolean oddOffset = false; /** * Construct a view annotation which can be drawn in the UI. @@ -61,10 +70,36 @@ public void addLabel(ArrayList nodes) { label.setLayoutX(getLayoutX()); } + /** + * Add an arrow to indicate the annotation direction. + * + * @param nodes the list of nodes to which to add the arrow. + */ + public void addArrow(ArrayList nodes) { + if (getWidth() < MINIMUM_ARROW_WIDTH || getHeight() < MINIMUM_LABEL_HEIGHT) { + return; + } + ImageView arrow; + if (Objects.equals(annotation.strand, "-")) { + arrow = new ImageView(LEFT_ARROW); + } else { + arrow = new ImageView(RIGHT_ARROW); + } + nodes.add(arrow); + arrow.setMouseTransparent(true); + if (oddOffset || getLayoutY() - LEFT_ARROW.getHeight() < 0) { + arrow.setLayoutY(getLayoutY() + getHeight()); + } else { + arrow.setLayoutY(getLayoutY() - LEFT_ARROW.getHeight()); + } + arrow.setLayoutX(getLayoutX() + (getWidth() - LEFT_ARROW.getWidth()) / 2.0); + } + /** * Sets a vertical offset to this label so if doesn't overlap with a different label. */ public void setOddOffset() { + oddOffset = true; setLayoutY(getLayoutY() + getHeight()); } diff --git a/PL2/PL2-gui/src/main/resources/images/arrow-left.png b/PL2/PL2-gui/src/main/resources/images/arrow-left.png new file mode 100644 index 00000000..c8fc2dac Binary files /dev/null and b/PL2/PL2-gui/src/main/resources/images/arrow-left.png differ diff --git a/PL2/PL2-gui/src/main/resources/images/arrow-right.png b/PL2/PL2-gui/src/main/resources/images/arrow-right.png new file mode 100644 index 00000000..b536beec Binary files /dev/null and b/PL2/PL2-gui/src/main/resources/images/arrow-right.png differ