From 244e58d18118b87327a14954056af1ecc285efb9 Mon Sep 17 00:00:00 2001 From: FarisElghlan Date: Tue, 21 Jun 2016 23:50:54 +0200 Subject: [PATCH] Added arrows to the annotations to indicate their direction --- .../gui/view/graph/GraphPaneController.java | 1 + .../gui/view/graph/ViewAnnotation.java | 35 ++++++++++++++++++ .../src/main/resources/images/arrow-left.png | Bin 0 -> 231 bytes .../src/main/resources/images/arrow-right.png | Bin 0 -> 252 bytes 4 files changed, 36 insertions(+) create mode 100644 PL2/PL2-gui/src/main/resources/images/arrow-left.png create mode 100644 PL2/PL2-gui/src/main/resources/images/arrow-right.png 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 0000000000000000000000000000000000000000..c8fc2dac13ed6dcd85a3778e02c4790a70bc5d32 GIT binary patch literal 231 zcmeAS@N?(olHy`uVBq!ia0vp^azM<@!3HEVv~9b96id3JuOkD)#(wTUiL5|AXMsm# zF#`kNArNL1)$nQn3QCl?MwA5SryYc!GMG1Lf^BDyk{8|H36Kqe;GATdcW~>ik4OS#96w*rn}9H{Sa%!r+Gc5 z17Y%q8Tq