Ignore:
Timestamp:
2012-08-04T16:33:49+02:00 (12 years ago)
Author:
bastiK
Message:

add session support for imagery layers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r5389 r5391  
    121121    protected boolean settingsChanged;
    122122    protected ImageryInfo info;
    123     protected final MapView mv;
     123    protected MapView mv;
    124124    public WmsCache cache;
    125125    private AttributionSupport attribution = new AttributionSupport();
     
    160160        super(info);
    161161        imageSize = PROP_IMAGE_SIZE.get();
    162         mv = Main.map.mapView;
    163162        setBackgroundLayer(true); /* set global background variable */
    164163        initializeImages();
     164        this.info = new ImageryInfo(info);
     165
     166        attribution.initialize(this.info);
     167
     168        if(info.getUrl() != null) {
     169            startGrabberThreads();
     170        }
     171       
     172        Main.pref.addPreferenceChangeListener(this);
     173    }
     174
     175    @Override
     176    public void hookUpMapView() {
     177        mv = Main.map.mapView;
    165178        if (info.getUrl() != null) {
    166179            for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) {
     
    175188            }
    176189        }
    177         this.info = new ImageryInfo(info);
    178190        if(this.info.getPixelPerDegree() == 0.0) {
    179191            this.info.setPixelPerDegree(getPPD());
     
    181193        resolution = mv.getDist100PixelText();
    182194
    183         attribution.initialize(this.info);
    184 
    185         if(info.getUrl() != null) {
    186             startGrabberThreads();
    187         }
    188 
    189 
    190         Main.pref.addPreferenceChangeListener(this);
    191 
    192         SwingUtilities.invokeLater(new Runnable() {
     195        final MouseAdapter adapter = new MouseAdapter() {
    193196            @Override
    194             public void run() {
    195                 final MouseAdapter adapter = new MouseAdapter() {
    196                     @Override
    197                     public void mouseClicked(MouseEvent e) {
    198                         if (!isVisible()) return;
    199                         if (e.getButton() == MouseEvent.BUTTON1) {
    200                             attribution.handleAttribution(e.getPoint(), true);
    201                         }
    202                     }
    203                 };
    204                 Main.map.mapView.addMouseListener(adapter);
    205 
    206                 MapView.addLayerChangeListener(new LayerChangeListener() {
    207                     @Override
    208                     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    209                         //
    210                     }
    211 
    212                     @Override
    213                     public void layerAdded(Layer newLayer) {
    214                         //
    215                     }
    216 
    217                     @Override
    218                     public void layerRemoved(Layer oldLayer) {
    219                         if (oldLayer == WMSLayer.this) {
    220                             Main.map.mapView.removeMouseListener(adapter);
    221                             MapView.removeLayerChangeListener(this);
    222                         }
    223                     }
    224                 });
     197            public void mouseClicked(MouseEvent e) {
     198                if (!isVisible()) return;
     199                if (e.getButton() == MouseEvent.BUTTON1) {
     200                    attribution.handleAttribution(e.getPoint(), true);
     201                }
     202            }
     203        };
     204        Main.map.mapView.addMouseListener(adapter);
     205
     206        MapView.addLayerChangeListener(new LayerChangeListener() {
     207            @Override
     208            public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     209                //
     210            }
     211
     212            @Override
     213            public void layerAdded(Layer newLayer) {
     214                //
     215            }
     216
     217            @Override
     218            public void layerRemoved(Layer oldLayer) {
     219                if (oldLayer == WMSLayer.this) {
     220                    Main.map.mapView.removeMouseListener(adapter);
     221                    MapView.removeLayerChangeListener(this);
     222                }
    225223            }
    226224        });
Note: See TracChangeset for help on using the changeset viewer.