Ignore:
Timestamp:
2016-06-30T23:56:10+02:00 (8 years ago)
Author:
donvip
Message:

remove calls to deprecated methods

Location:
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersAddLayerAction.java

    r30738 r32476  
    8585
    8686        WalkingPapersLayer wpl = new WalkingPapersLayer(mungedWpId, tile, b, minz, maxz);
    87         Main.main.addLayer(wpl);
    88 
     87        Main.getLayerManager().addLayer(wpl);
    8988    }
    9089
  • applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersLayer.java

    r31114 r32476  
    2121import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2222import org.openstreetmap.josm.gui.MapView;
    23 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2423import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    2524import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    2625import org.openstreetmap.josm.gui.layer.Layer;
     26import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     27import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     28import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     29import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     30import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     31import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2732import org.openstreetmap.josm.tools.ImageProvider;
    2833
     
    6772        clearTileStorage();
    6873
    69         MapView.addLayerChangeListener(new LayerChangeListener() {
    70             public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    71                 // if user changes to a walking papers layer, zoom there just as if
    72                 // it was newly added
    73                 layerAdded(newLayer);
    74             }
    75 
    76             public void layerAdded(Layer newLayer) {
    77                 // only do something if we are affected
    78                 if (newLayer != WalkingPapersLayer.this) return;
    79                 BoundingXYVisitor bbox = new BoundingXYVisitor();
    80                 bbox.visit(printBounds);
    81                 Main.map.mapView.zoomTo(bbox);
    82                 needRedraw = true;
    83             }
    84 
    85             public void layerRemoved(Layer oldLayer) {
    86                 if (oldLayer == WalkingPapersLayer.this) {
    87                     MapView.removeLayerChangeListener(this);
     74        final ActiveLayerChangeListener activeListener = new ActiveLayerChangeListener() {
     75            @Override
     76            public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     77                // if user changes to a walking papers layer, zoom there just as if it was newly added
     78                handleNewLayer(Main.getLayerManager().getActiveLayer());
     79            }
     80        };
     81
     82        Main.getLayerManager().addActiveLayerChangeListener(activeListener);
     83        Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
     84
     85            @Override
     86            public void layerAdded(LayerAddEvent e) {
     87                handleNewLayer(e.getAddedLayer());
     88            }
     89
     90            @Override
     91            public void layerRemoving(LayerRemoveEvent e) {
     92                if (e.getRemovedLayer() == WalkingPapersLayer.this) {
     93                    Main.getLayerManager().removeLayerChangeListener(this);
     94                    Main.getLayerManager().removeActiveLayerChangeListener(activeListener);
    8895                }
    8996            }
     97
     98            @Override
     99            public void layerOrderChanged(LayerOrderChangeEvent e) {
     100            }
    90101        });
     102    }
     103
     104    private void handleNewLayer(Layer newLayer) {
     105        // only do something if we are affected
     106        if (newLayer != WalkingPapersLayer.this) return;
     107        BoundingXYVisitor bbox = new BoundingXYVisitor();
     108        bbox.visit(printBounds);
     109        Main.map.mapView.zoomTo(bbox);
     110        needRedraw = true;
    91111    }
    92112
     
    117137
    118138    static class TileTimeComp implements Comparator<WalkingPapersTile> {
     139        @Override
    119140        public int compare(WalkingPapersTile s1, WalkingPapersTile s2) {
    120141            long t1 = s1.access_time();
     
    170191        int realHeight = img.getHeight(this);
    171192        if (realWidth == -1 || realHeight == -1)
    172                 return null;
     193            return null;
    173194        int drawWidth = p1.x - p0.x;
    174195        int drawHeight = p1.x - p0.x;
     
    189210
    190211        if (botRight.lon() == 0.0 || botRight.lat() == 0) {
    191                 // probably still initializing
    192                 return;
     212            // probably still initializing
     213            return;
    193214        }
    194215        if (lastTopLeft != null && lastBotRight != null
     
    209230
    210231        if (!LatLon.isValidLat(topLeft.lat())  ||
    211             !LatLon.isValidLat(botRight.lat()) ||
    212             !LatLon.isValidLon(topLeft.lon())  ||
    213             !LatLon.isValidLon(botRight.lon()))
     232                !LatLon.isValidLat(botRight.lat()) ||
     233                !LatLon.isValidLon(topLeft.lon())  ||
     234                !LatLon.isValidLon(botRight.lon()))
    214235            return;
    215236
     
    257278                    // check if tile is in range
    258279                    Bounds tileBounds = new Bounds(new LatLon(tileYToLat(y+1), tileXToLon(x)),
    259                         new LatLon(tileYToLat(y), tileXToLon(x+1)));
     280                            new LatLon(tileYToLat(y), tileXToLon(x+1)));
    260281                    if (!tileBounds.asRect().intersects(printBounds.asRect())) continue;
    261282                    tile = new WalkingPapersTile(x, y, currentZoomLevel, this);
     
    397418    }
    398419
     420    @Override
    399421    public boolean imageUpdate(Image img, int infoflags, int x, int y,
    400422            int width, int height) {
     
    414436    public URL formatImageUrl(int x, int y, int z) {
    415437        String urlstr = tileUrlTemplate.
    416             replace("{x}", String.valueOf(x)).
    417             replace("{y}", String.valueOf(y)).
    418             replace("{z}", String.valueOf(z));
     438                replace("{x}", String.valueOf(x)).
     439                replace("{y}", String.valueOf(y)).
     440                replace("{z}", String.valueOf(z));
    419441        try {
    420442            return new URL(urlstr);
Note: See TracChangeset for help on using the changeset viewer.