Changeset 30875 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2014-12-25T17:17:59+01:00 (10 years ago)
Author:
donvip
Message:

[jmapviewer] code cleanup

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

Legend:

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

    r30426 r30875  
    5858
    5959        // Listen to the map viewer for user operations so components will
    60         // recieve events and update
     60        // receive events and update
    6161        map().addJMVListener(this);
    62 
    63         // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4);
    64         // map.setTileLoader(new OsmFileCacheTileLoader(map));
    65         // new DefaultMapController(map);
    6662
    6763        setLayout(new BorderLayout());
     
    9490            }
    9591        });
    96         JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] { new OsmTileSource.Mapnik(),
    97                 new OsmTileSource.CycleMap(), new BingAerialTileSource(), new MapQuestOsmTileSource(), new MapQuestOpenAerialTileSource() });
     92        JComboBox<TileSource> tileSourceSelector = new JComboBox<>(new TileSource[] {
     93                new OsmTileSource.Mapnik(),
     94                new OsmTileSource.CycleMap(),
     95                new BingAerialTileSource(),
     96                new MapQuestOsmTileSource(),
     97                new MapQuestOpenAerialTileSource() });
    9898        tileSourceSelector.addItemListener(new ItemListener() {
    9999            public void itemStateChanged(ItemEvent e) {
     
    149149        panelBottom.add(showTileGrid);
    150150        final JCheckBox showZoomControls = new JCheckBox("Show zoom controls");
    151         showZoomControls.setSelected(map().getZoomContolsVisible());
     151        showZoomControls.setSelected(map().getZoomControlsVisible());
    152152        showZoomControls.addActionListener(new ActionListener() {
    153153            public void actionPerformed(ActionEvent e) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r30769 r30875  
    9696     * Creates a standard {@link JMapViewer} instance that can be controlled via
    9797     * mouse: hold right mouse button for moving, double click left mouse button
    98      * or use mouse wheel for zooming. Loaded tiles are stored the
     98     * or use mouse wheel for zooming. Loaded tiles are stored in a
    9999     * {@link MemoryTileCache} and the tile loader uses 4 parallel threads for
    100100     * retrieving the tiles.
    101101     */
    102     @SuppressWarnings("unused")
    103102    public JMapViewer() {
    104103        this(new MemoryTileCache(), 8);
     
    106105    }
    107106
     107    /**
     108     * Creates a new {@link JMapViewer} instance.
     109     * @param tileCache The cache where to store tiles
     110     * @param downloadThreadCount The number of parallel threads for retrieving the tiles
     111     */
    108112    public JMapViewer(TileCache tileCache, int downloadThreadCount) {
    109         super();
    110113        JobDispatcher.setMaxWorkers(downloadThreadCount);
    111114        tileSource = new OsmTileSource.Mapnik();
     
    123126        setPreferredSize(new Dimension(400, 400));
    124127        setDisplayPosition(new Coordinate(50, 9), 3);
    125         //setToolTipText("");
    126128    }
    127129
    128130    @Override
    129131    public String getToolTipText(MouseEvent event) {
    130         //        Point screenPoint = event.getLocationOnScreen();
    131         //        Coordinate c = getPosition(screenPoint);
    132132        return super.getToolTipText(event);
    133133    }
     
    245245
    246246    /**
    247      * Sets the displayed map pane and zoom level so that all chosen map elements are
    248      * visible.
     247     * Sets the displayed map pane and zoom level so that all chosen map elements are visible.
    249248     */
    250249    public void setDisplayToFitMapElements(boolean markers, boolean rectangles, boolean polygons) {
     
    329328
    330329    /**
    331      * Sets the displayed map pane and zoom level so that all map markers are
    332      * visible.
     330     * Sets the displayed map pane and zoom level so that all map markers are visible.
    333331     */
    334332    public void setDisplayToFitMapMarkers() {
     
    337335
    338336    /**
    339      * Sets the displayed map pane and zoom level so that all map rectangles are
    340      * visible.
     337     * Sets the displayed map pane and zoom level so that all map rectangles are visible.
    341338     */
    342339    public void setDisplayToFitMapRectangles() {
     
    345342
    346343    /**
    347      * Sets the displayed map pane and zoom level so that all map polygons are
    348      * visible.
     344     * Sets the displayed map pane and zoom level so that all map polygons are visible.
    349345     */
    350346    public void setDisplayToFitMapPolygons() {
     
    798794    /**
    799795     * Increases the current zoom level by one
     796     * @param mapPoint point to choose as center for new zoom level
    800797     */
    801798    public void zoomIn(Point mapPoint) {
     
    965962    }
    966963
    967     public boolean getZoomContolsVisible() {
     964    public boolean getZoomControlsVisible() {
    968965        return zoomSlider.isVisible();
    969966    }
     
    973970            throw new RuntimeException("Maximum zoom level too high");
    974971        if (tileSource.getMinZoom() < MIN_ZOOM)
    975             throw new RuntimeException("Minumim zoom level too low");
     972            throw new RuntimeException("Minimum zoom level too low");
    976973        Coordinate position = getPosition();
    977974        this.tileSource = tileSource;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java

    r30426 r30875  
    3232    protected final CacheLinkedListElement lruTiles;
    3333
     34    /**
     35     * Constructs a new {@code MemoryTileCache}.
     36     */
    3437    public MemoryTileCache() {
    3538        hash = new HashMap<>(cacheSize);
     
    8184    }
    8285
    83     /**
    84      * Clears the cache deleting all tiles from memory
    85      */
     86    @Override
    8687    public synchronized void clear() {
    8788        hash.clear();
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r30426 r30875  
    7171                    if (input == null) {
    7272                        try {
    73                             System.err.println("Failed loading " + tile.getUrl() +": " + e.getMessage());
    74                         } catch(IOException i) {
     73                            System.err.println("Failed loading " + tile.getUrl() +": "
     74                                    +e.getClass() + ": " + e.getMessage());
     75                        } catch (IOException ioe) {
     76                            ioe.printStackTrace();
    7577                        }
    7678                    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r30426 r30875  
    2525
    2626    /**
    27      * Hourglass image that is displayed until a map tile has been loaded
     27     * Hourglass image that is displayed until a map tile has been loaded, except for overlay sources
    2828     */
    2929    public static BufferedImage LOADING_IMAGE;
     30
     31    /**
     32     * Red cross image that is displayed after a loading error, except for overlay sources
     33     */
    3034    public static BufferedImage ERROR_IMAGE;
    3135
     
    3438            LOADING_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png"));
    3539            ERROR_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/error.png"));
    36         } catch (Exception e1) {
    37             LOADING_IMAGE = null;
    38             ERROR_IMAGE = null;
     40        } catch (Exception ex) {
     41            ex.printStackTrace();
    3942        }
    4043    }
     
    5760     * Creates a tile with empty image.
    5861     *
    59      * @param source
    60      * @param xtile
    61      * @param ytile
    62      * @param zoom
     62     * @param source Tile source
     63     * @param xtile X coordinate
     64     * @param ytile Y coordinate
     65     * @param zoom Zoom level
    6366     */
    6467    public Tile(TileSource source, int xtile, int ytile, int zoom) {
    65         super();
     68        this(source, xtile, ytile, zoom, LOADING_IMAGE);
     69    }
     70
     71    /**
     72     * Creates a tile with specified image.
     73     *
     74     * @param source Tile source
     75     * @param xtile X coordinate
     76     * @param ytile Y coordinate
     77     * @param zoom Zoom level
     78     * @param image Image content
     79     */
     80    public Tile(TileSource source, int xtile, int ytile, int zoom, BufferedImage image) {
    6681        this.source = source;
    6782        this.xtile = xtile;
    6883        this.ytile = ytile;
    6984        this.zoom = zoom;
    70         this.image = LOADING_IMAGE;
     85        this.image = image;
    7186        this.key = getTileKey(source, xtile, ytile, zoom);
    72     }
    73 
    74     public Tile(TileSource source, int xtile, int ytile, int zoom, BufferedImage image) {
    75         this(source, xtile, ytile, zoom);
    76         this.image = image;
    7787    }
    7888
     
    138148
    139149    /**
     150     * Returns the X coordinate.
    140151     * @return tile number on the x axis of this tile
    141152     */
     
    145156
    146157    /**
     158     * Returns the Y coordinate.
    147159     * @return tile number on the y axis of this tile
    148160     */
     
    152164
    153165    /**
     166     * Returns the zoom level.
    154167     * @return zoom level of this tile
    155168     */
     
    197210     * position <code>x</code>/<code>y</code>.
    198211     *
    199      * @param g
    200      * @param x
    201      *            x-coordinate in <code>g</code>
    202      * @param y
    203      *            y-coordinate in <code>g</code>
     212     * @param g the Graphics object
     213     * @param x x-coordinate in <code>g</code>
     214     * @param y y-coordinate in <code>g</code>
    204215     */
    205216    public void paint(Graphics g, int x, int y) {
     
    286297     * the meta data.
    287298     *
    288      * @param key
    289      * @param value
     299     * @param key Key
     300     * @param value Value
    290301     */
    291302    public void putValue(String key, String value) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileController.java

    r30223 r30875  
    77import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
    88import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    9 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;
    109
    1110public class TileController {
     
    1716
    1817    public TileController(TileSource source, TileCache tileCache, TileLoaderListener listener) {
    19         tileSource = new OsmTileSource.Mapnik();
    20         tileLoader = new OsmTileLoader(listener);
     18        this.tileSource = source;
     19        this.tileLoader = new OsmTileLoader(listener);
    2120        this.tileCache = tileCache;
    22         jobDispatcher = JobDispatcher.getInstance();
     21        this.jobDispatcher = JobDispatcher.getInstance();
    2322    }
    2423
     
    8180
    8281    /**
    83      *
     82     * Removes all jobs from the queue that are currently not being processed.
    8483     */
    8584    public void cancelOutstandingJobs() {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileCache.java

    r30223 r30875  
    4343     */
    4444    public int getTileCount();
     45
     46    /**
     47     * Clears the cache deleting all tiles from memory.
     48     */
     49    public void clear();
    4550}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoaderListener.java

    r30223 r30875  
    1010     * Loaded can mean downloaded or loaded from file cache.
    1111     *
    12      * @param tile
     12     * @param tile The tile
     13     * @param success {@code true} if the tile has been loaded successfully, {@code false} otherwise
    1314     */
    1415    public void tileLoadingFinished(Tile tile, boolean success);
    15 
    16     /**
    17      * Return the {@link TileCache} class containing {@link Tile}
    18      * data for requested and loaded tiles
    19      *
    20      * @return tile information caching class
    21      */
    22     public TileCache getTileCache();
    2316}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java

    r30854 r30875  
    5757         */
    5858        public CycleMap() {
    59             super("Cyclemap", PATTERN, "opencylemap");
     59            super("Cyclemap", PATTERN, "opencyclemap");
    6060        }
    6161
Note: See TracChangeset for help on using the changeset viewer.