From 422a3267cad0789a93d5753b113d488d1b577cf9 Mon Sep 17 00:00:00 2001 From: Holt59 Date: Sun, 25 Feb 2018 16:43:37 +0100 Subject: [PATCH] Add possibility to show/hide a marker after its creation without having to delete/recreate it. --- .../insa/graphics/drawing/BasicDrawing.java | 20 +++++++++++++++---- .../insa/graphics/drawing/MapViewDrawing.java | 5 +++++ .../insa/graphics/drawing/MarkerTracker.java | 7 +++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/org/insa/graphics/drawing/BasicDrawing.java b/src/main/org/insa/graphics/drawing/BasicDrawing.java index b6d63ce..7488789 100644 --- a/src/main/org/insa/graphics/drawing/BasicDrawing.java +++ b/src/main/org/insa/graphics/drawing/BasicDrawing.java @@ -46,9 +46,13 @@ public class BasicDrawing extends JPanel implements Drawing { // Image of the marker protected BufferedImage image; + // Visible? + protected boolean visible; + public BasicMarkerTracker(Point point, BufferedImage image) { this.point = point; this.image = image; + this.visible = true; } @Override @@ -62,6 +66,12 @@ public class BasicDrawing extends JPanel implements Drawing { BasicDrawing.this.repaint(); } + @Override + public void setVisible(boolean visible) { + this.visible = visible; + BasicDrawing.this.repaint(); + } + @Override public void delete() { BasicDrawing.this.markers.remove(this); @@ -151,10 +161,12 @@ public class BasicDrawing extends JPanel implements Drawing { // Draw markers for (BasicMarkerTracker mtracker: markers) { - BufferedImage img = mtracker.image; - int px = this.projx(mtracker.getPoint().getLongitude()); - int py = this.projy(mtracker.getPoint().getLatitude()); - g.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(), this); + if (mtracker.visible) { + BufferedImage img = mtracker.image; + int px = this.projx(mtracker.getPoint().getLongitude()); + int py = this.projy(mtracker.getPoint().getLatitude()); + g.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(), this); + } } } diff --git a/src/main/org/insa/graphics/drawing/MapViewDrawing.java b/src/main/org/insa/graphics/drawing/MapViewDrawing.java index 60be9a7..8bc92e4 100644 --- a/src/main/org/insa/graphics/drawing/MapViewDrawing.java +++ b/src/main/org/insa/graphics/drawing/MapViewDrawing.java @@ -69,6 +69,11 @@ public class MapViewDrawing extends MapView implements Drawing { MapViewDrawing.this.getLayerManager().getLayers().add(this.marker); } + @Override + public void setVisible(boolean visible) { + this.marker.setVisible(visible); + } + @Override public void delete() { MapViewDrawing.this.getLayerManager().getLayers().remove(marker); diff --git a/src/main/org/insa/graphics/drawing/MarkerTracker.java b/src/main/org/insa/graphics/drawing/MarkerTracker.java index b137a86..b43e9b9 100644 --- a/src/main/org/insa/graphics/drawing/MarkerTracker.java +++ b/src/main/org/insa/graphics/drawing/MarkerTracker.java @@ -14,6 +14,13 @@ public interface MarkerTracker { */ public void moveTo(Point point); + /** + * Show or hide this marker - A marker should be visible when created. + * + * @param visible true to show the marker, false to hide. + */ + public void setVisible(boolean visible); + /** * Delete this marker. */