Ignore:
Timestamp:
2015-08-02T23:08:40+02:00 (9 years ago)
Author:
donvip
Message:

[jmapviewer] fix some Sonar issues

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java

    r31429 r31438  
    1111public final class FeatureAdapter {
    1212
     13    private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter();
     14    private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter();
     15    private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter();
     16
    1317    private FeatureAdapter() {
    1418        // private constructor for utility classes
    1519    }
    16    
     20
    1721    public interface BrowserAdapter {
    1822        void openLink(String url);
     
    2731        Logger getLogger(String name);
    2832    }
    29 
    30     private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter();
    31     private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter();
    32     private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter();
    3333
    3434    public static void registerBrowserAdapter(BrowserAdapter browserAdapter) {
     
    5151        return translationAdapter.tr(text, objects);
    5252    }
    53    
     53
    5454    public static Logger getLogger(String name) {
    5555        return loggingAdapter.getLogger(name);
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r31434 r31438  
    373373     */
    374374    public ICoordinate getPosition() {
    375         return tileSource.XYToLatLon(center, zoom);
     375        return tileSource.xyToLatLon(center, zoom);
    376376    }
    377377
     
    400400        int x = center.x + mapPointX - getWidth() / 2;
    401401        int y = center.y + mapPointY - getHeight() / 2;
    402         return tileSource.XYToLatLon(x, y, zoom);
     402        return tileSource.xyToLatLon(x, y, zoom);
    403403    }
    404404
     
    547547        int tilex = center.x / tilesize;
    548548        int tiley = center.y / tilesize;
    549         int off_x = (center.x % tilesize);
    550         int off_y = (center.y % tilesize);
     549        int off_x = center.x % tilesize;
     550        int off_y = center.y % tilesize;
    551551
    552552        int w2 = getWidth() / 2;
     
    599599                        if (scrollWrapEnabled) {
    600600                            // in case tilex is out of bounds, grab the tile to use for wrapping
    601                             int tilexWrap = (((tilex % gridLength) + gridLength) % gridLength);
     601                            int tilexWrap = ((tilex % gridLength) + gridLength) % gridLength;
    602602                            tile = tileController.getTile(tilexWrap, tiley, zoom);
    603603                        } else {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java

    r31435 r31438  
    2222
    2323    private static int workerThreadMaxCount = 8;
    24 
    25     private final BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<>();
    26 
    27     private JobDispatcher() {
    28         addWorkerThread().firstThread = true;
    29     }
    30 
    31     /**
    32      * @return the singelton instance of the {@link JobDispatcher}
    33      */
    34     public static JobDispatcher getInstance() {
    35         return instance;
    36     }
    3724
    3825    /**
     
    6451    private int workerThreadId = 0;
    6552
     53    private final BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<>();
     54
     55    private JobDispatcher() {
     56        addWorkerThread().firstThread = true;
     57    }
     58
     59    /**
     60     * @return the singelton instance of the {@link JobDispatcher}
     61     */
     62    public static JobDispatcher getInstance() {
     63        return instance;
     64    }
     65
    6666    /**
    6767     * Removes all jobs from the queue that are currently not being processed.
     
    7373    /**
    7474     * Function to set the maximum number of workers for tile loading.
     75     * @param workers maximum number of workers
    7576     */
    7677    public static void setMaxWorkers(int workers) {
     
    180181        }
    181182    }
    182 
    183183}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java

    r31430 r31438  
    6666
    6767    public int falseNorthing(int aZoomlevel) {
    68         return (-1 * getMaxPixels(aZoomlevel) / 2);
     68        return -1 * getMaxPixels(aZoomlevel) / 2;
    6969    }
    7070
     
    8181     */
    8282    public double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) {
    83         double la1 = YToLat(y1, zoomLevel);
    84         double lo1 = XToLon(x1, zoomLevel);
    85         double la2 = YToLat(y2, zoomLevel);
    86         double lo2 = XToLon(x2, zoomLevel);
     83        double la1 = yToLat(y1, zoomLevel);
     84        double lo1 = xToLon(x1, zoomLevel);
     85        double la2 = yToLat(y2, zoomLevel);
     86        double lo2 = xToLon(x2, zoomLevel);
    8787
    8888        return getDistance(la1, lo1, la2, lo2);
     
    108108                * Math.cos(aEndLong - aStartLong));
    109109
    110         return (EARTH_RADIUS * distance);
     110        return EARTH_RADIUS * distance;
    111111    }
    112112
     
    126126     * @param aLongitude
    127127     *            [-180..180]
     128     * @param aZoomlevel zoom level
    128129     * @return [0..2^Zoomlevel*TILE_SIZE[
    129130     */
     
    149150     * @param aLat
    150151     *            [-90...90]
     152     * @param aZoomlevel zoom level
    151153     * @return [0..2^Zoomlevel*TILE_SIZE[
    152154     */
     
    178180     * @param aX
    179181     *            [0..2^Zoomlevel*TILE_WIDTH[
     182     * @param aZoomlevel zoom level
    180183     * @return ]-180..180[
    181184     */
    182     public double XToLon(int aX, int aZoomlevel) {
     185    public double xToLon(int aX, int aZoomlevel) {
    183186        return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0;
    184187    }
     
    189192     * @param aY
    190193     *            [0..2^Zoomlevel*TILE_WIDTH[
     194     * @param aZoomlevel zoom level
    191195     * @return [MIN_LAT..MAX_LAT] is about [-85..85]
    192196     */
    193     public double YToLat(int aY, int aZoomlevel) {
     197    public double yToLat(int aY, int aZoomlevel) {
    194198        aY += falseNorthing(aZoomlevel);
    195199        double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel))));
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r31434 r31438  
    3333     */
    3434    public static final BufferedImage ERROR_IMAGE = loadImage("images/error.png");
    35 
    36     private static BufferedImage loadImage(String path) {
    37         try {
    38             return ImageIO.read(JMapViewer.class.getResourceAsStream(path));
    39         } catch (Exception ex) {
    40             ex.printStackTrace();
    41             return null;
    42         }
    43     }
    4435
    4536    protected TileSource source;
     
    8576        this.image = image;
    8677        this.key = getTileKey(source, xtile, ytile, zoom);
     78    }
     79
     80    private static BufferedImage loadImage(String path) {
     81        try {
     82            return ImageIO.read(JMapViewer.class.getResourceAsStream(path));
     83        } catch (Exception ex) {
     84            ex.printStackTrace();
     85            return null;
     86        }
    8787    }
    8888
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r31436 r31438  
    170170     * @param aZoomlevel zoom level
    171171     * @return ]-180..180[
    172      * @deprecated use {@link #XYToLatLon(int, int, int)} instead
     172     * @deprecated use {@link #xyToLatLon(int, int, int)} instead
    173173     */
    174174    @Deprecated
     
    180180     * @param aZoomlevel zoom level
    181181     * @return [MIN_LAT..MAX_LAT]
    182      * @deprecated use {@link #XYToLatLon(int, int, int)} instead
     182     * @deprecated use {@link #xyToLatLon(int, int, int)} instead
    183183     */
    184184    @Deprecated
     
    190190     * @return WGS84 Coordinates of given point
    191191     */
    192     ICoordinate XYToLatLon(Point point, int zoom);
     192    ICoordinate xyToLatLon(Point point, int zoom);
    193193
    194194    /**
     
    199199     * @return WGS84 Coordinates of given point
    200200     */
    201     ICoordinate XYToLatLon(int x, int y, int zoom);
     201    ICoordinate xyToLatLon(int x, int y, int zoom);
    202202
    203203    /**
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r31435 r31438  
    153153    @Override
    154154    public double XToLon(int x, int zoom) {
    155         return osmMercator.XToLon(x, zoom);
     155        return osmMercator.xToLon(x, zoom);
    156156    }
    157157
    158158    @Override
    159159    public double YToLat(int y, int zoom) {
    160         return osmMercator.YToLat(y, zoom);
    161     }
    162 
    163     @Override
    164     public ICoordinate XYToLatLon(Point point, int zoom) {
    165         return XYToLatLon(point.x, point.y, zoom);
    166     }
    167 
    168     @Override
    169     public ICoordinate XYToLatLon(int x, int y, int zoom) {
     160        return osmMercator.yToLat(y, zoom);
     161    }
     162
     163    @Override
     164    public ICoordinate xyToLatLon(Point point, int zoom) {
     165        return xyToLatLon(point.x, point.y, zoom);
     166    }
     167
     168    @Override
     169    public ICoordinate xyToLatLon(int x, int y, int zoom) {
    170170        return new Coordinate(
    171                 osmMercator.YToLat(y, zoom),
    172                 osmMercator.XToLon(x, zoom)
     171                osmMercator.yToLat(y, zoom),
     172                osmMercator.xToLon(x, zoom)
    173173                );
    174174    }
     
    199199    @Override
    200200    public double tileYToLat(int y, int zoom) {
    201         return osmMercator.YToLat(y * tileSize, zoom);
     201        return osmMercator.yToLat(y * tileSize, zoom);
    202202    }
    203203
    204204    @Override
    205205    public double tileXToLon(int x, int zoom) {
    206         return osmMercator.XToLon(x * tileSize, zoom);
     206        return osmMercator.xToLon(x * tileSize, zoom);
    207207    }
    208208
     
    220220    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
    221221        return new Coordinate(
    222                 osmMercator.YToLat(y * tileSize, zoom),
    223                 osmMercator.XToLon(x * tileSize, zoom)
     222                osmMercator.yToLat(y * tileSize, zoom),
     223                osmMercator.xToLon(x * tileSize, zoom)
    224224                );
    225225    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java

    r31435 r31438  
    2121    private static final int DEFAULT_MAXZOOM = 14;
    2222    private static final String API_KEY = "4018C5A9AECAD8868ED5DEB2E41D09F7";
     23
     24    // Latitude to Y and back calculations.
     25
     26    /** radius of Earth at equator, m */
     27    private static double RADIUS_E = 6378137;
     28    /** equator length, m */
     29    private static double EQUATOR = 40075016.68557849;
     30    /** eccentricity of Earth's ellipsoid */
     31    private static double E = 0.0818191908426;
    2332
    2433    private enum ScanexLayer {
     
    4655    private ScanexLayer layer = ScanexLayer.IRS;
    4756
     57    /** cached latitude used in {@link #tileYToLat(double, int)} */
     58    private double cachedLat = 0;
     59
     60    /**
     61     * Constructs a new {@code ScanexTileSource}.
     62     * @param info tile source info
     63     */
    4864    public ScanexTileSource(TileSourceInfo info) {
    4965        super(info);
     
    7793    }
    7894
    79     /*
    80      * Latitude to Y and back calculations.
    81      */
    82     private static double RADIUS_E = 6378137;   /* radius of Earth at equator, m */
    83     private static double EQUATOR = 40075016.68557849; /* equator length, m */
    84     private static double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
    85 
    8695    @Override
    8796    public int latToY(double lat, int zoom) {
     
    111120     * Newton's method. We cache previous calculated latitude,
    112121     * because new one is usually close to the old one. In case
    113      * if solution gets out of bounds, we reset to a new random
    114      * value.
     122     * if solution gets out of bounds, we reset to a new random value.
    115123     */
    116     private double cachedLat = 0;
    117124    private double tileYToLat(double y, int zoom) {
    118125        double lat0;
     
    126133                  r.nextInt((int) (OsmMercator.MAX_LAT - OsmMercator.MIN_LAT));
    127134            }
    128         } while ((Math.abs(lat0 - lat) > 0.000001));
     135        } while (Math.abs(lat0 - lat) > 0.000001);
    129136
    130137        cachedLat = lat;
     
    141148        double ec = Math.exp((1 - y/zoom)*Math.PI);
    142149
    143         double f = (Math.tan(Math.PI/4+lat/2) -
    144             ec * Math.pow(Math.tan(Math.PI/4 + Math.asin(E * sinl)/2), E));
     150        double f = Math.tan(Math.PI/4+lat/2) -
     151            ec * Math.pow(Math.tan(Math.PI/4 + Math.asin(E * sinl)/2), E);
    145152        double df = 1/(1 - sinl) - ec * E * cosl/((1 - E * sinl) *
    146153            (Math.sqrt(1 - E * E * sinl * sinl)));
Note: See TracChangeset for help on using the changeset viewer.