Changeset 10391 in josm


Ignore:
Timestamp:
2016-06-15T20:30:09+02:00 (5 years ago)
Author:
wiktorn
Message:

Fixes for LayerManager.

  • LayerManager: invoke hookupMapView at the end of addLayer so layer's initialization code depending on presence of MapView will be executed
  • Main: moved creation of mapFrame from addLayer(...) to anonymous LayerManager listener, so hookupMapView can depend on the fact, that mapFrame exists
  • AbstractTileSourceLayer: forced generation of the event for this layer, so MouseAdapter listeners will be properly registered

Closes: #12964, #12965

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r10387 r10391  
    8888import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    8989import org.openstreetmap.josm.gui.layer.Layer;
     90import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     91import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     92import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     93import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    9094import org.openstreetmap.josm.gui.layer.MainLayerManager;
    9195import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    563567    public Main() {
    564568        main = this;
     569        getLayerManager().addLayerChangeListener(new LayerChangeListener() {
     570            @Override
     571            public void layerAdded(LayerAddEvent e) {
     572                if (map == null) {
     573                    Layer layer = e.getAddedLayer();
     574                    ProjectionBounds viewProjectionBounds = layer.getViewProjectionBounds();
     575                    Main.main.createMapFrame(layer, viewProjectionBounds == null ? null : new ViewportData(viewProjectionBounds));
     576                }
     577            }
     578
     579            @Override
     580            public void layerRemoving(LayerRemoveEvent e) {
     581                // empty
     582            }
     583
     584            @Override
     585            public void layerOrderChanged(LayerOrderChangeEvent e) {
     586                //empty
     587            }
     588
     589        });
    565590    }
    566591
     
    794819     */
    795820    public final synchronized void addLayer(final Layer layer, ViewportData viewport) {
    796         boolean noMap = map == null;
    797         if (noMap) {
    798             createMapFrame(layer, viewport);
    799         }
    800         layer.hookUpMapView();
    801821        getLayerManager().addLayer(layer);
    802         if (noMap) {
     822        if (map != null) {
    803823            Main.map.setVisible(true);
    804824        } else if (viewport != null) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r10378 r10391  
    651651                }
    652652            }
    653         });
     653        }, true);
    654654        // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not
    655655        // start loading.
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java

    r10313 r10391  
    149149        insertLayerAt(layer, position);
    150150        fireLayerAdded(layer);
     151        layer.hookUpMapView(); // needs to be after fireLayerAdded
    151152    }
    152153
Note: See TracChangeset for help on using the changeset viewer.