-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/annotation arrows #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<Node> 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<Node> nodes) { | ||
| if (getWidth() < MINIMUM_ARROW_WIDTH || getHeight() < MINIMUM_LABEL_HEIGHT) { | ||
| return; | ||
| } | ||
| ImageView arrow; | ||
| if (Objects.equals(annotation.strand, "-")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done with inheritance (
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be sure, you do know this is the same as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not explicitly realise, but my point was that deciding to draw either forward or backward arrows should be done with different annotation(view) classes. the null-check is good for safety right now but in general shouldn't be necessary |
||
| 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()); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimum arrow with is alrgeer than minimum label width? Sure this is desired? (weird overlapping with many small nodes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the annotation is smaller than
MINIMUM_LABEL_WIDTHthe label (text) isn't drawn. If the annotation is smaller thanMINIMUM_ARROW_WIDTHthe arrow won't be drawn.