This is an automated email from the git hooks/post-receive script. sebastic-guest pushed a commit to branch master in repository jmapviewer.
commit efa0a85ef3da7309ad13e2500522dcaef8045bad Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Fri Dec 12 21:58:27 2014 +0100 Imported Upstream version 1.04+dfsg --- build.xml | 2 +- .../gui/jmapviewer/AbstractLayer.java | 2 +- .../gui/jmapviewer/AttributionSupport.java | 326 ++++++++++----------- .../openstreetmap/gui/jmapviewer/Coordinate.java | 23 ++ .../gui/jmapviewer/DefaultMapController.java | 22 +- src/org/openstreetmap/gui/jmapviewer/Demo.java | 9 +- .../gui/jmapviewer/FeatureAdapter.java | 126 ++++---- .../openstreetmap/gui/jmapviewer/JMapViewer.java | 23 +- .../gui/jmapviewer/JobDispatcher.java | 2 +- .../gui/jmapviewer/MapPolygonImpl.java | 210 ++++++------- .../gui/jmapviewer/MapRectangleImpl.java | 156 +++++----- .../gui/jmapviewer/MemoryTileCache.java | 2 +- .../gui/jmapviewer/OsmFileCacheTileLoader.java | 41 +-- .../gui/jmapviewer/OsmTileLoader.java | 2 +- src/org/openstreetmap/gui/jmapviewer/Tile.java | 2 +- .../gui/jmapviewer/events/JMVCommandEvent.java | 96 +++--- .../openstreetmap/gui/jmapviewer/images/error.png | Bin 5668 -> 3217 bytes .../gui/jmapviewer/images/hourglass.png | Bin 9096 -> 5918 bytes .../openstreetmap/gui/jmapviewer/images/minus.png | Bin 171 -> 88 bytes .../openstreetmap/gui/jmapviewer/images/plus.png | Bin 225 -> 133 bytes .../gui/jmapviewer/interfaces/Attributed.java | 100 +++---- .../interfaces/JMapViewerEventListener.java | 34 +-- .../gui/jmapviewer/interfaces/MapPolygon.java | 76 ++--- .../jmapviewer/tilesources/AbstractTileSource.java | 154 +++++----- .../tilesources/BingAerialTileSource.java | 26 +- .../gui/jmapviewer/tilesources/OsmTileSource.java | 2 +- .../jmapviewer/tilesources/ScanexTileSource.java | 2 +- .../tilesources/TemplatedTMSTileSource.java | 2 +- 28 files changed, 720 insertions(+), 720 deletions(-) diff --git a/build.xml b/build.xml index a164e74..471058d 100644 --- a/build.xml +++ b/build.xml @@ -14,7 +14,7 @@ </target> <target name="build"> - <javac srcdir="src" destdir="bin" source="1.6" target="1.6" debug="true" includeantruntime="false" encoding="UTF-8"> + <javac srcdir="src" destdir="bin" source="1.7" target="1.7" debug="true" includeantruntime="false" encoding="UTF-8"> <include name="org/openstreetmap/gui/jmapviewer/**" /> </javac> diff --git a/src/org/openstreetmap/gui/jmapviewer/AbstractLayer.java b/src/org/openstreetmap/gui/jmapviewer/AbstractLayer.java index 1691032..e288087 100644 --- a/src/org/openstreetmap/gui/jmapviewer/AbstractLayer.java +++ b/src/org/openstreetmap/gui/jmapviewer/AbstractLayer.java @@ -71,7 +71,7 @@ public class AbstractLayer { } public static <E> List<E> add(List<E> list, E element) { if(element!=null){ - if(list==null) list = new ArrayList<E>(); + if(list==null) list = new ArrayList<>(); if(!list.contains(element)) list.add(element); } return list; diff --git a/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java b/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java index 261632e..cd53044 100644 --- a/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java +++ b/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java @@ -1,163 +1,163 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer; - -import static org.openstreetmap.gui.jmapviewer.FeatureAdapter.tr; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.font.TextAttribute; -import java.awt.geom.Rectangle2D; -import java.awt.image.ImageObserver; -import java.util.HashMap; - -import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; - -public class AttributionSupport { - - private Attributed source; - - private Image attrImage; - private String attrTermsText; - private String attrTermsUrl; - public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); - public static final Font ATTR_LINK_FONT; - - protected Rectangle attrTextBounds = null; - protected Rectangle attrToUBounds = null; - protected Rectangle attrImageBounds = null; - - static { - HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>(); - aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); - ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline); - } - - public void initialize(Attributed source) { - this.source = source; - boolean requireAttr = source.requiresAttribution(); - if (requireAttr) { - attrImage = source.getAttributionImage(); - attrTermsText = source.getTermsOfUseText(); - attrTermsUrl = source.getTermsOfUseURL(); - if (attrTermsUrl != null && attrTermsText == null) { - attrTermsText = tr("Background Terms of Use"); - } - } else { - attrImage = null; - attrTermsUrl = null; - } - } - - public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) { - if (source == null || !source.requiresAttribution()) { - attrToUBounds = null; - attrImageBounds = null; - attrTextBounds = null; - return; - } - - // Draw attribution - Font font = g.getFont(); - g.setFont(ATTR_LINK_FONT); - - // Draw terms of use text - int termsTextHeight = 0; - int termsTextY = height; - - if (attrTermsText != null) { - Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g); - int textRealHeight = (int) termsStringBounds.getHeight(); - termsTextHeight = textRealHeight - 5; - int termsTextWidth = (int) termsStringBounds.getWidth(); - termsTextY = height - termsTextHeight; - int x = 2; - int y = height - termsTextHeight; - attrToUBounds = new Rectangle(x, y-termsTextHeight, termsTextWidth, textRealHeight); - g.setColor(Color.black); - g.drawString(attrTermsText, x + 1, y + 1); - g.setColor(Color.white); - g.drawString(attrTermsText, x, y); - } else { - attrToUBounds = null; - } - - // Draw attribution logo - if (attrImage != null) { - int x = 2; - int imgWidth = attrImage.getWidth(observer); - int imgHeight = attrImage.getHeight(observer); - int y = termsTextY - imgHeight - termsTextHeight - 5; - attrImageBounds = new Rectangle(x, y, imgWidth, imgHeight); - g.drawImage(attrImage, x, y, null); - } else { - attrImageBounds = null; - } - - g.setFont(ATTR_FONT); - String attributionText = source.getAttributionText(zoom, topLeft, bottomRight); - if (attributionText != null) { - Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); - int textHeight = (int) stringBounds.getHeight() - 5; - int x = width - (int) stringBounds.getWidth(); - int y = height - textHeight; - g.setColor(Color.black); - g.drawString(attributionText, x + 1, y + 1); - g.setColor(Color.white); - g.drawString(attributionText, x, y); - attrTextBounds = new Rectangle(x, y-textHeight, (int) stringBounds.getWidth(), (int) stringBounds.getHeight()); - } else { - attrTextBounds = null; - } - - g.setFont(font); - } - - public boolean handleAttributionCursor(Point p) { - if (attrTextBounds != null && attrTextBounds.contains(p)) { - return true; - } else if (attrImageBounds != null && attrImageBounds.contains(p)) { - return true; - } else if (attrToUBounds != null && attrToUBounds.contains(p)) { - return true; - } - return false; - } - - public boolean handleAttribution(Point p, boolean click) { - if (source == null || !source.requiresAttribution()) - return false; - - if (attrTextBounds != null && attrTextBounds.contains(p)) { - String attributionURL = source.getAttributionLinkURL(); - if (attributionURL != null) { - if (click) { - FeatureAdapter.openLink(attributionURL); - } - return true; - } - } else if (attrImageBounds != null && attrImageBounds.contains(p)) { - String attributionImageURL = source.getAttributionImageURL(); - if (attributionImageURL != null) { - if (click) { - FeatureAdapter.openLink(source.getAttributionImageURL()); - } - return true; - } - } else if (attrToUBounds != null && attrToUBounds.contains(p)) { - String termsOfUseURL = source.getTermsOfUseURL(); - if (termsOfUseURL != null) { - if (click) { - FeatureAdapter.openLink(termsOfUseURL); - } - return true; - } - } - return false; - } - -} - +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer; + +import static org.openstreetmap.gui.jmapviewer.FeatureAdapter.tr; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.font.TextAttribute; +import java.awt.geom.Rectangle2D; +import java.awt.image.ImageObserver; +import java.util.HashMap; + +import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; + +public class AttributionSupport { + + private Attributed source; + + private Image attrImage; + private String attrTermsText; + private String attrTermsUrl; + public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); + public static final Font ATTR_LINK_FONT; + + protected Rectangle attrTextBounds = null; + protected Rectangle attrToUBounds = null; + protected Rectangle attrImageBounds = null; + + static { + HashMap<TextAttribute, Integer> aUnderline = new HashMap<>(); + aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline); + } + + public void initialize(Attributed source) { + this.source = source; + boolean requireAttr = source.requiresAttribution(); + if (requireAttr) { + attrImage = source.getAttributionImage(); + attrTermsText = source.getTermsOfUseText(); + attrTermsUrl = source.getTermsOfUseURL(); + if (attrTermsUrl != null && attrTermsText == null) { + attrTermsText = tr("Background Terms of Use"); + } + } else { + attrImage = null; + attrTermsUrl = null; + } + } + + public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) { + if (source == null || !source.requiresAttribution()) { + attrToUBounds = null; + attrImageBounds = null; + attrTextBounds = null; + return; + } + + // Draw attribution + Font font = g.getFont(); + g.setFont(ATTR_LINK_FONT); + + // Draw terms of use text + int termsTextHeight = 0; + int termsTextY = height; + + if (attrTermsText != null) { + Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g); + int textRealHeight = (int) termsStringBounds.getHeight(); + termsTextHeight = textRealHeight - 5; + int termsTextWidth = (int) termsStringBounds.getWidth(); + termsTextY = height - termsTextHeight; + int x = 2; + int y = height - termsTextHeight; + attrToUBounds = new Rectangle(x, y-termsTextHeight, termsTextWidth, textRealHeight); + g.setColor(Color.black); + g.drawString(attrTermsText, x + 1, y + 1); + g.setColor(Color.white); + g.drawString(attrTermsText, x, y); + } else { + attrToUBounds = null; + } + + // Draw attribution logo + if (attrImage != null) { + int x = 2; + int imgWidth = attrImage.getWidth(observer); + int imgHeight = attrImage.getHeight(observer); + int y = termsTextY - imgHeight - termsTextHeight - 5; + attrImageBounds = new Rectangle(x, y, imgWidth, imgHeight); + g.drawImage(attrImage, x, y, null); + } else { + attrImageBounds = null; + } + + g.setFont(ATTR_FONT); + String attributionText = source.getAttributionText(zoom, topLeft, bottomRight); + if (attributionText != null) { + Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); + int textHeight = (int) stringBounds.getHeight() - 5; + int x = width - (int) stringBounds.getWidth(); + int y = height - textHeight; + g.setColor(Color.black); + g.drawString(attributionText, x + 1, y + 1); + g.setColor(Color.white); + g.drawString(attributionText, x, y); + attrTextBounds = new Rectangle(x, y-textHeight, (int) stringBounds.getWidth(), (int) stringBounds.getHeight()); + } else { + attrTextBounds = null; + } + + g.setFont(font); + } + + public boolean handleAttributionCursor(Point p) { + if (attrTextBounds != null && attrTextBounds.contains(p)) { + return true; + } else if (attrImageBounds != null && attrImageBounds.contains(p)) { + return true; + } else if (attrToUBounds != null && attrToUBounds.contains(p)) { + return true; + } + return false; + } + + public boolean handleAttribution(Point p, boolean click) { + if (source == null || !source.requiresAttribution()) + return false; + + if (attrTextBounds != null && attrTextBounds.contains(p)) { + String attributionURL = source.getAttributionLinkURL(); + if (attributionURL != null) { + if (click) { + FeatureAdapter.openLink(attributionURL); + } + return true; + } + } else if (attrImageBounds != null && attrImageBounds.contains(p)) { + String attributionImageURL = source.getAttributionImageURL(); + if (attributionImageURL != null) { + if (click) { + FeatureAdapter.openLink(source.getAttributionImageURL()); + } + return true; + } + } else if (attrToUBounds != null && attrToUBounds.contains(p)) { + String termsOfUseURL = source.getTermsOfUseURL(); + if (termsOfUseURL != null) { + if (click) { + FeatureAdapter.openLink(termsOfUseURL); + } + return true; + } + } + return false; + } + +} + diff --git a/src/org/openstreetmap/gui/jmapviewer/Coordinate.java b/src/org/openstreetmap/gui/jmapviewer/Coordinate.java index d3803ce..25a482d 100644 --- a/src/org/openstreetmap/gui/jmapviewer/Coordinate.java +++ b/src/org/openstreetmap/gui/jmapviewer/Coordinate.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.Objects; import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; @@ -53,4 +54,26 @@ public class Coordinate implements Serializable, ICoordinate { public String toString() { return "Coordinate[" + data.y + ", " + data.x + "]"; } + + @Override + public int hashCode() { + int hash = 3; + hash = 61 * hash + Objects.hashCode(this.data); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Coordinate other = (Coordinate) obj; + if (!Objects.equals(this.data, other.data)) { + return false; + } + return true; + } } diff --git a/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java b/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java index 93e04be..e254c42 100644 --- a/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java +++ b/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java @@ -39,14 +39,10 @@ MouseWheelListener { private boolean doubleClickZoomEnabled = true; public void mouseDragged(MouseEvent e) { - debugMouseEvent("DefaultMapController.mouseDragged", e); if (!movementEnabled || !isMoving) return; // Is only the selected mouse button pressed? if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == movementMouseButtonMask || isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) { - if (JMapViewer.debug) { - System.err.println("(#9897) moving"); - } Point p = e.getPoint(); if (lastDragPoint != null) { int diffx = lastDragPoint.x - p.x; @@ -58,41 +54,25 @@ MouseWheelListener { } public void mouseClicked(MouseEvent e) { - debugMouseEvent("DefaultMapController.mouseClicked", e); if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { map.zoomIn(e.getPoint()); } } public void mousePressed(MouseEvent e) { - debugMouseEvent("DefaultMapController.mousePressed", e); - if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) { - if (JMapViewer.debug) { - System.err.println("(#9897) move start"); - } lastDragPoint = null; isMoving = true; } } - + public void mouseReleased(MouseEvent e) { - debugMouseEvent("DefaultMapController.mouseReleased", e); if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) { - if (JMapViewer.debug) { - System.err.println("(#9897) move stop"); - } lastDragPoint = null; isMoving = false; } } - public void debugMouseEvent(String s, MouseEvent e) { - if (JMapViewer.debug) { - System.err.println("(#9897) " + s + ": Button "+ e.getButton() + " Modifiers: " +Integer.toBinaryString(e.getModifiersEx())); - } - } - public void mouseWheelMoved(MouseWheelEvent e) { if (wheelZoomEnabled) { map.setZoom(map.getZoom() - e.getWheelRotation(), e.getPoint()); diff --git a/src/org/openstreetmap/gui/jmapviewer/Demo.java b/src/org/openstreetmap/gui/jmapviewer/Demo.java index b8ff7bb..d6ae3e8 100644 --- a/src/org/openstreetmap/gui/jmapviewer/Demo.java +++ b/src/org/openstreetmap/gui/jmapviewer/Demo.java @@ -93,19 +93,18 @@ public class Demo extends JFrame implements JMapViewerEventListener { map().setDisplayToFitMapMarkers(); } }); - JComboBox tileSourceSelector = new JComboBox(new TileSource[] { new OsmTileSource.Mapnik(), + JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] { new OsmTileSource.Mapnik(), new OsmTileSource.CycleMap(), new BingAerialTileSource(), new MapQuestOsmTileSource(), new MapQuestOpenAerialTileSource() }); tileSourceSelector.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { map().setTileSource((TileSource) e.getItem()); } }); - JComboBox tileLoaderSelector; + JComboBox<TileLoader> tileLoaderSelector; try { - tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map()), - new OsmTileLoader(map()) }); + tileLoaderSelector = new JComboBox<>(new TileLoader[] { new OsmFileCacheTileLoader(map()), new OsmTileLoader(map()) }); } catch (IOException e) { - tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmTileLoader(map()) }); + tileLoaderSelector = new JComboBox<>(new TileLoader[] { new OsmTileLoader(map()) }); } tileLoaderSelector.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { diff --git a/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java b/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java index b1e3fb4..24245f9 100644 --- a/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java +++ b/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java @@ -1,63 +1,63 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer; - -import java.awt.Desktop; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.MessageFormat; - -public class FeatureAdapter { - - public static interface BrowserAdapter { - void openLink(String url); - } - - public static interface TranslationAdapter { - String tr(String text, Object... objects); - // TODO: more i18n functions - } - - private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter(); - private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter(); - - public static void registerBrowserAdapter(BrowserAdapter browserAdapter) { - FeatureAdapter.browserAdapter = browserAdapter; - } - - public static void registerTranslationAdapter(TranslationAdapter translationAdapter) { - FeatureAdapter.translationAdapter = translationAdapter; - } - - public static void openLink(String url) { - browserAdapter.openLink(url); - } - - public static String tr(String text, Object... objects) { - return translationAdapter.tr(text, objects); - } - - public static class DefaultBrowserAdapter implements BrowserAdapter { - @Override - public void openLink(String url) { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException e) { - e.printStackTrace(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - } else { - System.err.println(tr("Opening link not supported on current platform (''{0}'')", url)); - } - } - } - - public static class DefaultTranslationAdapter implements TranslationAdapter { - @Override - public String tr(String text, Object... objects) { - return MessageFormat.format(text, objects); - } - } -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer; + +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.MessageFormat; + +public class FeatureAdapter { + + public static interface BrowserAdapter { + void openLink(String url); + } + + public static interface TranslationAdapter { + String tr(String text, Object... objects); + // TODO: more i18n functions + } + + private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter(); + private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter(); + + public static void registerBrowserAdapter(BrowserAdapter browserAdapter) { + FeatureAdapter.browserAdapter = browserAdapter; + } + + public static void registerTranslationAdapter(TranslationAdapter translationAdapter) { + FeatureAdapter.translationAdapter = translationAdapter; + } + + public static void openLink(String url) { + browserAdapter.openLink(url); + } + + public static String tr(String text, Object... objects) { + return translationAdapter.tr(text, objects); + } + + public static class DefaultBrowserAdapter implements BrowserAdapter { + @Override + public void openLink(String url) { + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } else { + System.err.println(tr("Opening link not supported on current platform (''{0}'')", url)); + } + } + } + + public static class DefaultTranslationAdapter implements TranslationAdapter { + @Override + public String tr(String text, Object... objects) { + return MessageFormat.format(text, objects); + } + } +} diff --git a/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java b/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java index 52610f3..f1ddc06 100644 --- a/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java +++ b/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java @@ -42,8 +42,6 @@ import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource; */ public class JMapViewer extends JPanel implements TileLoaderListener { - private static final long serialVersionUID = 1L; - public static boolean debug = false; /** @@ -99,6 +97,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { * {@link MemoryTileCache} and the tile loader uses 4 parallel threads for * retrieving the tiles. */ + @SuppressWarnings("unused") public JMapViewer() { this(new MemoryTileCache(), 8); new DefaultMapController(this); @@ -109,9 +108,9 @@ public class JMapViewer extends JPanel implements TileLoaderListener { JobDispatcher.setMaxWorkers(downloadThreadCount); tileSource = new OsmTileSource.Mapnik(); tileController = new TileController(tileSource, tileCache, this); - mapMarkerList = new LinkedList<MapMarker>(); - mapPolygonList = new LinkedList<MapPolygon>(); - mapRectangleList = new LinkedList<MapRectangle>(); + mapMarkerList = new LinkedList<>(); + mapPolygonList = new LinkedList<>(); + mapRectangleList = new LinkedList<>(); mapMarkersVisible = true; mapRectanglesVisible = true; mapPolygonsVisible = true; @@ -711,7 +710,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { protected void paintPolygon(Graphics g, MapPolygon polygon) { List<? extends ICoordinate> coords = polygon.getPoints(); if (coords != null && coords.size() >= 3) { - List<Point> points = new LinkedList<Point>(); + List<Point> points = new LinkedList<>(); for (ICoordinate c : coords) { Point p = getMapPosition(c, false); if (p == null) { @@ -723,7 +722,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { if (scrollWrapEnabled) { int tilesize = tileSource.getTileSize(); int mapSize = tilesize << zoom; - List<Point> pointsWrapped = new LinkedList<Point>(points); + List<Point> pointsWrapped = new LinkedList<>(points); boolean keepWrapping = true; while (keepWrapping) { for (Point p : pointsWrapped) { @@ -734,7 +733,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { } polygon.paint(g, pointsWrapped); } - pointsWrapped = new LinkedList<Point>(points); + pointsWrapped = new LinkedList<>(points); keepWrapping = true; while (keepWrapping) { for (Point p : pointsWrapped) { @@ -1065,20 +1064,20 @@ public class JMapViewer extends JPanel implements TileLoaderListener { return attribution; } - protected EventListenerList listenerList = new EventListenerList(); + protected EventListenerList evtListenerList = new EventListenerList(); /** * @param listener listener to set */ public void addJMVListener(JMapViewerEventListener listener) { - listenerList.add(JMapViewerEventListener.class, listener); + evtListenerList.add(JMapViewerEventListener.class, listener); } /** * @param listener listener to remove */ public void removeJMVListener(JMapViewerEventListener listener) { - listenerList.remove(JMapViewerEventListener.class, listener); + evtListenerList.remove(JMapViewerEventListener.class, listener); } /** @@ -1087,7 +1086,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { * @param evt event to dispatch */ void fireJMVEvent(JMVCommandEvent evt) { - Object[] listeners = listenerList.getListenerList(); + Object[] listeners = evtListenerList.getListenerList(); for (int i=0; i<listeners.length; i+=2) { if (listeners[i]==JMapViewerEventListener.class) { ((JMapViewerEventListener)listeners[i+1]).processCommand(evt); diff --git a/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java b/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java index 1cc4754..dfd6103 100644 --- a/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java +++ b/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java @@ -31,7 +31,7 @@ public class JobDispatcher { addWorkerThread().firstThread = true; } - protected BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<TileJob>(); + protected BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<>(); protected static int workerThreadMaxCount = 8; diff --git a/src/org/openstreetmap/gui/jmapviewer/MapPolygonImpl.java b/src/org/openstreetmap/gui/jmapviewer/MapPolygonImpl.java index daf201b..521935b 100644 --- a/src/org/openstreetmap/gui/jmapviewer/MapPolygonImpl.java +++ b/src/org/openstreetmap/gui/jmapviewer/MapPolygonImpl.java @@ -1,105 +1,105 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer; - -import java.awt.AlphaComposite; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Composite; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Rectangle; -import java.awt.Stroke; -import java.util.Arrays; -import java.util.List; - -import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; -import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon; - -public class MapPolygonImpl extends MapObjectImpl implements MapPolygon { - - private List<? extends ICoordinate> points; - - public MapPolygonImpl(ICoordinate ... points) { - this(null, null, points); - } - public MapPolygonImpl(List<? extends ICoordinate> points) { - this(null, null, points); - } - public MapPolygonImpl(String name, List<? extends ICoordinate> points) { - this(null, name, points); - } - public MapPolygonImpl(String name, ICoordinate ... points) { - this(null, name, points); - } - public MapPolygonImpl(Layer layer, List<? extends ICoordinate> points) { - this(layer, null, points); - } - public MapPolygonImpl(Layer layer, String name, List<? extends ICoordinate> points) { - this(layer, name, points, getDefaultStyle()); - } - public MapPolygonImpl(Layer layer, String name, ICoordinate ... points) { - this(layer, name, Arrays.asList(points), getDefaultStyle()); - } - public MapPolygonImpl(Layer layer, String name, List<? extends ICoordinate> points, Style style) { - super(layer, name, style); - this.points = points; - } - - @Override - public List<? extends ICoordinate> getPoints() { - return this.points; - } - - @Override - public void paint(Graphics g, List<Point> points) { - Polygon polygon = new Polygon(); - for (Point p : points) { - polygon.addPoint(p.x, p.y); - } - paint(g, polygon); - } - - @Override - public void paint(Graphics g, Polygon polygon) { - // Prepare graphics - Color oldColor = g.getColor(); - g.setColor(getColor()); - - Stroke oldStroke = null; - if (g instanceof Graphics2D) { - Graphics2D g2 = (Graphics2D) g; - oldStroke = g2.getStroke(); - g2.setStroke(getStroke()); - } - // Draw - g.drawPolygon(polygon); - if (g instanceof Graphics2D && getBackColor()!=null) { - Graphics2D g2 = (Graphics2D) g; - Composite oldComposite = g2.getComposite(); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); - g2.setPaint(getBackColor()); - g2.fillPolygon(polygon); - g2.setComposite(oldComposite); - } - // Restore graphics - g.setColor(oldColor); - if (g instanceof Graphics2D) { - ((Graphics2D) g).setStroke(oldStroke); - } - Rectangle rec = polygon.getBounds(); - Point corner = rec.getLocation(); - Point p= new Point(corner.x+(rec.width/2), corner.y+(rec.height/2)); - if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); - } - - public static Style getDefaultStyle(){ - return new Style(Color.BLUE, new Color(100,100,100,50), new BasicStroke(2), getDefaultFont()); - } - - @Override - public String toString() { - return "MapPolygon [points=" + points + "]"; - } -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer; + +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.util.Arrays; +import java.util.List; + +import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; +import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon; + +public class MapPolygonImpl extends MapObjectImpl implements MapPolygon { + + private List<? extends ICoordinate> points; + + public MapPolygonImpl(ICoordinate ... points) { + this(null, null, points); + } + public MapPolygonImpl(List<? extends ICoordinate> points) { + this(null, null, points); + } + public MapPolygonImpl(String name, List<? extends ICoordinate> points) { + this(null, name, points); + } + public MapPolygonImpl(String name, ICoordinate ... points) { + this(null, name, points); + } + public MapPolygonImpl(Layer layer, List<? extends ICoordinate> points) { + this(layer, null, points); + } + public MapPolygonImpl(Layer layer, String name, List<? extends ICoordinate> points) { + this(layer, name, points, getDefaultStyle()); + } + public MapPolygonImpl(Layer layer, String name, ICoordinate ... points) { + this(layer, name, Arrays.asList(points), getDefaultStyle()); + } + public MapPolygonImpl(Layer layer, String name, List<? extends ICoordinate> points, Style style) { + super(layer, name, style); + this.points = points; + } + + @Override + public List<? extends ICoordinate> getPoints() { + return this.points; + } + + @Override + public void paint(Graphics g, List<Point> points) { + Polygon polygon = new Polygon(); + for (Point p : points) { + polygon.addPoint(p.x, p.y); + } + paint(g, polygon); + } + + @Override + public void paint(Graphics g, Polygon polygon) { + // Prepare graphics + Color oldColor = g.getColor(); + g.setColor(getColor()); + + Stroke oldStroke = null; + if (g instanceof Graphics2D) { + Graphics2D g2 = (Graphics2D) g; + oldStroke = g2.getStroke(); + g2.setStroke(getStroke()); + } + // Draw + g.drawPolygon(polygon); + if (g instanceof Graphics2D && getBackColor()!=null) { + Graphics2D g2 = (Graphics2D) g; + Composite oldComposite = g2.getComposite(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + g2.setPaint(getBackColor()); + g2.fillPolygon(polygon); + g2.setComposite(oldComposite); + } + // Restore graphics + g.setColor(oldColor); + if (g instanceof Graphics2D) { + ((Graphics2D) g).setStroke(oldStroke); + } + Rectangle rec = polygon.getBounds(); + Point corner = rec.getLocation(); + Point p= new Point(corner.x+(rec.width/2), corner.y+(rec.height/2)); + if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); + } + + public static Style getDefaultStyle(){ + return new Style(Color.BLUE, new Color(100,100,100,50), new BasicStroke(2), getDefaultFont()); + } + + @Override + public String toString() { + return "MapPolygon [points=" + points + "]"; + } +} diff --git a/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java b/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java index 51c8b33..4d09ede 100644 --- a/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java +++ b/src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java @@ -1,78 +1,78 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Stroke; - -import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; - -public class MapRectangleImpl extends MapObjectImpl implements MapRectangle { - - private Coordinate topLeft; - private Coordinate bottomRight; - - public MapRectangleImpl(Coordinate topLeft, Coordinate bottomRight) { - this(null, null, topLeft, bottomRight); - } - public MapRectangleImpl(String name, Coordinate topLeft, Coordinate bottomRight) { - this(null, name, topLeft, bottomRight); - } - public MapRectangleImpl(Layer layer, Coordinate topLeft, Coordinate bottomRight) { - this(layer, null, topLeft, bottomRight); - } - public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight) { - this(layer, name, topLeft, bottomRight, getDefaultStyle()); - } - public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight, Style style) { - super(layer, name, style); - this.topLeft = topLeft; - this.bottomRight = bottomRight; - } - - @Override - public Coordinate getTopLeft() { - return topLeft; - } - - @Override - public Coordinate getBottomRight() { - return bottomRight; - } - - @Override - public void paint(Graphics g, Point topLeft, Point bottomRight) { - // Prepare graphics - Color oldColor = g.getColor(); - g.setColor(getColor()); - Stroke oldStroke = null; - if (g instanceof Graphics2D) { - Graphics2D g2 = (Graphics2D) g; - oldStroke = g2.getStroke(); - g2.setStroke(getStroke()); - } - // Draw - g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); - // Restore graphics - g.setColor(oldColor); - if (g instanceof Graphics2D) { - ((Graphics2D) g).setStroke(oldStroke); - } - int width=bottomRight.x-topLeft.x; - int height=bottomRight.y-topLeft.y; - Point p= new Point(topLeft.x+(width/2), topLeft.y+(height/2)); - if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); - } - - public static Style getDefaultStyle(){ - return new Style(Color.BLUE, null, new BasicStroke(2), getDefaultFont()); - } - - @Override - public String toString() { - return "MapRectangle from " + getTopLeft() + " to " + getBottomRight(); - } -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Stroke; + +import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; + +public class MapRectangleImpl extends MapObjectImpl implements MapRectangle { + + private Coordinate topLeft; + private Coordinate bottomRight; + + public MapRectangleImpl(Coordinate topLeft, Coordinate bottomRight) { + this(null, null, topLeft, bottomRight); + } + public MapRectangleImpl(String name, Coordinate topLeft, Coordinate bottomRight) { + this(null, name, topLeft, bottomRight); + } + public MapRectangleImpl(Layer layer, Coordinate topLeft, Coordinate bottomRight) { + this(layer, null, topLeft, bottomRight); + } + public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight) { + this(layer, name, topLeft, bottomRight, getDefaultStyle()); + } + public MapRectangleImpl(Layer layer, String name, Coordinate topLeft, Coordinate bottomRight, Style style) { + super(layer, name, style); + this.topLeft = topLeft; + this.bottomRight = bottomRight; + } + + @Override + public Coordinate getTopLeft() { + return topLeft; + } + + @Override + public Coordinate getBottomRight() { + return bottomRight; + } + + @Override + public void paint(Graphics g, Point topLeft, Point bottomRight) { + // Prepare graphics + Color oldColor = g.getColor(); + g.setColor(getColor()); + Stroke oldStroke = null; + if (g instanceof Graphics2D) { + Graphics2D g2 = (Graphics2D) g; + oldStroke = g2.getStroke(); + g2.setStroke(getStroke()); + } + // Draw + g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); + // Restore graphics + g.setColor(oldColor); + if (g instanceof Graphics2D) { + ((Graphics2D) g).setStroke(oldStroke); + } + int width=bottomRight.x-topLeft.x; + int height=bottomRight.y-topLeft.y; + Point p= new Point(topLeft.x+(width/2), topLeft.y+(height/2)); + if(getLayer()==null||getLayer().isVisibleTexts()) paintText(g, p); + } + + public static Style getDefaultStyle(){ + return new Style(Color.BLUE, null, new BasicStroke(2), getDefaultFont()); + } + + @Override + public String toString() { + return "MapRectangle from " + getTopLeft() + " to " + getBottomRight(); + } +} diff --git a/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java b/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java index 4fb527a..ccf61b2 100644 --- a/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java +++ b/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java @@ -32,7 +32,7 @@ public class MemoryTileCache implements TileCache { protected final CacheLinkedListElement lruTiles; public MemoryTileCache() { - hash = new HashMap<String, CacheEntry>(cacheSize); + hash = new HashMap<>(cacheSize); lruTiles = new CacheLinkedListElement(); } diff --git a/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java b/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java index f82a874..c88c207 100644 --- a/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java +++ b/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java @@ -99,7 +99,7 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL log.finest("Tile cache directory: " + cacheDir); cacheDirBase = cacheDir.getAbsolutePath(); - sourceCacheDirMap = new HashMap<TileSource, File>(); + sourceCacheDirMap = new HashMap<>(); } /** @@ -260,28 +260,23 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL } protected boolean loadTileFromFile() { - FileInputStream fin = null; try { tileFile = getTileFile(); if (!tileFile.exists()) return false; loadTagsFromFile(); - if ("no-tile".equals(tile.getValue("tile-info"))) - { + if ("no-tile".equals(tile.getValue("tile-info"))) { tile.setError("No tile at this zoom level"); if (tileFile.exists()) { tileFile.delete(); } tileFile = getTagsFile(); } else { - fin = new FileInputStream(tileFile); - try { + try (FileInputStream fin = new FileInputStream(tileFile)) { if (fin.available() == 0) throw new IOException("File empty"); tile.loadImage(fin); - } finally { - fin.close(); } } @@ -296,13 +291,7 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL listener.tileLoadingFinished(tile, true); fileTilePainted = true; } catch (Exception e) { - try { - if (fin != null) { - fin.close(); - tileFile.delete(); - } - } catch (Exception e1) { - } + tileFile.delete(); tileFile = null; fileAge = 0; } @@ -391,12 +380,11 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL } protected void saveTileToFile(byte[] rawData) { - try { + try ( FileOutputStream f = new FileOutputStream(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() - + "_" + tile.getYtile() + "." + tile.getSource().getTileType()); + + "_" + tile.getYtile() + "." + tile.getSource().getTileType()) + ) { f.write(rawData); - f.close(); - // System.out.println("Saved tile to file: " + tile); } catch (Exception e) { System.err.println("Failed to save tile content: " + e.getLocalizedMessage()); } @@ -408,13 +396,10 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL tagsFile.delete(); return; } - try { - final PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile), - TAGS_CHARSET)); + try (PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile), TAGS_CHARSET))) { for (Entry<String, String> entry : tile.getMetadata().entrySet()) { f.println(entry.getKey() + "=" + entry.getValue()); } - f.close(); } catch (Exception e) { System.err.println("Failed to save tile tags: " + e.getLocalizedMessage()); } @@ -425,11 +410,9 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL File etagFile = new File(tileCacheDir, tile.getZoom() + "_" + tile.getXtile() + "_" + tile.getYtile() + ETAG_FILE_EXT); if (!etagFile.exists()) return; - try { - FileInputStream f = new FileInputStream(etagFile); + try (FileInputStream f = new FileInputStream(etagFile)) { byte[] buf = new byte[f.available()]; f.read(buf); - f.close(); String etag = new String(buf, TAGS_CHARSET.name()); tile.putValue("etag", etag); if (etagFile.delete()) { @@ -443,9 +426,7 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL protected void loadTagsFromFile() { loadOldETagfromFile(); File tagsFile = getTagsFile(); - try { - final BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), - TAGS_CHARSET)); + try (BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), TAGS_CHARSET))) { for (String line = f.readLine(); line != null; line = f.readLine()) { final int i = line.indexOf('='); if (i == -1 || i == 0) { @@ -454,13 +435,11 @@ public class OsmFileCacheTileLoader extends OsmTileLoader implements CachedTileL } tile.putValue(line.substring(0,i),line.substring(i+1)); } - f.close(); } catch (FileNotFoundException e) { } catch (Exception e) { System.err.println("Failed to load tile tags: " + e.getLocalizedMessage()); } } - } public long getMaxFileAge() { diff --git a/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java b/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java index b84f83e..8bb0955 100644 --- a/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java +++ b/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java @@ -24,7 +24,7 @@ public class OsmTileLoader implements TileLoader { /** * Holds the HTTP headers. Insert e.g. User-Agent here when default should not be used. */ - public Map<String, String> headers = new HashMap<String, String>(); + public Map<String, String> headers = new HashMap<>(); public int timeoutConnect = 0; public int timeoutRead = 0; diff --git a/src/org/openstreetmap/gui/jmapviewer/Tile.java b/src/org/openstreetmap/gui/jmapviewer/Tile.java index 99b04d7..9e56e71 100644 --- a/src/org/openstreetmap/gui/jmapviewer/Tile.java +++ b/src/org/openstreetmap/gui/jmapviewer/Tile.java @@ -296,7 +296,7 @@ public class Tile { return; } if (metadata == null) { - metadata = new HashMap<String,String>(); + metadata = new HashMap<>(); } metadata.put(key, value); } diff --git a/src/org/openstreetmap/gui/jmapviewer/events/JMVCommandEvent.java b/src/org/openstreetmap/gui/jmapviewer/events/JMVCommandEvent.java index a3c2c47..7ffc3ce 100644 --- a/src/org/openstreetmap/gui/jmapviewer/events/JMVCommandEvent.java +++ b/src/org/openstreetmap/gui/jmapviewer/events/JMVCommandEvent.java @@ -1,48 +1,48 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer.events; - -import java.util.EventObject; - -/** - * Used for passing events between UI components and other - * objects that register as a JMapViewerEventListener - * - * @author Jason Huntley - * - */ -public class JMVCommandEvent extends EventObject { - public static enum COMMAND { - MOVE, - ZOOM - } - - private COMMAND command; - /** - * - */ - private static final long serialVersionUID = 8701544867914969620L; - - public JMVCommandEvent(COMMAND cmd, Object source) { - super(source); - - setCommand(cmd); - } - - public JMVCommandEvent(Object source) { - super(source); - } - - /** - * @return the command - */ - public COMMAND getCommand() { - return command; - } - - /** - * @param command the command to set - */ - public void setCommand(COMMAND command) { - this.command = command; - } -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer.events; + +import java.util.EventObject; + +/** + * Used for passing events between UI components and other + * objects that register as a JMapViewerEventListener + * + * @author Jason Huntley + * + */ +public class JMVCommandEvent extends EventObject { + public static enum COMMAND { + MOVE, + ZOOM + } + + private COMMAND command; + /** + * + */ + private static final long serialVersionUID = 8701544867914969620L; + + public JMVCommandEvent(COMMAND cmd, Object source) { + super(source); + + setCommand(cmd); + } + + public JMVCommandEvent(Object source) { + super(source); + } + + /** + * @return the command + */ + public COMMAND getCommand() { + return command; + } + + /** + * @param command the command to set + */ + public void setCommand(COMMAND command) { + this.command = command; + } +} diff --git a/src/org/openstreetmap/gui/jmapviewer/images/error.png b/src/org/openstreetmap/gui/jmapviewer/images/error.png index c6a4b4b..16d12d1 100644 Binary files a/src/org/openstreetmap/gui/jmapviewer/images/error.png and b/src/org/openstreetmap/gui/jmapviewer/images/error.png differ diff --git a/src/org/openstreetmap/gui/jmapviewer/images/hourglass.png b/src/org/openstreetmap/gui/jmapviewer/images/hourglass.png index 172ac96..e8bba2a 100644 Binary files a/src/org/openstreetmap/gui/jmapviewer/images/hourglass.png and b/src/org/openstreetmap/gui/jmapviewer/images/hourglass.png differ diff --git a/src/org/openstreetmap/gui/jmapviewer/images/minus.png b/src/org/openstreetmap/gui/jmapviewer/images/minus.png index 4093e64..429237a 100644 Binary files a/src/org/openstreetmap/gui/jmapviewer/images/minus.png and b/src/org/openstreetmap/gui/jmapviewer/images/minus.png differ diff --git a/src/org/openstreetmap/gui/jmapviewer/images/plus.png b/src/org/openstreetmap/gui/jmapviewer/images/plus.png index 6d7df3c..d74f858 100644 Binary files a/src/org/openstreetmap/gui/jmapviewer/images/plus.png and b/src/org/openstreetmap/gui/jmapviewer/images/plus.png differ diff --git a/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java b/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java index 862ec81..24d25e6 100644 --- a/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java +++ b/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java @@ -1,50 +1,50 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer.interfaces; - -import java.awt.Image; - -import org.openstreetmap.gui.jmapviewer.Coordinate; - -public interface Attributed { - /** - * @return True if the tile source requires attribution in text or image form. - */ - boolean requiresAttribution(); - - /** - * @param zoom The optional zoom level for the view. - * @param botRight The bottom right of the bounding box for attribution. - * @param topLeft The top left of the bounding box for attribution. - * @return Attribution text for the image source. - */ - String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight); - - /** - * @return The URL to open when the user clicks the attribution text. - */ - String getAttributionLinkURL(); - - /** - * @return The URL for the attribution image. Null if no image should be displayed. - */ - Image getAttributionImage(); - - /** - * @return The URL to open when the user clicks the attribution image. - * When return value is null, the image is still displayed (provided getAttributionImage() - * returns a value other than null), but the image does not link to a website. - */ - String getAttributionImageURL(); - - /** - * @return The attribution "Terms of Use" text. - * In case it returns null, but getTermsOfUseURL() is not null, a default - * terms of use text is used. - */ - String getTermsOfUseText(); - - /** - * @return The URL to open when the user clicks the attribution "Terms of Use" text. - */ - String getTermsOfUseURL(); -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer.interfaces; + +import java.awt.Image; + +import org.openstreetmap.gui.jmapviewer.Coordinate; + +public interface Attributed { + /** + * @return True if the tile source requires attribution in text or image form. + */ + boolean requiresAttribution(); + + /** + * @param zoom The optional zoom level for the view. + * @param botRight The bottom right of the bounding box for attribution. + * @param topLeft The top left of the bounding box for attribution. + * @return Attribution text for the image source. + */ + String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight); + + /** + * @return The URL to open when the user clicks the attribution text. + */ + String getAttributionLinkURL(); + + /** + * @return The URL for the attribution image. Null if no image should be displayed. + */ + Image getAttributionImage(); + + /** + * @return The URL to open when the user clicks the attribution image. + * When return value is null, the image is still displayed (provided getAttributionImage() + * returns a value other than null), but the image does not link to a website. + */ + String getAttributionImageURL(); + + /** + * @return The attribution "Terms of Use" text. + * In case it returns null, but getTermsOfUseURL() is not null, a default + * terms of use text is used. + */ + String getTermsOfUseText(); + + /** + * @return The URL to open when the user clicks the attribution "Terms of Use" text. + */ + String getTermsOfUseURL(); +} diff --git a/src/org/openstreetmap/gui/jmapviewer/interfaces/JMapViewerEventListener.java b/src/org/openstreetmap/gui/jmapviewer/interfaces/JMapViewerEventListener.java index e0914ad..0064aeb 100644 --- a/src/org/openstreetmap/gui/jmapviewer/interfaces/JMapViewerEventListener.java +++ b/src/org/openstreetmap/gui/jmapviewer/interfaces/JMapViewerEventListener.java @@ -1,17 +1,17 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer.interfaces; - -import java.util.EventListener; - -import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent; - -/** - * Must be implemented for processing commands while user - * interacts with map viewer. - * - * @author Jason Huntley - * - */ -public interface JMapViewerEventListener extends EventListener { - public void processCommand(JMVCommandEvent command); -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer.interfaces; + +import java.util.EventListener; + +import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent; + +/** + * Must be implemented for processing commands while user + * interacts with map viewer. + * + * @author Jason Huntley + * + */ +public interface JMapViewerEventListener extends EventListener { + public void processCommand(JMVCommandEvent command); +} diff --git a/src/org/openstreetmap/gui/jmapviewer/interfaces/MapPolygon.java b/src/org/openstreetmap/gui/jmapviewer/interfaces/MapPolygon.java index 8db97da..73b1259 100644 --- a/src/org/openstreetmap/gui/jmapviewer/interfaces/MapPolygon.java +++ b/src/org/openstreetmap/gui/jmapviewer/interfaces/MapPolygon.java @@ -1,38 +1,38 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer.interfaces; - -import java.awt.Graphics; -import java.awt.Point; -import java.awt.Polygon; -import java.util.List; - -/** - * Interface to be implemented by polygons that can be displayed on the map. - * - * @author Vincent - */ -public interface MapPolygon extends MapObject{ - - /** - * @return Latitude/Longitude of each point of polygon - */ - public List<? extends ICoordinate> getPoints(); - - /** - * Paints the map rectangle on the map. The <code>points</code> - * are specifying the coordinates within <code>g</code> - * - * @param g - * @param points - */ - public void paint(Graphics g, List<Point> points); - - /** - * Paints the map rectangle on the map. The <code>polygon</code> - * is specifying the coordinates within <code>g</code> - * - * @param g - * @param polygon - */ - public void paint(Graphics g, Polygon polygon); -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer.interfaces; + +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Polygon; +import java.util.List; + +/** + * Interface to be implemented by polygons that can be displayed on the map. + * + * @author Vincent + */ +public interface MapPolygon extends MapObject{ + + /** + * @return Latitude/Longitude of each point of polygon + */ + public List<? extends ICoordinate> getPoints(); + + /** + * Paints the map rectangle on the map. The <code>points</code> + * are specifying the coordinates within <code>g</code> + * + * @param g + * @param points + */ + public void paint(Graphics g, List<Point> points); + + /** + * Paints the map rectangle on the map. The <code>polygon</code> + * is specifying the coordinates within <code>g</code> + * + * @param g + * @param polygon + */ + public void paint(Graphics g, Polygon polygon); +} diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java index 66456a6..9505330 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java @@ -1,77 +1,77 @@ -// License: GPL. For details, see Readme.txt file. -package org.openstreetmap.gui.jmapviewer.tilesources; - -import java.awt.Image; - -import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; -import org.openstreetmap.gui.jmapviewer.Coordinate; - -abstract public class AbstractTileSource implements TileSource { - - protected String attributionText; - protected String attributionLinkURL; - protected Image attributionImage; - protected String attributionImageURL; - protected String termsOfUseText; - protected String termsOfUseURL; - - @Override - public boolean requiresAttribution() { - return attributionText != null || attributionImage != null || termsOfUseText != null || termsOfUseURL != null; - } - - @Override - public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) { - return attributionText; - } - - @Override - public String getAttributionLinkURL() { - return attributionLinkURL; - } - - @Override - public Image getAttributionImage() { - return attributionImage; - } - - @Override - public String getAttributionImageURL() { - return attributionImageURL; - } - - @Override - public String getTermsOfUseText() { - return termsOfUseText; - } - - @Override - public String getTermsOfUseURL() { - return termsOfUseURL; - } - - public void setAttributionText(String attributionText) { - this.attributionText = attributionText; - } - - public void setAttributionLinkURL(String attributionLinkURL) { - this.attributionLinkURL = attributionLinkURL; - } - - public void setAttributionImage(Image attributionImage) { - this.attributionImage = attributionImage; - } - - public void setAttributionImageURL(String attributionImageURL) { - this.attributionImageURL = attributionImageURL; - } - - public void setTermsOfUseText(String termsOfUseText) { - this.termsOfUseText = termsOfUseText; - } - - public void setTermsOfUseURL(String termsOfUseURL) { - this.termsOfUseURL = termsOfUseURL; - } - -} +// License: GPL. For details, see Readme.txt file. +package org.openstreetmap.gui.jmapviewer.tilesources; + +import java.awt.Image; + +import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; +import org.openstreetmap.gui.jmapviewer.Coordinate; + +abstract public class AbstractTileSource implements TileSource { + + protected String attributionText; + protected String attributionLinkURL; + protected Image attributionImage; + protected String attributionImageURL; + protected String termsOfUseText; + protected String termsOfUseURL; + + @Override + public boolean requiresAttribution() { + return attributionText != null || attributionImage != null || termsOfUseText != null || termsOfUseURL != null; + } + + @Override + public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) { + return attributionText; + } + + @Override + public String getAttributionLinkURL() { + return attributionLinkURL; + } + + @Override + public Image getAttributionImage() { + return attributionImage; + } + + @Override + public String getAttributionImageURL() { + return attributionImageURL; + } + + @Override + public String getTermsOfUseText() { + return termsOfUseText; + } + + @Override + public String getTermsOfUseURL() { + return termsOfUseURL; + } + + public void setAttributionText(String attributionText) { + this.attributionText = attributionText; + } + + public void setAttributionLinkURL(String attributionLinkURL) { + this.attributionLinkURL = attributionLinkURL; + } + + public void setAttributionImage(Image attributionImage) { + this.attributionImage = attributionImage; + } + + public void setAttributionImageURL(String attributionImageURL) { + this.attributionImageURL = attributionImageURL; + } + + public void setTermsOfUseText(String termsOfUseText) { + this.termsOfUseText = termsOfUseText; + } + + public void setTermsOfUseURL(String termsOfUseURL) { + this.termsOfUseURL = termsOfUseURL; + } + +} diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java index a4cbc16..7504b8a 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java @@ -3,6 +3,7 @@ package org.openstreetmap.gui.jmapviewer.tilesources; import java.awt.Image; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -45,7 +46,11 @@ public class BingAerialTileSource extends AbstractTMSTileSource { private static final Pattern subdomainPattern = Pattern.compile("\\{subdomain\\}"); private static final Pattern quadkeyPattern = Pattern.compile("\\{quadkey\\}"); private static final Pattern culturePattern = Pattern.compile("\\{culture\\}"); + private String brandLogoUri = null; + /** + * Constructs a new {@code BingAerialTileSource}. + */ public BingAerialTileSource() { super("Bing Aerial Maps", "http://example.com/"); } @@ -97,6 +102,8 @@ public class BingAerialTileSource extends AbstractTMSTileSource { subdomains[i] = subdomainTxt.item(i).getNodeValue(); } + brandLogoUri = xpath.compile("/Response/BrandLogoUri/text()").evaluate(document); + XPathExpression attributionXpath = xpath.compile("Attribution/text()"); XPathExpression coverageAreaXpath = xpath.compile("CoverageArea"); XPathExpression zoomMinXpath = xpath.compile("ZoomMin/text()"); @@ -107,7 +114,7 @@ public class BingAerialTileSource extends AbstractTMSTileSource { XPathExpression eastLonXpath = xpath.compile("BoundingBox/EastLongitude/text()"); NodeList imageryProviderNodes = (NodeList) xpath.compile("//ImageryMetadata/ImageryProvider").evaluate(document, XPathConstants.NODESET); - List<Attribution> attributions = new ArrayList<Attribution>(imageryProviderNodes.getLength()); + List<Attribution> attributions = new ArrayList<>(imageryProviderNodes.getLength()); for (int i = 0; i < imageryProviderNodes.getLength(); i++) { Node providerNode = imageryProviderNodes.item(i); @@ -174,10 +181,23 @@ public class BingAerialTileSource extends AbstractTMSTileSource { @Override public Image getAttributionImage() { try { - return ImageIO.read(JMapViewer.class.getResourceAsStream("images/bing_maps.png")); + final InputStream imageResource = JMapViewer.class.getResourceAsStream("images/bing_maps.png"); + if (imageResource != null) { + return ImageIO.read(imageResource); + } else { + // Some Linux distributions (like Debian) will remove Bing logo from sources, so get it at runtime + for (int i = 0; i < 5 && getAttribution() == null; i++) { + // Makes sure attribution is loaded + } + if (brandLogoUri != null && !brandLogoUri.isEmpty()) { + System.out.println("Reading Bing logo from "+brandLogoUri); + return ImageIO.read(new URL(brandLogoUri)); + } + } } catch (IOException e) { - return null; + System.err.println("Error while retrieving Bing logo: "+e.getMessage()); } + return null; } @Override diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java index 8ec5dbc..3d4ab7f 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java @@ -16,7 +16,7 @@ public class OsmTileSource { private static final String[] SERVER = { "a", "b", "c" }; private int SERVER_NUM = 0; - + /** * Constructs a new {@code "Mapnik"} tile source. */ diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java index fd48b29..934bd71 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java @@ -93,7 +93,7 @@ public class ScanexTileSource extends TMSTileSource { public int LatToY(double lat, int zoom) { return (int )(latToTileY(lat, zoom) * OsmMercator.TILE_SIZE); } - + @Override public double YToLat(int y, int zoom) { return tileYToLat((double )y / OsmMercator.TILE_SIZE, zoom); diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java index 1296a06..fea0e5a 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java @@ -11,7 +11,7 @@ public class TemplatedTMSTileSource extends TMSTileSource { private Random rand = null; private String[] randomParts = null; - private Map<String, String> headers = new HashMap<String, String>(); + private Map<String, String> headers = new HashMap<>(); public static final String PATTERN_ZOOM = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}"; public static final String PATTERN_X = "\\{x\\}"; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/jmapviewer.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel