From f7b946eaaace894405bac2e377c59f4a4d4042e3 Mon Sep 17 00:00:00 2001 From: Ryan Duryea Date: Wed, 6 May 2015 14:50:36 -0700 Subject: [PATCH 1/3] Paint highlighted arrows last This makes highlighted arrows show up on top of all other arrows. However, this doesn't guarantee clicking on the highlighted arrow will select that arrow. --- src/org/ohdsi/rabbitInAHat/Arrow.java | 4 ++++ src/org/ohdsi/rabbitInAHat/MappingPanel.java | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/org/ohdsi/rabbitInAHat/Arrow.java b/src/org/ohdsi/rabbitInAHat/Arrow.java index d90d862b..5ba93862 100644 --- a/src/org/ohdsi/rabbitInAHat/Arrow.java +++ b/src/org/ohdsi/rabbitInAHat/Arrow.java @@ -147,6 +147,10 @@ public Color fillColor() { return color; } } + + public boolean isHighlighted() { + return (source != null && source.isSelected()) || (target != null && target.isSelected()); + } public static void drawArrowHead(Graphics2D g2d, int x, int y) { int nPoints = 3; diff --git a/src/org/ohdsi/rabbitInAHat/MappingPanel.java b/src/org/ohdsi/rabbitInAHat/MappingPanel.java index 924e1a8b..0c91c103 100644 --- a/src/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/src/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -236,7 +236,7 @@ public void paint(Graphics g) { component.paint(g2d); for (Arrow component : arrows) - if (component != dragArrow) + if (component != dragArrow && !component.isHighlighted()) component.paint(g2d); if (dragRectangle != null) @@ -244,7 +244,11 @@ public void paint(Graphics g) { if (dragArrow != null) dragArrow.paint(g2d); - + + for (Arrow component : arrows) + if (component != dragArrow && component.isHighlighted()) + component.paint(g2d); + if (offscreen != null) g.drawImage(offscreen, 0, 0, this); } From af52dcb94b940a339572f4a464a255b8ebf74894 Mon Sep 17 00:00:00 2001 From: Ryan Duryea Date: Wed, 6 May 2015 15:03:52 -0700 Subject: [PATCH 2/3] MappingPanel: add highlighted/normalArrows Turns out I'm going to need to iterate over these two kinds of arrows more than once, so I created new private methods for both --- src/org/ohdsi/rabbitInAHat/MappingPanel.java | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/org/ohdsi/rabbitInAHat/MappingPanel.java b/src/org/ohdsi/rabbitInAHat/MappingPanel.java index 0c91c103..800709e0 100644 --- a/src/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/src/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -235,8 +235,8 @@ public void paint(Graphics g) { if (component != dragRectangle) component.paint(g2d); - for (Arrow component : arrows) - if (component != dragArrow && !component.isHighlighted()) + for (Arrow component : normalArrows()) + if (component != dragArrow) component.paint(g2d); if (dragRectangle != null) @@ -245,8 +245,8 @@ public void paint(Graphics g) { if (dragArrow != null) dragArrow.paint(g2d); - for (Arrow component : arrows) - if (component != dragArrow && component.isHighlighted()) + for (Arrow component : highlightedArrows()) + if (component != dragArrow) component.paint(g2d); if (offscreen != null) @@ -602,5 +602,26 @@ public void addResizeListener(ResizeListener resizeListener) { public void setDetailsListener(DetailsListener detailsListener) { this.detailsListener = detailsListener; } + + private List highlightedArrows() { + List highlighted = new ArrayList(); + for(Arrow arrow : arrows) { + if (arrow.isHighlighted()) { + highlighted.add(arrow); + } + } + return highlighted; + } + + + private List normalArrows() { + List highlighted = new ArrayList(); + for(Arrow arrow : arrows) { + if (!arrow.isHighlighted()) { + highlighted.add(arrow); + } + } + return highlighted; + } } From 0a7e0c8fed6f37cb0c8d588aad9c7c118724cc58 Mon Sep 17 00:00:00 2001 From: Ryan Duryea Date: Wed, 6 May 2015 15:16:57 -0700 Subject: [PATCH 3/3] MappingPanel: try to select highlighted arrows before normal GIve preference to highlighted arrows when testing if a mouse click was contained within an arrow. --- src/org/ohdsi/rabbitInAHat/MappingPanel.java | 54 ++++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/org/ohdsi/rabbitInAHat/MappingPanel.java b/src/org/ohdsi/rabbitInAHat/MappingPanel.java index 800709e0..fd8c2d43 100644 --- a/src/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/src/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -262,6 +262,11 @@ private void addLabel(Graphics2D g2d, String string, int x, int y) { @Override public void mouseClicked(MouseEvent event) { + // Save away which arrows are currently highlighted vs normal before we + // de-select all the tables and arrows + List currentlyHighlightedArrows = highlightedArrows(); + List currentlyNormalArrows = normalArrows(); + if (selectedArrow != null) { selectedArrow.setSelected(false); detailsListener.showDetails(null); @@ -300,27 +305,42 @@ public void mouseClicked(MouseEvent event) { } } if (event.getX() > sourceX + ITEM_WIDTH && event.getX() < cdmX) { // Arrows - for (Arrow component : arrows) { - if (component.contains(event.getPoint())) { - if (event.getClickCount() == 2) { // double click - zoomArrow = component; - if (slaveMappingPanel != null) { - slaveMappingPanel.setMapping(ObjectExchange.etl.getFieldToFieldMapping((Table) zoomArrow.getSource().getItem(), (Table) zoomArrow - .getTarget().getItem())); - new AnimateThread(true).start(); - } - - } else { // single click - if (!component.isSelected()) { - component.setSelected(true); - selectedArrow = component; - detailsListener.showDetails(mapping.getSourceToCdmMap(selectedArrow.getSource().getItem(), selectedArrow.getTarget().getItem())); - } - repaint(); + Arrow clickedArrow = null; + + for (Arrow arrow : currentlyHighlightedArrows) { + if (arrow.contains(event.getPoint())) { + clickedArrow = arrow; + break; + } + } + + if (clickedArrow == null) { + for (Arrow arrow : currentlyNormalArrows) { + if (arrow.contains(event.getPoint())) { + clickedArrow = arrow; break; } } } + + if (clickedArrow != null) { + if (event.getClickCount() == 2) { // double click + zoomArrow = clickedArrow; + if (slaveMappingPanel != null) { + slaveMappingPanel.setMapping(ObjectExchange.etl.getFieldToFieldMapping((Table) zoomArrow.getSource().getItem(), (Table) zoomArrow + .getTarget().getItem())); + new AnimateThread(true).start(); + } + + } else { // single click + if (!clickedArrow.isSelected()) { + clickedArrow.setSelected(true); + selectedArrow = clickedArrow; + detailsListener.showDetails(mapping.getSourceToCdmMap(selectedArrow.getSource().getItem(), selectedArrow.getTarget().getItem())); + } + repaint(); + } + } } }