Changeset 12119 in josm


Ignore:
Timestamp:
2017-05-11T10:57:14+02:00 (6 months ago)
Author:
michael2402
Message:

Fix weak projection listener of NavigatableComponent being lost.

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

Legend:

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

    r12011 r12119  
    10781078        if ((newValue == null ^ oldValue == null)
    10791079                || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
    1080             if (Main.map != null) {
    1081                 // This needs to be called first
    1082                 Main.map.mapView.fixProjection();
    1083             }
    10841080            synchronized (Main.class) {
    10851081                Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
     
    11031099    /**
    11041100     * Register a projection change listener.
     1101     * The listener is registered to be weak, so keep a reference of it if you want it to be preserved.
    11051102     *
    11061103     * @param listener the listener. Ignored if <code>null</code>.
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r12074 r12119  
    5252import org.openstreetmap.josm.data.preferences.IntegerProperty;
    5353import org.openstreetmap.josm.data.projection.Projection;
     54import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    5455import org.openstreetmap.josm.data.projection.Projections;
    5556import org.openstreetmap.josm.gui.help.Helpful;
     
    171172
    172173    /**
     174     * Main uses weak link to store this, so we need to keep a reference.
     175     */
     176    private final ProjectionChangeListener projectionChangeListener = (oldValue, newValue) -> fixProjection();
     177
     178    /**
    173179     * Constructs a new {@code NavigatableComponent}.
    174180     */
     
    176182        setLayout(null);
    177183        state = MapViewState.createDefaultState(getWidth(), getHeight());
    178         // uses weak link.
    179         Main.addProjectionChangeListener((oldValue, newValue) -> fixProjection());
     184        Main.addProjectionChangeListener(projectionChangeListener);
    180185    }
    181186
Note: See TracChangeset for help on using the changeset viewer.