Changeset 36223 in osm for applications/viewer


Ignore:
Timestamp:
2024-03-11T21:33:09+01:00 (7 months ago)
Author:
taylor.smock
Message:

Fix some lint issues in JMapViewer

This additionally updates some dependencies

Location:
applications/viewer/jmapviewer
Files:
1 added
26 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/build.xml

    r36202 r36223  
    88    <property name="java.lang.version" value="8" />
    99    <dirname property="base.dir" file="${ant.file.jmapviewer}"/>
    10     <property name="tools.dir" location="${base.dir}/tools"/>
    1110    <property name="jacoco.includes" value="org.openstreetmap.gui.jmapviewer.*" />
    1211    <property name="jacoco.inclbootstrapclasses" value="false" />
     
    1413    <!-- For Java specific stuff by version -->
    1514    <condition property="isJava9"><matches string="${ant.java.version}" pattern="(1.)?(9|1[0-9])" /></condition>
    16     <condition property="isJava10"><matches string="${ant.java.version}" pattern="(1|2)[0-9]" /></condition>
    17     <condition property="isJava11"><matches string="${ant.java.version}" pattern="1[1-9]|[2-9][0-9]" /></condition>
    18     <condition property="isJava12"><matches string="${ant.java.version}" pattern="1[2-9]|[2-9][0-9]" /></condition>
    19     <condition property="isJava13"><matches string="${ant.java.version}" pattern="1[3-9]|[2-9][0-9]" /></condition>
    20     <condition property="isJava14"><matches string="${ant.java.version}" pattern="1[4-9]|[2-9][0-9]" /></condition>
    21     <condition property="isJava16"><matches string="${ant.java.version}" pattern="1[6-9]|[2-9][0-9]" /></condition>
    22     <condition property="isJava18"><matches string="${ant.java.version}" pattern="1[8-9]|[2-9][0-9]" /></condition>
    23     <condition property="isJava19"><matches string="${ant.java.version}" pattern="19|[2-9][0-9]" /></condition>
    24     <condition property="isJava20"><matches string="${ant.java.version}" pattern="[2-9][0-9]" /></condition>
    25     <condition property="isJava21"><matches string="${ant.java.version}" pattern="2[1-9]|[3-9][0-9]" /></condition>
    26     <!-- Disable jacoco on Java 18+, see https://github.com/jacoco/jacoco/pull/1132 -->
     15    <condition property="isJava23"><matches string="${ant.java.version}" pattern="2[3-9]|[3-9][0-9]" /></condition>
     16    <!-- Disable jacoco 0.8.11 on Java 23+, see https://www.jacoco.org/jacoco/trunk/doc/changes.html for latest supported version -->
    2717    <condition property="coverageByDefault">
    2818        <not>
    29             <isset property="isJava18"/>
     19            <isset property="isJava23"/>
    3020        </not>
    3121    </condition>
  • applications/viewer/jmapviewer/ivy.xml

    r36140 r36223  
    88    </configurations>
    99    <dependencies>
    10         <!-- jacocoant->default -->
    11         <dependency conf="jacocoant->default" org="org.jacoco" name="org.jacoco.ant" rev="0.8.10">
     10        <!-- jacocoant->default - don't forget to update the Jacoco disable section in build.xml -->
     11        <dependency conf="jacocoant->default" org="org.jacoco" name="org.jacoco.ant" rev="0.8.11">
    1212            <artifact name="org.jacoco.ant" type="jar" maven:classifier="nodeps"/>
    1313        </dependency>
    1414        <!-- test->default -->
    15         <dependency conf="test->default" org="com.github.spotbugs" name="spotbugs-annotations" rev="4.7.3"/>
    16         <dependency conf="test->default" org="org.junit.platform" name="junit-platform-launcher" rev="1.10.0"/>
    17         <dependency conf="test->default" org="org.junit.platform" name="junit-platform-suite" rev="1.10.0"/>
    18         <dependency conf="test->default" org="org.junit.vintage" name="junit-vintage-engine" rev="5.10.0"/>
    19         <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-params" rev="5.10.0"/>
    20         <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-api" rev="5.10.0"/>
    21         <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.10.0"/>
    22         <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-migrationsupport" rev="5.10.0"/>
     15        <dependency conf="test->default" org="com.github.spotbugs" name="spotbugs-annotations" rev="4.8.3"/>
     16        <dependency conf="test->default" org="org.junit.platform" name="junit-platform-launcher" rev="1.10.2"/>
     17        <dependency conf="test->default" org="org.junit.platform" name="junit-platform-suite" rev="1.10.2"/>
     18        <dependency conf="test->default" org="org.junit.vintage" name="junit-vintage-engine" rev="5.10.2"/>
     19        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-params" rev="5.10.2"/>
     20        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-api" rev="5.10.2"/>
     21        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.10.2"/>
     22        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-migrationsupport" rev="5.10.2"/>
    2323        <!-- checkstyle->default -->
    2424        <dependency org="com.puppycrawl.tools" name="checkstyle" rev="9.3" conf="checkstyle->default"/>
    2525        <!-- spotbugs->default -->
    26         <dependency org="com.github.spotbugs" name="spotbugs" rev="4.7.3" conf="spotbugs->default"/>
    27         <dependency org="com.github.spotbugs" name="spotbugs-ant" rev="4.7.3" conf="spotbugs->default"/>
     26        <dependency org="com.github.spotbugs" name="spotbugs" rev="4.8.3" conf="spotbugs->default"/>
     27        <dependency org="com.github.spotbugs" name="spotbugs-ant" rev="4.8.3" conf="spotbugs->default"/>
    2828    </dependencies>
    2929</ivy-module>
  • applications/viewer/jmapviewer/pom.xml

    r36202 r36223  
    8484                <groupId>org.junit</groupId>
    8585                <artifactId>junit-bom</artifactId>
    86                 <version>5.10.1</version>
     86                <version>5.10.2</version>
    8787                <type>pom</type>
    8888                <scope>import</scope>
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java

    r33332 r36223  
    1919
    2020public class AttributionSupport {
     21    public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
     22    public static final Font ATTR_LINK_FONT;
    2123
    2224    private Attributed source;
     
    2527    private String attrTermsText;
    2628    private String attrTermsUrl;
    27     public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
    28     public static final Font ATTR_LINK_FONT;
    2929
    3030    protected Rectangle attrTextBounds;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Coordinate.java

    r35355 r36223  
    7474    public boolean equals(Object o) {
    7575        if (this == o) return true;
    76         if (!(o instanceof Coordinate)) return false;
     76        if (o == null || !this.getClass().equals(o.getClass())) return false;
    7777        Coordinate that = (Coordinate) o;
    7878        return Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java

    r32724 r36223  
    137137                break;
    138138            default:
    139                 throw new RuntimeException("Unsupported button");
     139                throw new JMapViewerRuntimeException("Unsupported button");
    140140        }
    141141    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java

    r34766 r36223  
    55import java.awt.Cursor;
    66import java.awt.Point;
    7 import java.awt.event.ItemEvent;
    8 import java.awt.event.ItemListener;
    97import java.awt.event.MouseAdapter;
    108import java.awt.event.MouseEvent;
     
    8482                new BingAerialTileSource(),
    8583        });
    86         tileSourceSelector.addItemListener(new ItemListener() {
    87             @Override
    88             public void itemStateChanged(ItemEvent e) {
    89                 map().setTileSource((TileSource) e.getItem());
    90             }
    91         });
     84        tileSourceSelector.addItemListener(e -> map().setTileSource((TileSource) e.getItem()));
    9285        JComboBox<TileLoader> tileLoaderSelector;
    9386        tileLoaderSelector = new JComboBox<>(new TileLoader[] {new OsmTileLoader(map())});
    94         tileLoaderSelector.addItemListener(new ItemListener() {
    95             @Override
    96             public void itemStateChanged(ItemEvent e) {
    97                 map().setTileLoader((TileLoader) e.getItem());
    98             }
    99         });
     87        tileLoaderSelector.addItemListener(e -> map().setTileLoader((TileLoader) e.getItem()));
    10088        map().setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem());
    10189        panelTop.add(tileSourceSelector);
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java

    r35321 r36223  
    299299                try {
    300300                    Desktop.getDesktop().browse(new URI(url));
    301                 } catch (IOException e) {
    302                     e.printStackTrace();
    303                 } catch (URISyntaxException e) {
    304                     e.printStackTrace();
     301                } catch (IOException | URISyntaxException e) {
     302                    getLogger(FeatureAdapter.class).log(Level.SEVERE, e.getMessage(), e);
    305303                }
    306304            } else {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r35533 r36223  
    1313import java.util.Collections;
    1414import java.util.List;
     15import java.util.logging.Level;
    1516
    1617import javax.swing.ImageIcon;
     
    137138        tileSource = new OsmTileSource.Mapnik();
    138139        tileController = new TileController(tileSource, tileCache, this);
    139         mapMarkerList = Collections.synchronizedList(new ArrayList<MapMarker>());
    140         mapPolygonList = Collections.synchronizedList(new ArrayList<MapPolygon>());
    141         mapRectangleList = Collections.synchronizedList(new ArrayList<MapRectangle>());
     140        mapMarkerList = Collections.synchronizedList(new ArrayList<>());
     141        mapPolygonList = Collections.synchronizedList(new ArrayList<>());
     142        mapRectangleList = Collections.synchronizedList(new ArrayList<>());
    142143        mapMarkersVisible = true;
    143144        mapRectanglesVisible = true;
     
    197198                return new ImageIcon(FeatureAdapter.readImage(url));
    198199            } catch (IOException e) {
    199                 e.printStackTrace();
     200                FeatureAdapter.getLogger(JMapViewer.class).log(Level.FINE, e.getMessage(), e);
    200201            }
    201202        }
     
    502503        else if (p != null) {
    503504            Integer radius = getLatOffset(marker.getLat(), marker.getLon(), marker.getRadius(), false);
    504             radius = radius == null ? null : p.y - radius;
     505            radius = radius == null ? null : (p.y - radius);
    505506            return radius;
    506507        } else
     
    543544    public double getMeterPerPixel() {
    544545        Point origin = new Point(5, 5);
    545         Point center = new Point(getWidth() / 2, getHeight() / 2);
    546 
    547         double pDistance = center.distance(origin);
     546        Point centerPixel = new Point(getWidth() / 2, getHeight() / 2);
     547
     548        double pDistance = centerPixel.distance(origin);
    548549
    549550        ICoordinate originCoord = getPosition(origin);
    550         ICoordinate centerCoord = getPosition(center);
     551        ICoordinate centerCoord = getPosition(centerPixel);
    551552
    552553        double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(),
     
    560561        super.paintComponent(g);
    561562
    562         int iMove = 0;
     563        int iMove;
    563564
    564565        int tilesize = tileSource.getTileSize();
     
    11011102    public void setTileSource(TileSource tileSource) {
    11021103        if (tileSource.getMaxZoom() > MAX_ZOOM)
    1103             throw new RuntimeException("Maximum zoom level too high");
     1104            throw new JMapViewerRuntimeException("Maximum zoom level too high");
    11041105        if (tileSource.getMinZoom() < MIN_ZOOM)
    1105             throw new RuntimeException("Minimum zoom level too low");
     1106            throw new JMapViewerRuntimeException("Minimum zoom level too low");
    11061107        ICoordinate position = getPosition();
    11071108        this.tileSource = tileSource;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java

    r35527 r36223  
    44import java.util.HashMap;
    55import java.util.Map;
     6import java.util.logging.Level;
    67import java.util.logging.Logger;
    78
     
    1819public class MemoryTileCache implements TileCache {
    1920
    20     protected static final Logger log = Logger.getLogger(MemoryTileCache.class.getName());
     21    private static final Logger LOGGER = Logger.getLogger(MemoryTileCache.class.getName());
     22    /**
     23     * @deprecated since 2.20 (create a class specific logger)
     24     */
     25    @Deprecated
     26    protected static final Logger log = LOGGER;
    2127
    2228    /**
     
    7985            }
    8086        } catch (NullPointerException e) {
    81             log.warning(e.getMessage());
     87            LOGGER.log(Level.WARNING, e.getMessage(), e);
    8288        }
    8389    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java

    r35190 r36223  
    5858     */
    5959    public long getMaxPixels(int aZoomlevel) {
    60         return tileSize * (1 << aZoomlevel);
     60        return tileSize * (1L << aZoomlevel);
    6161    }
    6262
     
    162162        long mp = getMaxPixels(aZoomlevel);
    163163        double y = mp * (0.5 - (log / (4.0 * Math.PI)));
    164         return Math.min(y, mp - 1);
     164        return Math.min(y, mp - 1d);
    165165    }
    166166
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r35526 r36223  
    177177                // ignore malformed Cache-Control headers
    178178                if (JMapViewer.debug) {
    179                     System.err.println(e.getMessage());
     179                    LOG.log(Level.FINE, e.getMessage(), e);
    180180                }
    181181            }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Projected.java

    r35341 r36223  
    6262        if (this == obj)
    6363            return true;
    64         if (!(obj instanceof Projected))
     64        if (obj == null || !this.getClass().equals(obj.getClass()))
    6565            return false;
    6666        final Projected other = (Projected) obj;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Style.java

    r32030 r36223  
    88
    99public class Style {
     10    private static final AlphaComposite TRANSPARENCY = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
     11    private static final AlphaComposite OPAQUE = AlphaComposite.getInstance(AlphaComposite.SRC);
     12
    1013    private Color color;
    1114    private Color backColor;
    1215    private Stroke stroke;
    1316    private Font font;
    14 
    15     private static final AlphaComposite TRANSPARENCY = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
    16     private static final AlphaComposite OPAQUE = AlphaComposite.getInstance(AlphaComposite.SRC);
    1717
    1818    public Style() {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r35527 r36223  
    1212import java.util.Objects;
    1313import java.util.concurrent.Callable;
     14import java.util.logging.Level;
    1415
    1516import javax.imageio.ImageIO;
     
    8485            return FeatureAdapter.readImage(JMapViewer.class.getResource(path));
    8586        } catch (IOException | IllegalArgumentException ex) {
    86             ex.printStackTrace();
     87            FeatureAdapter.getLogger(Tile.class).log(Level.SEVERE, ex.getMessage(), ex);
    8788            return null;
    8889        }
     
    110111            } catch (Exception e) {
    111112                // this should not happen here
    112                 throw new RuntimeException(e);
     113                throw new JMapViewerRuntimeException(e);
    113114            }
    114115        }
     
    125126         *  this way we can avoid object creation until we're sure it's needed
    126127         */
    127         final CachedCallable<BufferedImage> tmpImage = new CachedCallable<>(new Callable<BufferedImage>() {
    128             @Override
    129             public BufferedImage call() throws Exception {
    130                 return new BufferedImage(source.getTileSize(), source.getTileSize(), BufferedImage.TYPE_INT_ARGB);
    131             }
    132         });
     128        final CachedCallable<BufferedImage> tmpImage = new CachedCallable<>(() ->
     129                new BufferedImage(source.getTileSize(), source.getTileSize(), BufferedImage.TYPE_INT_ARGB));
    133130
    134131        for (int zoomDiff = 1; zoomDiff < 5; zoomDiff++) {
     
    146143                 * something to draw
    147144                 */
    148                 CachedCallable<Graphics2D> graphics = new CachedCallable<>(new Callable<Graphics2D>() {
    149                     @Override
    150                     public Graphics2D call() throws Exception {
    151                         Graphics2D g = (Graphics2D) tmpImage.call().getGraphics();
    152                         g.setTransform(AffineTransform.getScaleInstance(scale, scale));
    153                         return g;
    154                     }
     145                CachedCallable<Graphics2D> graphics = new CachedCallable<>(() -> {
     146                    Graphics2D g = (Graphics2D) tmpImage.call().getGraphics();
     147                    g.setTransform(AffineTransform.getScaleInstance(scale, scale));
     148                    return g;
    155149                });
    156150
     
    177171                final int factor = 1 << zoomDiff;
    178172                final double scale = factor;
    179                 CachedCallable<Graphics2D> graphics = new CachedCallable<>(new Callable<Graphics2D>() {
    180                     @Override
    181                     public Graphics2D call() throws Exception {
    182                         Graphics2D g = (Graphics2D) tmpImage.call().getGraphics();
    183                         AffineTransform at = new AffineTransform();
    184                         int translateX = (xtile % factor) * source.getTileSize();
    185                         int translateY = (ytile % factor) * source.getTileSize();
    186                         at.setTransform(scale, 0, 0, scale, -translateX, -translateY);
    187                         g.setTransform(at);
    188                         return g;
    189                     }
    190 
     173                CachedCallable<Graphics2D> graphics = new CachedCallable<>(() -> {
     174                    Graphics2D g = (Graphics2D) tmpImage.call().getGraphics();
     175                    AffineTransform at = new AffineTransform();
     176                    int translateX = (xtile % factor) * source.getTileSize();
     177                    int translateY = (ytile % factor) * source.getTileSize();
     178                    at.setTransform(scale, 0, 0, scale, -translateX, -translateY);
     179                    g.setTransform(at);
     180                    return g;
    191181                });
    192182
     
    341331        if (this == obj)
    342332            return true;
    343         if (obj == null || !(obj instanceof Tile))
     333        if (obj == null || !this.getClass().equals(obj.getClass()))
    344334            return false;
    345335        final Tile other = (Tile) obj;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/checkBoxTree/CheckBoxNodeEditor.java

    r32030 r36223  
    33
    44import java.awt.Component;
    5 import java.awt.event.ItemEvent;
    65import java.awt.event.ItemListener;
    76import java.awt.event.MouseAdapter;
     
    8584
    8685        // editor always selected / focused
    87         final ItemListener itemListener = new ItemListener() {
    88 
    89             @Override
    90             public void itemStateChanged(final ItemEvent itemEvent) {
    91                 if (stopCellEditing()) {
    92                     fireEditingStopped();
    93                 }
     86        final ItemListener itemListener = itemEvent -> {
     87            if (stopCellEditing()) {
     88                fireEditingStopped();
    9489            }
    9590        };
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/checkBoxTree/CheckBoxNodePanel.java

    r32030 r36223  
    3333            check.getModel().setArmed(true);
    3434        } else {
    35             check.setSelected(bool.booleanValue());
     35            check.setSelected(bool);
    3636            check.getModel().setArmed(false);
    3737        }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/events/JMVCommandEvent.java

    r32682 r36223  
    1717    }
    1818
    19     private COMMAND command;
    2019    /**
    2120     *
    2221     */
    2322    private static final long serialVersionUID = 8701544867914969620L;
     23
     24    private COMMAND command;
    2425
    2526    public JMVCommandEvent(COMMAND cmd, Object source) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/IProjected.java

    r33285 r36223  
    44/**
    55 * Projected coordinates (east / north space).
    6  *
     6 * <p>
    77 * For most projections, one unit in projected space is roughly one meter, but
    88 * can also be degrees or feet.
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r36138 r36223  
    179179                for (final int v : byteDigest) {
    180180                    int vn = (v & 0xf0) >> 4;
    181                     hexChars[j++] = (char) (vn + (vn >= 10 ? 'a' - 10 : '0'));
     181                    hexChars[j++] = (char) (vn + (vn >= 10 ? ('a' - 10) : '0'));
    182182                    vn = (v & 0xf);
    183                     hexChars[j++] = (char) (vn + (vn >= 10 ? 'a' - 10 : '0'));
     183                    hexChars[j++] = (char) (vn + (vn >= 10 ? ('a' - 10) : '0'));
    184184                }
    185185                for (String val: searchEntry.getValue()) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r36174 r36223  
    3232import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    3333import org.openstreetmap.gui.jmapviewer.JMapViewer;
     34import org.openstreetmap.gui.jmapviewer.JMapViewerRuntimeException;
    3435import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    3536import org.w3c.dom.Document;
     
    6263    /** Original Bing API key created by Potlatch2 developers in 2010 */
    6364    private static final String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU";
    64    
     65
     66    private static final Pattern PATTERN_SUBDOMAIN = Pattern.compile("\\{subdomain}");
     67    private static final Pattern PATTERN_QUADKEY = Pattern.compile("\\{quadkey}");
     68    private static final Pattern PATTERN_CULTURE = Pattern.compile("\\{culture}");
     69
    6570    private volatile Future<List<Attribution>> attributions; // volatile is required for getAttribution(), see below.
    6671    private String imageUrlTemplate;
    6772    private int imageryZoomMax = Integer.MIN_VALUE;
    6873    private String[] subdomains;
    69 
    70     private static final Pattern subdomainPattern = Pattern.compile("\\{subdomain}");
    71     private static final Pattern quadkeyPattern = Pattern.compile("\\{quadkey}");
    72     private static final Pattern culturePattern = Pattern.compile("\\{culture}");
    7374    private String brandLogoUri;
    7475    private String layer = "Aerial";
     
    108109
    109110        String url = imageUrlTemplate;
    110         url = subdomainPattern.matcher(url).replaceAll(subdomain);
    111         url = quadkeyPattern.matcher(url).replaceAll(computeQuadTree(zoom, tilex, tiley));
     111        url = PATTERN_SUBDOMAIN.matcher(url).replaceAll(subdomain);
     112        url = PATTERN_QUADKEY.matcher(url).replaceAll(computeQuadTree(zoom, tilex, tiley));
    112113
    113114        return url;
     
    289290            return attributions.get();
    290291        } catch (ExecutionException ex) {
    291             throw new RuntimeException(ex);
     292            throw new JMapViewerRuntimeException(ex);
    292293        } catch (InterruptedException ign) {
    293294            LOG.log(Level.SEVERE, "InterruptedException: {0}", ign.getMessage());
     
    319320        String noHttpTemplate = template.replace("http://ecn.{subdomain}.tiles.virtualearth.net/",
    320321                "https://ecn.{subdomain}.tiles.virtualearth.net/");
    321         this.imageUrlTemplate = culturePattern.matcher(noHttpTemplate).replaceAll(Locale.getDefault().toString());
     322        this.imageUrlTemplate = PATTERN_CULTURE.matcher(noHttpTemplate).replaceAll(Locale.getDefault().toString());
    322323    }
    323324
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java

    r34766 r36223  
    3232        @Override
    3333        public String getBaseUrl() {
    34             String url = String.format(this.baseUrl, new Object[] {SERVER[serverNum]});
     34            String url = String.format(this.baseUrl, SERVER[serverNum]);
    3535            serverNum = (serverNum + 1) % SERVER.length;
    3636            return url;
     
    5858        @Override
    5959        public String getBaseUrl() {
    60             String url = String.format(this.baseUrl, new Object[] {SERVER[serverNum]});
     60            String url = String.format(this.baseUrl, SERVER[serverNum]);
    6161            serverNum = (serverNum + 1) % SERVER.length;
    6262            return url;
     
    6565        /**
    6666         * Get the thunderforest API key.
    67          *
    68          * Needs to be registered at their web site.
     67         * <p>
     68         * Needs to be registered at their website.
    6969         * @return the API key
    7070         */
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java

    r34777 r36223  
    1414/**
    1515 * This tilesource uses different to OsmMercator projection.
    16  *
     16 * <p>
    1717 * Earth is assumed an ellipsoid in this projection, unlike
    1818 * sphere in OsmMercator, so latitude calculation differs a lot.
    19  *
     19 * <p>
    2020 * The longitude calculation is the same as in OsmMercator,
    2121 * we inherit it from AbstractTMSTileSource.
     
    2424 */
    2525public class ScanexTileSource extends TMSTileSource {
    26     private static final String DEFAULT_URL = "http://maps.kosmosnimki.ru";
     26    private static final String DEFAULT_URL = "https://maps.kosmosnimki.ru";
    2727    private static final int DEFAULT_MAXZOOM = 14;
    2828    private static final String API_KEY = "4018C5A9AECAD8868ED5DEB2E41D09F7";
     29
     30    // Latitude to Y and back calculations.
     31    private static final double RADIUS_E = 6_378_137;   /* radius of Earth at equator, m */
     32    private static final double EQUATOR = 40075016.68557849; /* equator length, m */
     33    private static final double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
    2934
    3035    private enum ScanexLayer {
     
    5055    /** IRS by default */
    5156    private ScanexLayer layer = ScanexLayer.IRS;
    52     private TemplatedTMSTileSource TemplateSource = null;
     57    private TemplatedTMSTileSource templateSource;
    5358
    5459    /** cached latitude used in {@link #tileYToLat(double, int)} */
     
    6368        String url = info.getUrl();
    6469
    65         /**
     70        /*
    6671         * The formulae in tileYToLat() and latToTileY() have 2^8
    6772         * hardcoded in them, so explicitly state that.  For now
    68          * the assignment matches OsmMercator.DEFAUL_TILE_SIZE, and
     73         * the assignment matches OsmMercator.DEFAULT_TILE_SIZE, and
    6974         * thus is extraneous.  But let it be there just in case if
    7075         * OsmMercator changes.
     
    8287            }
    8388        }
    84         /** If not "irs" or "spot" keyword, then a custom URL. */
     89        /* If not "irs" or "spot" keyword, then a custom URL. */
    8590        TemplatedTMSTileSource.checkUrl(info.getUrl());
    86         this.TemplateSource = new TemplatedTMSTileSource(info);
     91        this.templateSource = new TemplatedTMSTileSource(info);
    8792    }
    8893
     
    9499   @Override
    95100    public String getTileUrl(int zoom, int tilex, int tiley) {
    96         if (this.TemplateSource != null)
    97             return this.TemplateSource.getTileUrl(zoom, tilex, tiley);
     101        if (this.templateSource != null)
     102            return this.templateSource.getTileUrl(zoom, tilex, tiley);
    98103        else
    99104            return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
     
    102107    @Override
    103108    public String getTilePath(int zoom, int tilex, int tiley) {
    104         int tmp = (int) Math.pow(2.0, zoom - 1);
     109        int tmp = (int) Math.pow(2.0, zoom - 1d);
    105110
    106111        tilex = tilex - tmp;
     
    109114        return this.layer.getUri() + "&apikey=" + API_KEY + "&x=" + tilex + "&y=" + tiley + "&z=" + zoom;
    110115    }
    111 
    112     // Latitude to Y and back calculations.
    113     private static final double RADIUS_E = 6378137;   /* radius of Earth at equator, m */
    114     private static final double EQUATOR = 40075016.68557849; /* equator length, m */
    115     private static final double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
    116116
    117117    @Override
     
    143143        return new Coordinate(
    144144                tileYToLat(y, zoom),
    145                 osmMercator.xToLon(x * getTileSize(), zoom)
     145                osmMercator.xToLon((long) x * getTileSize(), zoom)
    146146                );
    147147    }
    148148
    149     private double latToTileY(double lat, int zoom) {
     149    private static double latToTileY(double lat, int zoom) {
    150150        double tmp = Math.tan(Math.PI/4 * (1 + lat/90));
    151151        double pow = Math.pow(Math.tan(Math.PI/4 + Math.asin(E * Math.sin(Math.toRadians(lat)))/2), E);
     
    183183        double cosl = Math.cos(lat);
    184184
    185         zoom = (int) Math.pow(2.0, zoom - 1);
     185        zoom = (int) Math.pow(2.0, zoom - 1d);
    186186        double ec = Math.exp((1 - y/zoom)*Math.PI);
    187187
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

    r33313 r36223  
    7575    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
    7676        return new Coordinate(
    77                 osmMercator.yToLat(y * getTileSize(), zoom),
    78                 osmMercator.xToLon(x * getTileSize(), zoom)
     77                osmMercator.yToLat((long) y * getTileSize(), zoom),
     78                osmMercator.xToLon((long) x * getTileSize(), zoom)
    7979                );
    8080    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

    r35918 r36223  
    1717 * Handles templated TMS Tile Source. Templated means, that some patterns within
    1818 * URL gets substituted.
    19  *
     19 * <p>
    2020 * Supported parameters
    21  * {zoom} - substituted with zoom level
    22  * {z} - as above
    23  * {NUMBER-zoom} - substituted with result of equation "NUMBER - zoom",
    24  *                  eg. {20-zoom} for zoom level 15 will result in 5 in this place
    25  * {zoom+number} - substituted with result of equation "zoom + number",
    26  *                 eg. {zoom+5} for zoom level 15 will result in 20.
    27  * {x} - substituted with X tile number
    28  * {y} - substituted with Y tile number
    29  * {!y} - substituted with Yahoo Y tile number
    30  * {-y} - substituted with reversed Y tile number
    31  * {apikey} - substituted with API key retrieved for the imagery id
    32  * {switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually
    33  *                                  used to specify many tile servers
    34  * {header:(HEADER_NAME,HEADER_VALUE)} - sets the headers to be sent to tile server
     21 * <ul>
     22 * <li>{zoom} - substituted with zoom level</li>
     23 * <li>{z} - as above</li>
     24 * <li>{NUMBER-zoom} - substituted with result of equation "NUMBER - zoom",
     25 *                  eg. {20-zoom} for zoom level 15 will result in 5 in this place</li>
     26 * <li>{zoom+number} - substituted with result of equation "zoom + number",
     27 *                 eg. {zoom+5} for zoom level 15 will result in 20.</li>
     28 * <li>{x} - substituted with X tile number</li>
     29 * <li>{y} - substituted with Y tile number</li>
     30 * <li>{!y} - substituted with Yahoo Y tile number</li>
     31 * <li>{-y} - substituted with reversed Y tile number</li>
     32 * <li>{apikey} - substituted with API key retrieved for the imagery id</li>
     33 * <li>{switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually
     34 *                                  used to specify many tile servers</li>
     35 * <li>{header:(HEADER_NAME,HEADER_VALUE)} - sets the headers to be sent to tile server</li>
     36 * </ul>
    3537 */
    3638public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTileSource {
     39
     40    // CHECKSTYLE.OFF: SingleSpaceSeparator
     41    private static final String COOKIE_HEADER   = "Cookie";
     42    private static final Pattern PATTERN_ZOOM    = Pattern.compile("\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?}");
     43    private static final Pattern PATTERN_X       = Pattern.compile("\\{x}");
     44    private static final Pattern PATTERN_Y       = Pattern.compile("\\{y}");
     45    private static final Pattern PATTERN_Y_YAHOO = Pattern.compile("\\{!y}");
     46    private static final Pattern PATTERN_NEG_Y   = Pattern.compile("\\{-y}");
     47    private static final Pattern PATTERN_SWITCH  = Pattern.compile("\\{switch:([^}]+)}");
     48    private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)}");
     49    private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey}");
     50    private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))}");
     51
     52    // CHECKSTYLE.ON: SingleSpaceSeparator
     53
     54    private static final Pattern[] ALL_PATTERNS = {
     55            PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, PATTERN_SWITCH, PATTERN_API_KEY
     56    };
    3757
    3858    private Random rand;
    3959    private String[] randomParts;
    4060    private final Map<String, String> headers = new HashMap<>();
    41     private boolean inverse_zoom = false;
    42     private int zoom_offset = 0;
    43 
    44     // CHECKSTYLE.OFF: SingleSpaceSeparator
    45     private static final String COOKIE_HEADER   = "Cookie";
    46     private static final Pattern PATTERN_ZOOM    = Pattern.compile("\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}");
    47     private static final Pattern PATTERN_X       = Pattern.compile("\\{x\\}");
    48     private static final Pattern PATTERN_Y       = Pattern.compile("\\{y\\}");
    49     private static final Pattern PATTERN_Y_YAHOO = Pattern.compile("\\{!y\\}");
    50     private static final Pattern PATTERN_NEG_Y   = Pattern.compile("\\{-y\\}");
    51     private static final Pattern PATTERN_SWITCH  = Pattern.compile("\\{switch:([^}]+)\\}");
    52     private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
    53     private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey\\}");
    54     private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))\\}");
    55 
    56     // CHECKSTYLE.ON: SingleSpaceSeparator
    57 
    58     private static final Pattern[] ALL_PATTERNS = {
    59         PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, PATTERN_SWITCH, PATTERN_API_KEY
    60     };
     61    private boolean inverse_zoom;
     62    private int zoom_offset;
    6163
    6264    /**
     
    137139            case "z": // PATTERN_ZOOM
    138140            case "zoom":
    139                 replacement = Integer.toString((inverse_zoom ? -1 * zoom : zoom) + zoom_offset);
     141                replacement = Integer.toString((inverse_zoom ? -zoom : zoom) + zoom_offset);
    140142                break;
    141143            case "x": // PATTERN_X
     
    146148                break;
    147149            case "!y": // PATTERN_Y_YAHOO
    148                 replacement = Integer.toString((int) Math.pow(2, zoom-1)-1-tiley);
     150                replacement = Integer.toString((int) Math.pow(2, zoom - 1d) - 1 - tiley);
    149151                break;
    150152            case "-y": // PATTERN_NEG_Y
     
    157159                // handle switch/zoom here, as group will contain parameters and switch will not work
    158160                if (PATTERN_ZOOM.matcher("{" + matcher.group(1) + "}").matches()) {
    159                     replacement = Integer.toString((inverse_zoom ? -1 * zoom : zoom) + zoom_offset);
     161                    replacement = Integer.toString((inverse_zoom ? -zoom : zoom) + zoom_offset);
    160162                } else if (PATTERN_SWITCH.matcher("{" + matcher.group(1) + "}").matches()) {
    161163                    replacement = getRandomPart(randomParts);
     
    180182    public static void checkUrl(String url) {
    181183        assert url != null && !"".equals(url) : "URL cannot be null or empty";
    182         Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
     184        Matcher m = Pattern.compile("\\{[^}]*}").matcher(url);
    183185        while (m.find()) {
    184186            boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> pattern.matcher(m.group()).matches());
  • applications/viewer/jmapviewer/test/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSourceTest.java

    r36140 r36223  
    88import java.util.Arrays;
    99import java.util.Collection;
     10import java.util.Collections;
    1011import java.util.function.Predicate;
    1112import java.util.stream.Stream;
     
    1415
    1516/**
    16  * Tests for TemplaedTMSTileSource
     17 * Tests for TemplatedTMSTileSource
    1718 */
    1819public class TemplatedTMSTileSourceTest {
    1920
    20     private static final Collection<String> TMS_IMAGERIES = Arrays.asList(new String[]{
    21             "http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z={zoom}&x={x}&y={-y}",
     21    private static final Collection<String> TMS_IMAGERIES = Collections.singleton("http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z={zoom}&x={x}&y={-y}"
    2222            /*
    2323             *  generate for example with:
     
    2525             *    xmlstarlet sel -N 'josm=http://josm.openstreetmap.de/maps-1.0' -t -v "//josm:entry[josm:type='tms']/josm:url" -n  | \
    2626             *    sed -e 's/\&amp;/\&/g' -e 's/^/"/' -e 's/$/",/'
    27              */
    28     });
     27             */);
    2928
    3029    /**
Note: See TracChangeset for help on using the changeset viewer.