Changeset 12196 in josm for trunk/src/org


Ignore:
Timestamp:
2017-05-16T21:25:34+02:00 (8 years ago)
Author:
michael2402
Message:

Remove listeners from parent preference if they were added to both cild and parent.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java

    r12181 r12196  
    77import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    88import org.openstreetmap.josm.tools.ListenableWeakReference;
     9import org.openstreetmap.josm.tools.bugreport.BugReport;
    910
    1011/**
     
    238239     */
    239240    public void addListener(ValueChangeListener<? super T> listener) {
    240         addListenerImpl(new PreferenceChangedListenerAdapter(listener));
     241        try {
     242            addListenerImpl(new PreferenceChangedListenerAdapter(listener));
     243        } catch (RuntimeException e) {
     244            throw BugReport.intercept(e).put("listener", listener).put("preference", key);
     245        }
    241246    }
    242247
     
    251256     */
    252257    public void addWeakListener(ValueChangeListener<? super T> listener) {
    253         ValueChangeListener<T> weakListener = new WeakPreferenceAdapter(listener);
    254         PreferenceChangedListenerAdapter adapter = new PreferenceChangedListenerAdapter(weakListener);
    255         addListenerImpl(adapter);
     258        try {
     259            ValueChangeListener<T> weakListener = new WeakPreferenceAdapter(listener);
     260            PreferenceChangedListenerAdapter adapter = new PreferenceChangedListenerAdapter(weakListener);
     261            addListenerImpl(adapter);
     262        } catch (RuntimeException e) {
     263            throw BugReport.intercept(e).put("listener", listener).put("preference", key);
     264        }
    256265    }
    257266
     
    281290     */
    282291    public void removeListener(ValueChangeListener<? super T> listener) {
    283         removeListenerImpl(new PreferenceChangedListenerAdapter(listener));
     292        try {
     293            removeListenerImpl(new PreferenceChangedListenerAdapter(listener));
     294        } catch (RuntimeException e) {
     295            throw BugReport.intercept(e).put("listener", listener).put("preference", key);
     296        }
    284297    }
    285298
  • trunk/src/org/openstreetmap/josm/data/preferences/AbstractToStringProperty.java

    r12181 r12196  
    5757            super.addListenerImpl(adapter);
    5858            parent.addListenerImpl(adapter);
     59        }
     60
     61        @Override
     62        protected void removeListenerImpl(PreferenceChangedListener adapter) {
     63            super.removeListenerImpl(adapter);
     64            parent.removeListenerImpl(adapter);
    5965        }
    6066
Note: See TracChangeset for help on using the changeset viewer.