Changeset 9619 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2008-08-10T18:06:29+02:00 (16 years ago)
Author:
stotz
Message:

Usage of TileLoader completely changed

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

Legend:

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

    r9494 r9619  
    4343         * Vectors for clock-wise tile painting
    4444         */
    45         protected static final Point[] move =
    46                         { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1) };
     45        protected static final Point[] move = { new Point(1, 0), new Point(0, 1),
     46                        new Point(-1, 0), new Point(0, -1) };
    4747
    4848        public static final int MAX_ZOOM = 18;
     
    102102                setPreferredSize(new Dimension(400, 400));
    103103                try {
    104                         loadingImage =
    105                                         ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png"));
     104                        loadingImage = ImageIO.read(JMapViewer.class
     105                                        .getResourceAsStream("images/hourglass.png"));
    106106                } catch (Exception e1) {
    107107                        loadingImage = null;
     
    123123                int size = 18;
    124124                try {
    125                         ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png"));
     125                        ImageIcon icon = new ImageIcon(getClass().getResource(
     126                                        "images/plus.png"));
    126127                        zoomInButton = new JButton(icon);
    127128                } catch (Exception e) {
     
    139140                add(zoomInButton);
    140141                try {
    141                         ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png"));
     142                        ImageIcon icon = new ImageIcon(getClass().getResource(
     143                                        "images/minus.png"));
    142144                        zoomOutButton = new JButton(icon);
    143145                } catch (Exception e) {
     
    168170         */
    169171        public void setDisplayPositionByLatLon(double lat, double lon, int zoom) {
    170                 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), lat, lon, zoom);
     172                setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2),
     173                                lat, lon, zoom);
    171174        }
    172175
     
    186189         *            {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM}
    187190         */
    188         public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) {
     191        public void setDisplayPositionByLatLon(Point mapPoint, double lat,
     192                        double lon, int zoom) {
    189193                int x = OsmMercator.LonToX(lon, zoom);
    190194                int y = OsmMercator.LatToY(lat, zoom);
     
    193197
    194198        public void setDisplayPosition(int x, int y, int zoom) {
    195                 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom);
     199                setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y,
     200                                zoom);
    196201        }
    197202
     
    329334                                        x++;
    330335                                for (int z = 0; z < x; z++) {
    331                                         if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { // tile
     336                                        if (x_min <= posx && posx <= x_max && y_min <= posy
     337                                                        && posy <= y_max) { // tile
    332338                                                // is
    333339                                                // visible
     
    444450                }
    445451                if (!tile.isLoaded()) {
    446                         tileLoader.addLoadRequest(tilex, tiley, zoom);
     452                        jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley,
     453                                        zoom));
    447454                }
    448455                return tile;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java

    r9618 r9619  
    1414import java.net.URLConnection;
    1515
     16import org.openstreetmap.gui.jmapviewer.interfaces.Job;
    1617import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
    1718import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
     
    5657        }
    5758
    58         public void addLoadRequest(final int tilex, final int tiley, final int zoom) {
    59                 map.jobDispatcher.addJob(new FileLoadJob(tilex, tiley, zoom));
    60         }
    61 
    62         protected class FileLoadJob implements Runnable {
     59        public Job createTileLoaderJob(final int tilex, final int tiley, final int zoom) {
     60                return new FileLoadJob(tilex, tiley, zoom);
     61        }
     62
     63        protected class FileLoadJob implements Job {
    6364                InputStream input = null;
    6465
     
    210211                        }
    211212                }
     213
     214                public void stop() {
     215                }
    212216        }
    213217
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r9618 r9619  
    3535        }
    3636
    37         public void addLoadRequest(final int tilex, final int tiley, final int zoom) {
    38                 map.jobDispatcher.addJob(new Job() {
     37        public Job createTileLoaderJob(final int tilex, final int tiley,
     38                        final int zoom) {
     39                return new Job() {
    3940
    4041                        InputStream input = null;
     
    7778                                }
    7879                        }
    79                 });
     80                };
    8081        }
    8182
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoader.java

    r9494 r9619  
    55/**
    66 * Interface for implementing a tile loader. Tiles are usually loaded via HTTP
    7  * or from a file. The {@link TileLoader} implementation is responsible for
    8  * performing the loading action asynchronously by creating a new
    9  * {@link Runnable} or {@link Job}.
     7 * or from a file.
    108 *
    119 * @author Jan Peter Stotz
     
    1412
    1513        /**
    16          * A typical {@link #addLoadRequest(int, int, int)} implementation should
    17          * create a new {@link Job} instance that performs the load action. This
    18          * {@link Job} instance is then handed over to
    19          * <code>map.jobDispatcher</code>.
     14         * A typical {@link #createTileLoaderJob(int, int, int)} implementation
     15         * should create and return a new {@link Job} instance that performs the
     16         * load action.
    2017         *
    2118         * @param tilex
    2219         * @param tiley
    2320         * @param zoom
     21         * @returns {@link Job} implementation that performs the desired load
     22         *          action.
    2423         */
    25         public void addLoadRequest(int tilex, int tiley, int zoom);
     24        public Job createTileLoaderJob(int tilex, int tiley, int zoom);
    2625}
Note: See TracChangeset for help on using the changeset viewer.