[Git][debian-gis-team/jmapviewer][upstream] New upstream version 2.8+dfsg

Bas Couwenberg gitlab at salsa.debian.org
Sun Dec 2 10:53:39 GMT 2018


Bas Couwenberg pushed to branch upstream at Debian GIS Project / jmapviewer


Commits:
bf7999bc by Bas Couwenberg at 2018-12-02T10:36:27Z
New upstream version 2.8+dfsg
- - - - -


16 changed files:

- build.xml
- src/org/openstreetmap/gui/jmapviewer/Coordinate.java
- src/org/openstreetmap/gui/jmapviewer/Demo.java
- src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java
- src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
- src/org/openstreetmap/gui/jmapviewer/JMapViewerTree.java
- src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
- src/org/openstreetmap/gui/jmapviewer/Projected.java
- src/org/openstreetmap/gui/jmapviewer/Tile.java
- src/org/openstreetmap/gui/jmapviewer/checkBoxTree/CheckBoxTree.java
- src/org/openstreetmap/gui/jmapviewer/interfaces/ICoordinate.java
- src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
- src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java


Changes:

=====================================
build.xml
=====================================
@@ -1,30 +1,67 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<project default="all" name="Compile and build java classes plus jar archives">
+<project default="all" name="jmapviewer" xmlns:jacoco="antlib:org.jacoco.ant" xmlns:if="ant:if" xmlns:unless="ant:unless">
 
-	<target name="all" depends="clean,build,svn_info,pack,create_run_jar,spotbugs,checkstyle,javadoc,create_release_zip,create_source_release_zip" />
+    <property name="java.lang.version" value="1.8" />
+    <dirname property="base.dir" file="${ant.file.jmapviewer}"/>
+    <property name="tools.dir" location="${base.dir}/tools"/>
+    <property name="jacoco.includes" value="org.openstreetmap.gui.jmapviewer.*" />
+    <property name="jacoco.inclbootstrapclasses" value="false" />
+    <property name="jacoco.inclnolocationclasses" value="false" />
+    <!-- For Java specific stuff by version -->
+    <condition property="isJava9"><matches string="${ant.java.version}" pattern="(1.)?(9|1[0-9])" /></condition>
+    <condition property="isJava10"><matches string="${ant.java.version}" pattern="1[0-9]" /></condition>
+    <condition property="isJava11"><matches string="${ant.java.version}" pattern="1[1-9]" /></condition>
+    <condition property="isJava12"><matches string="${ant.java.version}" pattern="1[2-9]" /></condition>
+    <condition property="isJava13"><matches string="${ant.java.version}" pattern="1[3-9]" /></condition>
+    <!-- Disable jacoco on Java 13+, see https://github.com/jacoco/jacoco/pull/738 -->
+    <condition property="coverageByDefault">
+        <not>
+            <isset property="isJava13"/>
+        </not>
+    </condition>
+    <path id="test.classpath">
+        <fileset dir="${tools.dir}/testlib">
+            <include name="**/*.jar"/>
+        </fileset>
+        <pathelement location="bin"/>
+    </path>
 
-	<target name="clean">
-		<mkdir dir="bin" />
-		<delete>
-			<fileset dir="bin">
-				<include name="**" />
-			</fileset>
-			<fileset dir="." includes="*.jar"/>
-		</delete>
-	</target>
+    <target name="all" depends="clean,build,test,svn_info,pack,create_run_jar,spotbugs,checkstyle,javadoc,create_release_zip,create_source_release_zip" />
 
-	<target name="build">
-		<javac srcdir="src" destdir="bin" source="1.8" target="1.8" debug="true" includeantruntime="false" encoding="UTF-8">
-			<include name="org/openstreetmap/gui/jmapviewer/**" />
-		</javac>
+    <target name="clean">
+        <mkdir dir="bin" />
+        <mkdir dir="bintest" />
+        <mkdir dir="javadoc" />
+        <mkdir dir="report" />
+        <delete>
+            <fileset dir="bin">
+                <include name="**" />
+            </fileset>
+            <fileset dir="bintest">
+                <include name="**" />
+            </fileset>
+            <fileset dir="javadoc">
+                <include name="**" />
+            </fileset>
+            <fileset dir="report">
+                <include name="**" />
+            </fileset>
+            <fileset dir="." includes="*.jar,*.exec"/>
+        </delete>
+    </target>
+
+    <target name="build" depends="clean">
+        <javac srcdir="src" destdir="bin" source="${java.lang.version}" target="${java.lang.version}" debug="true" includeantruntime="false" encoding="UTF-8">
+            <include name="org/openstreetmap/gui/jmapviewer/**" />
+        </javac>
+
+        <copy todir="bin">
+            <fileset dir="src">
+                <include name="**/*.png" />
+            </fileset>
+        </copy>
+    </target>
 
-		<copy todir="bin">
-			<fileset dir="src">
-				<include name="**/*.png" />
-			</fileset>
-		</copy>
-	</target>
-	
     <target name="svn_info" description="Get SVN info for use in JAR/ZIP filenames.">
         <!-- Get the svn ReleaseVersion property -->
         <exec executable="svn" outputproperty="svnReleaseVersion">
@@ -32,52 +69,52 @@
             <env key="LANG" value="en_US"/>
         </exec>
     </target>
-	
-	<target name="pack" depends="build">
-		<!-- Create the JAR file containing the compiled class files -->
-		<jar destfile="JMapViewer.jar" filesetmanifest="mergewithoutmain">
-			<fileset dir="bin" includes="**/jmapviewer/**" />
-		</jar>
-		<!-- Create the JAR file containing the source java files -->
-		<jar destfile="JMapViewer_src.jar" filesetmanifest="mergewithoutmain">
-			<fileset dir="src" includes="**/jmapviewer/**" />
-		</jar>
-	</target>
-	
-	<!-- if you want to build outside of svn, use "ant clean build [pack]" -->
-	
-	<target name="create_run_jar" description="Create a JAR file that can be used to execute the JMapViewer demo app. Requires JMapViewer.jar to be present.">
-		<jar destfile="JMapViewer_Demo.jar" filesetmanifest="mergewithoutmain">
-			<manifest>
-				<attribute name="Main-Class" value="org.openstreetmap.gui.jmapviewer.Demo" />
-				<attribute name="Class-Path" value="JMapViewer.jar" />
-			</manifest>
-		</jar>
-	</target>
+    
+    <target name="pack" depends="build">
+        <!-- Create the JAR file containing the compiled class files -->
+        <jar destfile="JMapViewer.jar" filesetmanifest="mergewithoutmain">
+            <fileset dir="bin" includes="**/jmapviewer/**" />
+        </jar>
+        <!-- Create the JAR file containing the source java files -->
+        <jar destfile="JMapViewer_src.jar" filesetmanifest="mergewithoutmain">
+            <fileset dir="src" includes="**/jmapviewer/**" />
+        </jar>
+    </target>
+    
+    <!-- if you want to build outside of svn, use "ant clean build [pack]" -->
+    
+    <target name="create_run_jar" description="Create a JAR file that can be used to execute the JMapViewer demo app. Requires JMapViewer.jar to be present.">
+        <jar destfile="JMapViewer_Demo.jar" filesetmanifest="mergewithoutmain">
+            <manifest>
+                <attribute name="Main-Class" value="org.openstreetmap.gui.jmapviewer.Demo" />
+                <attribute name="Class-Path" value="JMapViewer.jar" />
+            </manifest>
+        </jar>
+    </target>
 
-	<target name="create_release_zip" description="Create a release zip file containing the binary and source jar files as well as the demo starter">
-		<zip basedir="." destfile="releases/${svnReleaseVersion}/JMapViewer-${svnReleaseVersion}.zip">
-			<include name="JMapViewer*.jar" />
-			<include name="Readme.txt" />
-			<include name="Gpl.txt" />
-		</zip>
-		<delete>
-			<fileset dir="." includes="JMapViewer*.jar"/>
-		</delete> 
-	</target>
-	
-	<target name="create_source_release_zip" description="Create a release zip file containing the source files">
-		<zip destfile="releases/${svnReleaseVersion}/JMapViewer-${svnReleaseVersion}-Source.zip">
-			<zipfileset file="Readme.txt" prefix="jmapviewer-${svnReleaseVersion}"/>
-			<zipfileset file="build.xml" prefix="jmapviewer-${svnReleaseVersion}"/>
-			<zipfileset file="Gpl.txt" prefix="jmapviewer-${svnReleaseVersion}"/>
-			<zipfileset dir="src" includes="**/jmapviewer/**" prefix="jmapviewer-${svnReleaseVersion}/src"/>
-		</zip>
-	</target>
+    <target name="create_release_zip" description="Create a release zip file containing the binary and source jar files as well as the demo starter">
+        <zip basedir="." destfile="releases/${svnReleaseVersion}/JMapViewer-${svnReleaseVersion}.zip">
+            <include name="JMapViewer*.jar" />
+            <include name="Readme.txt" />
+            <include name="Gpl.txt" />
+        </zip>
+        <delete>
+            <fileset dir="." includes="JMapViewer*.jar"/>
+        </delete> 
+    </target>
+    
+    <target name="create_source_release_zip" description="Create a release zip file containing the source files">
+        <zip destfile="releases/${svnReleaseVersion}/JMapViewer-${svnReleaseVersion}-Source.zip">
+            <zipfileset file="Readme.txt" prefix="jmapviewer-${svnReleaseVersion}"/>
+            <zipfileset file="build.xml" prefix="jmapviewer-${svnReleaseVersion}"/>
+            <zipfileset file="Gpl.txt" prefix="jmapviewer-${svnReleaseVersion}"/>
+            <zipfileset dir="src" includes="**/jmapviewer/**" prefix="jmapviewer-${svnReleaseVersion}/src"/>
+        </zip>
+    </target>
 
     <target name="checkstyle">
         <taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" 
-        	classpath="tools/checkstyle/checkstyle-all.jar"/>
+            classpath="tools/checkstyle/checkstyle-all.jar"/>
         <checkstyle config="tools/checkstyle/jmapviewer_checks.xml">
             <fileset dir="${basedir}/src" includes="**/*.java" />
             <formatter type="xml" toFile="checkstyle-jmapviewer.xml"/>
@@ -86,7 +123,7 @@
 
     <target name="spotbugs" depends="pack">
         <taskdef name="spotbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" 
-        	classpath="tools/spotbugs/spotbugs-ant.jar"/>
+            classpath="tools/spotbugs/spotbugs-ant.jar"/>
         <path id="spotbugs-classpath">
             <fileset dir="tools/spotbugs/">
                 <include name="*.jar"/>
@@ -103,7 +140,7 @@
         </spotbugs>
     </target>
 
-	<target name="javadoc">
+    <target name="javadoc">
         <javadoc destdir="javadoc" 
                 sourcepath="src"
                 encoding="UTF-8"    
@@ -116,7 +153,36 @@
             <link href="http://docs.oracle.com/javase/8/docs/api"/>
             <doctitle><![CDATA[<h2>JMapViewer - Javadoc</h2>]]></doctitle>
             <bottom><![CDATA[<a href="https://josm.openstreetmap.de/">JMapViewer</a>]]></bottom>
+            <arg value="-html5" if:set="isJava9" />
         </javadoc>
     </target>
 
+    <target name="test" depends="clean, build">
+        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="${tools.dir}/jacocoant.jar" />
+        <javac srcdir="test" destdir="bintest"
+            target="${java.lang.version}" source="${java.lang.version}" debug="on"
+            includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8">
+            <compilerarg value="-Xlint:all"/>
+            <compilerarg value="-Xlint:-serial"/>
+            <classpath>
+            	<path refid="test.classpath"/>
+            </classpath>
+        </javac>
+        <jacoco:coverage enabled="@{coverage}" includes="${jacoco.includes}"
+            inclbootstrapclasses="${jacoco.inclbootstrapclasses}" inclnolocationclasses="${jacoco.inclnolocationclasses}">
+            <junit printsummary="yes" fork="true" forkmode="once">
+                <jvmarg value="-Dfile.encoding=UTF-8"/>
+                <classpath>
+                    <path refid="test.classpath"/>
+                    <pathelement location="bintest"/>
+                </classpath>
+                <formatter type="plain"/>
+                <formatter type="xml"/>
+                <batchtest fork="yes" todir="report">
+                    <fileset dir="bintest" includes="**/*Test.class"/>
+                </batchtest>
+            </junit>
+        </jacoco:coverage>
+    </target>
+
 </project>


=====================================
src/org/openstreetmap/gui/jmapviewer/Coordinate.java
=====================================
@@ -19,6 +19,11 @@ import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
 public class Coordinate implements ICoordinate {
     private transient Point2D.Double data;
 
+    /**
+     * Constructs a new {@code Coordinate}.
+     * @param lat latitude in degrees
+     * @param lon longitude in degrees
+     */
     public Coordinate(double lat, double lon) {
         data = new Point2D.Double(lon, lat);
     }
@@ -61,20 +66,16 @@ public class Coordinate implements ICoordinate {
 
     @Override
     public int hashCode() {
-        int hash = 3;
-        hash = 61 * hash + Objects.hashCode(this.data);
-        return hash;
+        return Objects.hashCode(data);
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (obj == null) {
+        if (this == obj)
+            return true;
+        if (obj == null || !(obj instanceof Coordinate))
             return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
         final Coordinate other = (Coordinate) obj;
-        return Objects.equals(this.data, other.data);
+        return Objects.equals(data, other.data);
     }
 }


=====================================
src/org/openstreetmap/gui/jmapviewer/Demo.java
=====================================
@@ -4,8 +4,6 @@ package org.openstreetmap.gui.jmapviewer;
 import java.awt.BorderLayout;
 import java.awt.Cursor;
 import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.MouseAdapter;
@@ -79,12 +77,7 @@ public class Demo extends JFrame implements JMapViewerEventListener {
                 + "left double click or mouse wheel to zoom.");
         helpPanel.add(helpLabel);
         JButton button = new JButton("setDisplayToFitMapMarkers");
-        button.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setDisplayToFitMapMarkers();
-            }
-        });
+        button.addActionListener(e -> map().setDisplayToFitMapMarkers());
         JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] {
                 new OsmTileSource.Mapnik(),
                 new OsmTileSource.CycleMap(),
@@ -109,57 +102,27 @@ public class Demo extends JFrame implements JMapViewerEventListener {
         panelTop.add(tileLoaderSelector);
         final JCheckBox showMapMarker = new JCheckBox("Map markers visible");
         showMapMarker.setSelected(map().getMapMarkersVisible());
-        showMapMarker.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setMapMarkerVisible(showMapMarker.isSelected());
-            }
-        });
+        showMapMarker.addActionListener(e -> map().setMapMarkerVisible(showMapMarker.isSelected()));
         panelBottom.add(showMapMarker);
         ///
         final JCheckBox showTreeLayers = new JCheckBox("Tree Layers visible");
-        showTreeLayers.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                treeMap.setTreeVisible(showTreeLayers.isSelected());
-            }
-        });
+        showTreeLayers.addActionListener(e -> treeMap.setTreeVisible(showTreeLayers.isSelected()));
         panelBottom.add(showTreeLayers);
         ///
         final JCheckBox showToolTip = new JCheckBox("ToolTip visible");
-        showToolTip.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setToolTipText(null);
-            }
-        });
+        showToolTip.addActionListener(e -> map().setToolTipText(null));
         panelBottom.add(showToolTip);
         ///
         final JCheckBox showTileGrid = new JCheckBox("Tile grid visible");
         showTileGrid.setSelected(map().isTileGridVisible());
-        showTileGrid.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setTileGridVisible(showTileGrid.isSelected());
-            }
-        });
+        showTileGrid.addActionListener(e -> map().setTileGridVisible(showTileGrid.isSelected()));
         panelBottom.add(showTileGrid);
         final JCheckBox showZoomControls = new JCheckBox("Show zoom controls");
         showZoomControls.setSelected(map().getZoomControlsVisible());
-        showZoomControls.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setZoomContolsVisible(showZoomControls.isSelected());
-            }
-        });
+        showZoomControls.addActionListener(e -> map().setZoomControlsVisible(showZoomControls.isSelected()));
         panelBottom.add(showZoomControls);
         final JCheckBox scrollWrapEnabled = new JCheckBox("Scrollwrap enabled");
-        scrollWrapEnabled.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                map().setScrollWrapEnabled(scrollWrapEnabled.isSelected());
-            }
-        });
+        scrollWrapEnabled.addActionListener(e -> map().setScrollWrapEnabled(scrollWrapEnabled.isSelected()));
         panelBottom.add(scrollWrapEnabled);
         panelBottom.add(button);
 


=====================================
src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java
=====================================
@@ -2,15 +2,21 @@
 package org.openstreetmap.gui.jmapviewer;
 
 import java.awt.Desktop;
+import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.text.MessageFormat;
+import java.util.Objects;
 import java.util.logging.Logger;
 
+import javax.imageio.ImageIO;
+
 public final class FeatureAdapter {
 
     private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter();
+    private static ImageAdapter imageAdapter = new DefaultImageAdapter();
     private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter();
     private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter();
 
@@ -31,22 +37,34 @@ public final class FeatureAdapter {
         Logger getLogger(String name);
     }
 
+    public interface ImageAdapter {
+        BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException;
+    }
+
     public static void registerBrowserAdapter(BrowserAdapter browserAdapter) {
-        FeatureAdapter.browserAdapter = browserAdapter;
+        FeatureAdapter.browserAdapter = Objects.requireNonNull(browserAdapter);
+    }
+
+    public static void registerImageAdapter(ImageAdapter imageAdapter) {
+        FeatureAdapter.imageAdapter = Objects.requireNonNull(imageAdapter);
     }
 
     public static void registerTranslationAdapter(TranslationAdapter translationAdapter) {
-        FeatureAdapter.translationAdapter = translationAdapter;
+        FeatureAdapter.translationAdapter = Objects.requireNonNull(translationAdapter);
     }
 
     public static void registerLoggingAdapter(LoggingAdapter loggingAdapter) {
-        FeatureAdapter.loggingAdapter = loggingAdapter;
+        FeatureAdapter.loggingAdapter = Objects.requireNonNull(loggingAdapter);
     }
 
     public static void openLink(String url) {
         browserAdapter.openLink(url);
     }
 
+    public static BufferedImage readImage(URL url) throws IOException {
+        return imageAdapter.read(url, false, false);
+    }
+
     public static String tr(String text, Object... objects) {
         return translationAdapter.tr(text, objects);
     }
@@ -72,6 +90,13 @@ public final class FeatureAdapter {
         }
     }
 
+    public static class DefaultImageAdapter implements ImageAdapter {
+        @Override
+        public BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException {
+            return ImageIO.read(input);
+        }
+    }
+
     public static class DefaultTranslationAdapter implements TranslationAdapter {
         @Override
         public String tr(String text, Object... objects) {


=====================================
src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
=====================================
@@ -6,9 +6,8 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -18,8 +17,6 @@ import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JPanel;
 import javax.swing.JSlider;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
 import javax.swing.event.EventListenerList;
 
 import org.openstreetmap.gui.jmapviewer.events.JMVCommandEvent;
@@ -163,18 +160,12 @@ public class JMapViewer extends JPanel implements TileLoaderListener {
         zoomSlider.setOrientation(JSlider.VERTICAL);
         zoomSlider.setBounds(10, 10, 30, 150);
         zoomSlider.setOpaque(false);
-        zoomSlider.addChangeListener(new ChangeListener() {
-            @Override
-            public void stateChanged(ChangeEvent e) {
-                setZoom(zoomSlider.getValue());
-            }
-        });
+        zoomSlider.addChangeListener(e -> setZoom(zoomSlider.getValue()));
         zoomSlider.setFocusable(false);
         add(zoomSlider);
         int size = 18;
-        URL url = JMapViewer.class.getResource("images/plus.png");
-        if (url != null) {
-            ImageIcon icon = new ImageIcon(url);
+        ImageIcon icon = getImageIcon("images/plus.png");
+        if (icon != null) {
             zoomInButton = new JButton(icon);
         } else {
             zoomInButton = new JButton("+");
@@ -182,18 +173,11 @@ public class JMapViewer extends JPanel implements TileLoaderListener {
             zoomInButton.setMargin(new Insets(0, 0, 0, 0));
         }
         zoomInButton.setBounds(4, 155, size, size);
-        zoomInButton.addActionListener(new ActionListener() {
-
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                zoomIn();
-            }
-        });
+        zoomInButton.addActionListener(e -> zoomIn());
         zoomInButton.setFocusable(false);
         add(zoomInButton);
-        url = JMapViewer.class.getResource("images/minus.png");
-        if (url != null) {
-            ImageIcon icon = new ImageIcon(url);
+        icon = getImageIcon("images/minus.png");
+        if (icon != null) {
             zoomOutButton = new JButton(icon);
         } else {
             zoomOutButton = new JButton("-");
@@ -201,17 +185,23 @@ public class JMapViewer extends JPanel implements TileLoaderListener {
             zoomOutButton.setMargin(new Insets(0, 0, 0, 0));
         }
         zoomOutButton.setBounds(8 + size, 155, size, size);
-        zoomOutButton.addActionListener(new ActionListener() {
-
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                zoomOut();
-            }
-        });
+        zoomOutButton.addActionListener(e -> zoomOut());
         zoomOutButton.setFocusable(false);
         add(zoomOutButton);
     }
 
+    private static ImageIcon getImageIcon(String name) {
+        URL url = JMapViewer.class.getResource(name);
+        if (url != null) {
+            try {
+                return new ImageIcon(FeatureAdapter.readImage(url));
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
     /**
      * Changes the map pane so that it is centered on the specified coordinate
      * at the given zoom level.


=====================================
src/org/openstreetmap/gui/jmapviewer/JMapViewerTree.java
=====================================
@@ -3,8 +3,6 @@ package org.openstreetmap.gui.jmapviewer;
 
 import java.awt.BorderLayout;
 import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.List;
@@ -93,21 +91,15 @@ public class JMapViewerTree extends JPanel {
         } else if (layer.isVisibleTexts()) popup.add(menuItemHide);
         else popup.add(menuItemShow);
 
-        menuItemShow.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent arg0) {
-                setVisibleTexts(layer, true);
-                if (layer.getParent() != null) layer.getParent().calculateVisibleTexts();
-                map.repaint();
-            }
+        menuItemShow.addActionListener(e -> {
+            setVisibleTexts(layer, true);
+            if (layer.getParent() != null) layer.getParent().calculateVisibleTexts();
+            map.repaint();
         });
-        menuItemHide.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent arg0) {
-                setVisibleTexts(layer, false);
-                if (layer.getParent() != null) layer.getParent().calculateVisibleTexts();
-                map.repaint();
-            }
+        menuItemHide.addActionListener(e -> {
+            setVisibleTexts(layer, false);
+            if (layer.getParent() != null) layer.getParent().calculateVisibleTexts();
+            map.repaint();
         });
 
         return popup;


=====================================
src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
=====================================
@@ -188,7 +188,7 @@ public class OsmTileLoader implements TileLoader {
 
     /**
      * Sets the maximum number of concurrent connections the tile loader will do
-     * @param num number of conncurent connections
+     * @param num number of concurrent connections
      */
     public static void setConcurrentConnections(int num) {
         jobDispatcher.setMaximumPoolSize(num);


=====================================
src/org/openstreetmap/gui/jmapviewer/Projected.java
=====================================
@@ -52,21 +52,16 @@ public class Projected implements IProjected {
 
     @Override
     public int hashCode() {
-        int hash = 3;
-        hash = 61 * hash + Objects.hashCode(this.data);
-        return hash;
+        return Objects.hashCode(data);
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (obj == null) {
+        if (this == obj)
+            return true;
+        if (obj == null || !(obj instanceof Projected))
             return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
         final Projected other = (Projected) obj;
-        return Objects.equals(this.data, other.data);
+        return Objects.equals(data, other.data);
     }
 }
-


=====================================
src/org/openstreetmap/gui/jmapviewer/Tile.java
=====================================
@@ -9,6 +9,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 
 import javax.imageio.ImageIO;
@@ -80,7 +81,7 @@ public class Tile {
 
     private static BufferedImage loadImage(String path) {
         try {
-            return ImageIO.read(JMapViewer.class.getResourceAsStream(path));
+            return FeatureAdapter.readImage(JMapViewer.class.getResource(path));
         } catch (IOException | IllegalArgumentException ex) {
             ex.printStackTrace();
             return null;
@@ -339,18 +340,13 @@ public class Tile {
     public boolean equals(Object obj) {
         if (this == obj)
             return true;
-        if (obj == null)
+        if (obj == null || !(obj instanceof Tile))
             return false;
-        if (getClass() != obj.getClass())
-            return false;
-        Tile other = (Tile) obj;
-        if (xtile != other.xtile)
-            return false;
-        if (ytile != other.ytile)
-            return false;
-        if (zoom != other.zoom)
-            return false;
-        return getTileSource().equals(other.getTileSource());
+        final Tile other = (Tile) obj;
+        return xtile == other.xtile
+            && ytile == other.ytile
+            && zoom == other.zoom
+            && Objects.equals(source, other.source);
     }
 
     public static String getTileKey(TileSource source, int xtile, int ytile, int zoom) {
@@ -459,5 +455,4 @@ public class Tile {
         loading = false;
         loaded = false;
     }
-
 }


=====================================
src/org/openstreetmap/gui/jmapviewer/checkBoxTree/CheckBoxTree.java
=====================================
@@ -108,13 +108,6 @@ public class CheckBoxTree extends JTree {
         final CheckBoxTree tree = new CheckBoxTree(root);
         ((DefaultMutableTreeNode) tree.getModel().getRoot()).add(new DefaultMutableTreeNode(new CheckBoxNodeData("gggg", null)));
         ((DefaultTreeModel) tree.getModel()).reload();
-        // listen for changes in the selection
-        tree.addTreeSelectionListener(new TreeSelectionListener() {
-            @Override
-            public void valueChanged(final TreeSelectionEvent e) {
-                //System.out.println("selection changed");
-            }
-        });
         // show the tree on screen
         final JFrame frame = new JFrame("CheckBox Tree");
         final JScrollPane scrollPane = new JScrollPane(tree);


=====================================
src/org/openstreetmap/gui/jmapviewer/interfaces/ICoordinate.java
=====================================
@@ -1,13 +1,32 @@
 // License: GPL. For details, see Readme.txt file.
 package org.openstreetmap.gui.jmapviewer.interfaces;
 
+/**
+ * Latitude/Longitude coordinates.
+ */
 public interface ICoordinate {
 
+    /**
+     * Returns latitude.
+     * @return latitude in degrees
+     */
     double getLat();
 
+    /**
+     * Sets latitude.
+     * @param lat latitude in degrees
+     */
     void setLat(double lat);
 
+    /**
+     * Returns longitude.
+     * @return longitude in degrees
+     */
     double getLon();
 
+    /**
+     * Sets longitude.
+     * @param lon longitude in degrees
+     */
     void setLon(double lon);
 }


=====================================
src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
=====================================
@@ -82,7 +82,6 @@ public interface TileSource extends Attributed {
 
     /**
      * @return default tile size, for this tile source
-     * TODO: @since
      */
     int getDefaultTileSize();
 


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
=====================================
@@ -3,7 +3,6 @@ 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;
@@ -17,7 +16,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.regex.Pattern;
 
-import javax.imageio.ImageIO;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -28,6 +26,7 @@ import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 
 import org.openstreetmap.gui.jmapviewer.Coordinate;
+import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
 import org.openstreetmap.gui.jmapviewer.JMapViewer;
 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
 import org.w3c.dom.Document;
@@ -190,9 +189,9 @@ public class BingAerialTileSource extends TMSTileSource {
     @Override
     public Image getAttributionImage() {
         try {
-            final InputStream imageResource = JMapViewer.class.getResourceAsStream("images/bing_maps.png");
+            final URL imageResource = JMapViewer.class.getResource("images/bing_maps.png");
             if (imageResource != null) {
-                return ImageIO.read(imageResource);
+                return FeatureAdapter.readImage(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++) {
@@ -203,7 +202,7 @@ public class BingAerialTileSource extends TMSTileSource {
                 }
                 if (brandLogoUri != null && !brandLogoUri.isEmpty()) {
                     System.out.println("Reading Bing logo from "+brandLogoUri);
-                    return ImageIO.read(new URL(brandLogoUri));
+                    return FeatureAdapter.readImage(new URL(brandLogoUri));
                 }
             }
         } catch (IOException e) {


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java
=====================================
@@ -1,4 +1,6 @@
-// License: GPL. For details, see Readme.txt file.
+// License: BSD or GPL. For details, see Readme.txt file.
+// Authors of this file, namely Gleb Smirnoff and Andrey Boltenkov, allow
+// to reuse the code under BSD license.
 package org.openstreetmap.gui.jmapviewer.tilesources;
 
 import java.awt.Point;
@@ -187,7 +189,7 @@ public class ScanexTileSource extends TMSTileSource {
         double f = Math.tan(Math.PI/4+lat/2) -
             ec * Math.pow(Math.tan(Math.PI/4 + Math.asin(E * sinl)/2), E);
         double df = 1/(1 - sinl) - ec * E * cosl/((1 - E * sinl) *
-            (Math.sqrt(1 - E * E * sinl * sinl)));
+            Math.sqrt(1 - E * E * sinl * sinl));
 
         return f/df;
     }


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
=====================================
@@ -33,19 +33,22 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
     private Random rand;
     private String[] randomParts;
     private final Map<String, String> headers = new HashMap<>();
+    private boolean inverse_zoom = false;
+    private int zoom_offset = 0;
 
     // CHECKSTYLE.OFF: SingleSpaceSeparator
     private static final String COOKIE_HEADER   = "Cookie";
-    private static final String PATTERN_ZOOM    = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}";
-    private static final String PATTERN_X       = "\\{x\\}";
-    private static final String PATTERN_Y       = "\\{y\\}";
-    private static final String PATTERN_Y_YAHOO = "\\{!y\\}";
-    private static final String PATTERN_NEG_Y   = "\\{-y\\}";
-    private static final String PATTERN_SWITCH  = "\\{switch:([^}]+)\\}";
-    private static final String PATTERN_HEADER  = "\\{header\\(([^,]+),([^}]+)\\)\\}";
+    private static final Pattern PATTERN_ZOOM    = Pattern.compile("\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}");
+    private static final Pattern PATTERN_X       = Pattern.compile("\\{x\\}");
+    private static final Pattern PATTERN_Y       = Pattern.compile("\\{y\\}");
+    private static final Pattern PATTERN_Y_YAHOO = Pattern.compile("\\{!y\\}");
+    private static final Pattern PATTERN_NEG_Y   = Pattern.compile("\\{-y\\}");
+    private static final Pattern PATTERN_SWITCH  = Pattern.compile("\\{switch:([^}]+)\\}");
+    private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
+    private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))\\}");
     // CHECKSTYLE.ON: SingleSpaceSeparator
 
-    private static final String[] ALL_PATTERNS = {
+    private static final Pattern[] ALL_PATTERNS = {
         PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, PATTERN_SWITCH
     };
 
@@ -64,20 +67,33 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
 
     private void handleTemplate() {
         // Capturing group pattern on switch values
-        Matcher m = Pattern.compile(".*"+PATTERN_SWITCH+".*").matcher(baseUrl);
-        if (m.matches()) {
+        Matcher m = PATTERN_SWITCH.matcher(baseUrl);
+        if (m.find()) {
             rand = new Random();
             randomParts = m.group(1).split(",");
         }
-        Pattern pattern = Pattern.compile(PATTERN_HEADER);
         StringBuffer output = new StringBuffer();
-        Matcher matcher = pattern.matcher(baseUrl);
+        Matcher matcher = PATTERN_HEADER.matcher(baseUrl);
         while (matcher.find()) {
             headers.put(matcher.group(1), matcher.group(2));
             matcher.appendReplacement(output, "");
         }
         matcher.appendTail(output);
         baseUrl = output.toString();
+        m = PATTERN_ZOOM.matcher(this.baseUrl);
+        if (m.find()) {
+            if (m.group(1) != null) {
+                inverse_zoom = true;
+                zoom_offset = Integer.parseInt(m.group(1));
+            }
+            if (m.group(2) != null) {
+                String ofs = m.group(2);
+                if (ofs.startsWith("+"))
+                    ofs = ofs.substring(1);
+                zoom_offset += Integer.parseInt(ofs);
+            }
+        }
+
     }
 
     @Override
@@ -87,29 +103,44 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
 
     @Override
     public String getTileUrl(int zoom, int tilex, int tiley) {
-        int finalZoom = zoom;
-        Matcher m = Pattern.compile(".*"+PATTERN_ZOOM+".*").matcher(this.baseUrl);
-        if (m.matches()) {
-            if (m.group(1) != null) {
-                finalZoom = Integer.parseInt(m.group(1))-zoom;
-            }
-            if (m.group(2) != null) {
-                String ofs = m.group(2);
-                if (ofs.startsWith("+"))
-                    ofs = ofs.substring(1);
-                finalZoom += Integer.parseInt(ofs);
+        StringBuffer url = new StringBuffer(baseUrl.length());
+        Matcher matcher = PATTERN_PARAM.matcher(baseUrl);
+        while (matcher.find()) {
+            String replacement = "replace";
+            switch (matcher.group(1)) {
+            case "z": // PATTERN_ZOOM
+            case "zoom":
+                replacement = Integer.toString((inverse_zoom ? -1 * zoom : zoom) + zoom_offset);
+                break;
+            case "x": // PATTERN_X
+                replacement = Integer.toString(tilex);
+                break;
+            case "y": // PATTERN_Y
+                replacement = Integer.toString(tiley);
+                break;
+            case "!y": // PATTERN_Y_YAHOO
+                replacement = Integer.toString((int) Math.pow(2, zoom-1)-1-tiley);
+                break;
+            case "-y": // PATTERN_NEG_Y
+                replacement = Integer.toString((int) Math.pow(2, zoom)-1-tiley);
+                break;
+            case "switch:":
+                replacement = randomParts[rand.nextInt(randomParts.length)];
+                break;
+            default:
+                // handle switch/zoom here, as group will contain parameters and switch will not work
+                if (PATTERN_ZOOM.matcher("{" + matcher.group(1) + "}").matches()) {
+                    replacement = Integer.toString((inverse_zoom ? -1 * zoom : zoom) + zoom_offset);
+                } else if (PATTERN_SWITCH.matcher("{" + matcher.group(1) + "}").matches()) {
+                    replacement = randomParts[rand.nextInt(randomParts.length)];
+                } else {
+                    replacement = '{' + matcher.group(1) + '}';
+                }
             }
+            matcher.appendReplacement(url, replacement);
         }
-        String r = this.baseUrl
-            .replaceAll(PATTERN_ZOOM, Integer.toString(finalZoom))
-            .replaceAll(PATTERN_X, Integer.toString(tilex))
-            .replaceAll(PATTERN_Y, Integer.toString(tiley))
-            .replaceAll(PATTERN_Y_YAHOO, Integer.toString((int) Math.pow(2, zoom-1)-1-tiley))
-            .replaceAll(PATTERN_NEG_Y, Integer.toString((int) Math.pow(2, zoom)-1-tiley));
-        if (rand != null) {
-            r = r.replaceAll(PATTERN_SWITCH, randomParts[rand.nextInt(randomParts.length)]);
-        }
-        return r;
+        matcher.appendTail(url);
+        return url.toString().replace(" ", "%20");
     }
 
     /**
@@ -121,8 +152,8 @@ public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTi
         Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
         while (m.find()) {
             boolean isSupportedPattern = false;
-            for (String pattern : ALL_PATTERNS) {
-                if (m.group().matches(pattern)) {
+            for (Pattern pattern : ALL_PATTERNS) {
+                if (pattern.matcher(m.group()).matches()) {
                     isSupportedPattern = true;
                     break;
                 }


=====================================
src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java
=====================================
@@ -191,6 +191,14 @@ public class TileSourceInfo {
         this.id = id;
     }
 
+    /**
+     * Sets the cookies to be sent together with request
+     * @param cookies cookies to be sent along with request to tile source
+     */
+    public final void setCookies(String cookies) {
+        this.cookies = cookies;
+    }
+
     /**
      * Determines if this imagery supports "/status" and "/dirty" mode (tile re-rendering).
      * @return <code>true</code> if it supports "/status" and "/dirty" mode (tile re-rendering)



View it on GitLab: https://salsa.debian.org/debian-gis-team/jmapviewer/commit/bf7999bc3c1a882bcdf705bd8b2da8e43b849eee

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/jmapviewer/commit/bf7999bc3c1a882bcdf705bd8b2da8e43b849eee
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20181202/2cf85c88/attachment-0001.html>


More information about the Pkg-grass-devel mailing list