Ignore:
Timestamp:
2017-09-21T12:41:32+02:00 (2 years ago)
Author:
bastiK
Message:

see #15229 - move remaining classes to spi.preferences package, to make it self-contained

  • extract event listener classes from Preferences (duplicated, for smooth transition)
  • move *Setting classes
Location:
trunk/src/org/openstreetmap/josm/data
Files:
11 edited

Legend:

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

    r12865 r12881  
    4848import org.openstreetmap.josm.data.preferences.DoubleProperty;
    4949import org.openstreetmap.josm.data.preferences.IntegerProperty;
    50 import org.openstreetmap.josm.data.preferences.ListListSetting;
    51 import org.openstreetmap.josm.data.preferences.ListSetting;
     50import org.openstreetmap.josm.spi.preferences.ListListSetting;
     51import org.openstreetmap.josm.spi.preferences.ListSetting;
    5252import org.openstreetmap.josm.data.preferences.LongProperty;
    53 import org.openstreetmap.josm.data.preferences.MapListSetting;
     53import org.openstreetmap.josm.spi.preferences.MapListSetting;
    5454import org.openstreetmap.josm.data.preferences.PreferencesReader;
    5555import org.openstreetmap.josm.data.preferences.PreferencesWriter;
    56 import org.openstreetmap.josm.data.preferences.Setting;
    57 import org.openstreetmap.josm.data.preferences.StringSetting;
     56import org.openstreetmap.josm.spi.preferences.Setting;
     57import org.openstreetmap.josm.spi.preferences.StringSetting;
    5858import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
    5959import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
     
    157157    /**
    158158     * Event triggered when a preference entry value changes.
    159      */
     159     * @deprecated use {@link org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent}
     160     */
     161    @Deprecated
    160162    public interface PreferenceChangeEvent {
    161163        /**
     
    181183     * Listener to preference change events.
    182184     * @since 10600 (functional interface)
     185     * @deprecated use {@link org.openstreetmap.josm.spi.preferences.PreferenceChangedListener}
    183186     */
    184187    @FunctionalInterface
     188    @Deprecated
    185189    public interface PreferenceChangedListener {
    186190        /**
     
    191195    }
    192196
     197    @Deprecated
    193198    private static class DefaultPreferenceChangeEvent implements PreferenceChangeEvent {
    194199        private final String key;
     
    218223    }
    219224
    220     private final ListenerList<PreferenceChangedListener> listeners = ListenerList.create();
    221 
    222     private final HashMap<String, ListenerList<PreferenceChangedListener>> keyListeners = new HashMap<>();
     225    private final ListenerList<org.openstreetmap.josm.spi.preferences.PreferenceChangedListener> listeners = ListenerList.create();
     226
     227    private final HashMap<String, ListenerList<org.openstreetmap.josm.spi.preferences.PreferenceChangedListener>> keyListeners = new HashMap<>();
     228
     229    @Deprecated
     230    private final ListenerList<Preferences.PreferenceChangedListener> listenersDeprecated = ListenerList.create();
     231
     232    @Deprecated
     233    private final HashMap<String, ListenerList<Preferences.PreferenceChangedListener>> keyListenersDeprecated = new HashMap<>();
    223234
    224235    /**
     
    243254     * Adds a new preferences listener.
    244255     * @param listener The listener to add
     256     * @since xxx
    245257     */
    246258    @Override
    247     public void addPreferenceChangeListener(PreferenceChangedListener listener) {
     259    public void addPreferenceChangeListener(org.openstreetmap.josm.spi.preferences.PreferenceChangedListener listener) {
    248260        if (listener != null) {
    249261            listeners.addListener(listener);
     
    252264
    253265    /**
     266     * Adds a new preferences listener.
     267     * @param listener The listener to add
     268     * @deprecated use {@link #addPreferenceChangeListener(org.openstreetmap.josm.spi.preferences.PreferenceChangedListener)}
     269     */
     270    @Deprecated
     271    public void addPreferenceChangeListener(Preferences.PreferenceChangedListener listener) {
     272        if (listener != null) {
     273            listenersDeprecated.addListener(listener);
     274        }
     275    }
     276
     277    /**
    254278     * Removes a preferences listener.
    255279     * @param listener The listener to remove
     280     * @since xxx
    256281     */
    257282    @Override
    258     public void removePreferenceChangeListener(PreferenceChangedListener listener) {
     283    public void removePreferenceChangeListener(org.openstreetmap.josm.spi.preferences.PreferenceChangedListener listener) {
    259284        listeners.removeListener(listener);
     285    }
     286
     287    /**
     288     * Removes a preferences listener.
     289     * @param listener The listener to remove
     290     * @deprecated use {@link #removePreferenceChangeListener(org.openstreetmap.josm.spi.preferences.PreferenceChangedListener)}
     291     */
     292    @Deprecated
     293    public void removePreferenceChangeListener(Preferences.PreferenceChangedListener listener) {
     294        listenersDeprecated.removeListener(listener);
     295    }
     296
     297    /**
     298     * Adds a listener that only listens to changes in one preference
     299     * @param key The preference key to listen to
     300     * @param listener The listener to add.
     301     * @since xxx
     302     */
     303    @Override
     304    public void addKeyPreferenceChangeListener(String key, org.openstreetmap.josm.spi.preferences.PreferenceChangedListener listener) {
     305        listenersForKey(key).addListener(listener);
    260306    }
    261307
     
    265311     * @param listener The listener to add.
    266312     * @since 10824
    267      */
    268     @Override
    269     public void addKeyPreferenceChangeListener(String key, PreferenceChangedListener listener) {
    270         listenersForKey(key).addListener(listener);
     313     * @deprecated use {@link #addKeyPreferenceChangeListener(java.lang.String, org.openstreetmap.josm.spi.preferences.PreferenceChangedListener)}
     314     */
     315    @Deprecated
     316    public void addKeyPreferenceChangeListener(String key, Preferences.PreferenceChangedListener listener) {
     317        listenersForKeyDeprecated(key).addListener(listener);
    271318    }
    272319
     
    277324     * @since 10824
    278325     */
    279     public void addWeakKeyPreferenceChangeListener(String key, PreferenceChangedListener listener) {
     326    public void addWeakKeyPreferenceChangeListener(String key, org.openstreetmap.josm.spi.preferences.PreferenceChangedListener listener) {
    280327        listenersForKey(key).addWeakListener(listener);
    281328    }
    282329
    283     private ListenerList<PreferenceChangedListener> listenersForKey(String key) {
     330    private ListenerList<org.openstreetmap.josm.spi.preferences.PreferenceChangedListener> listenersForKey(String key) {
    284331        return keyListeners.computeIfAbsent(key, k -> ListenerList.create());
     332    }
     333
     334    @Deprecated
     335    private ListenerList<Preferences.PreferenceChangedListener> listenersForKeyDeprecated(String key) {
     336        return keyListenersDeprecated.computeIfAbsent(key, k -> ListenerList.create());
    285337    }
    286338
     
    289341     * @param key The preference key to listen to
    290342     * @param listener The listener to add.
     343     * @since xxx
    291344     */
    292345    @Override
    293     public void removeKeyPreferenceChangeListener(String key, PreferenceChangedListener listener) {
     346    public void removeKeyPreferenceChangeListener(String key, org.openstreetmap.josm.spi.preferences.PreferenceChangedListener listener) {
    294347        Optional.ofNullable(keyListeners.get(key)).orElseThrow(
    295348                () -> new IllegalArgumentException("There are no listeners registered for " + key))
     
    297350    }
    298351
     352    /**
     353     * Removes a listener that only listens to changes in one preference
     354     * @param key The preference key to listen to
     355     * @param listener The listener to add.
     356     * @deprecated use {@link #removeKeyPreferenceChangeListener(java.lang.String, org.openstreetmap.josm.spi.preferences.PreferenceChangedListener)}
     357     */
     358    @Deprecated
     359    public void removeKeyPreferenceChangeListener(String key, Preferences.PreferenceChangedListener listener) {
     360        Optional.ofNullable(keyListenersDeprecated.get(key)).orElseThrow(
     361                () -> new IllegalArgumentException("There are no listeners registered for " + key))
     362        .removeListener(listener);
     363    }
     364
    299365    protected void firePreferenceChanged(String key, Setting<?> oldValue, Setting<?> newValue) {
    300         final PreferenceChangeEvent evt = new DefaultPreferenceChangeEvent(key, oldValue, newValue);
     366        final org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent evt = new org.openstreetmap.josm.spi.preferences.DefaultPreferenceChangeEvent(key, oldValue, newValue);
    301367        listeners.fireEvent(listener -> listener.preferenceChanged(evt));
    302368
    303         ListenerList<PreferenceChangedListener> forKey = keyListeners.get(key);
     369        ListenerList<org.openstreetmap.josm.spi.preferences.PreferenceChangedListener> forKey = keyListeners.get(key);
    304370        if (forKey != null) {
    305371            forKey.fireEvent(listener -> listener.preferenceChanged(evt));
     372        }
     373        firePreferenceChangedDeprecated(key, oldValue, newValue);
     374    }
     375
     376    @Deprecated
     377    private void firePreferenceChangedDeprecated(String key, Setting<?> oldValue, Setting<?> newValue) {
     378        final Preferences.PreferenceChangeEvent evtDeprecated = new Preferences.DefaultPreferenceChangeEvent(key, oldValue, newValue);
     379        listenersDeprecated.fireEvent(listener -> listener.preferenceChanged(evtDeprecated));
     380
     381        ListenerList<Preferences.PreferenceChangedListener> forKeyDeprecated = keyListenersDeprecated.get(key);
     382        if (forKeyDeprecated != null) {
     383            forKeyDeprecated.fireEvent(listener -> listener.preferenceChanged(evtDeprecated));
    306384        }
    307385    }
  • trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java

    r12869 r12881  
    1818
    1919import org.openstreetmap.josm.Main;
    20 import org.openstreetmap.josm.data.preferences.ListListSetting;
    21 import org.openstreetmap.josm.data.preferences.ListSetting;
    22 import org.openstreetmap.josm.data.preferences.MapListSetting;
    23 import org.openstreetmap.josm.data.preferences.Setting;
    24 import org.openstreetmap.josm.data.preferences.StringSetting;
     20import org.openstreetmap.josm.spi.preferences.ListListSetting;
     21import org.openstreetmap.josm.spi.preferences.ListSetting;
     22import org.openstreetmap.josm.spi.preferences.MapListSetting;
     23import org.openstreetmap.josm.spi.preferences.Setting;
     24import org.openstreetmap.josm.spi.preferences.StringSetting;
    2525import org.openstreetmap.josm.tools.Logging;
    2626import org.openstreetmap.josm.tools.Utils;
  • trunk/src/org/openstreetmap/josm/data/UserIdentityManager.java

    r12846 r12881  
    77
    88import org.openstreetmap.josm.Main;
    9 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    10 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     9import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     10import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    1111import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    1212import org.openstreetmap.josm.data.osm.User;
    1313import org.openstreetmap.josm.data.osm.UserInfo;
    14 import org.openstreetmap.josm.data.preferences.StringSetting;
     14import org.openstreetmap.josm.spi.preferences.StringSetting;
    1515import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1616import org.openstreetmap.josm.io.OnlineResource;
  • trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java

    r12846 r12881  
    1212import java.util.stream.Collectors;
    1313
    14 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    15 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     14import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     15import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    1616import org.openstreetmap.josm.data.UserIdentityManager;
    1717import org.openstreetmap.josm.spi.preferences.Config;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java

    r12846 r12881  
    44import java.awt.Color;
    55
    6 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    7 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     6import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     7import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    88import org.openstreetmap.josm.spi.preferences.Config;
    99
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r12846 r12881  
    1515
    1616import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    18 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     17import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     18import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    1919import org.openstreetmap.josm.data.coor.EastNorth;
    2020import org.openstreetmap.josm.data.osm.DataSet;
  • trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java

    r12207 r12881  
    44import org.openstreetmap.josm.Main;
    55import org.openstreetmap.josm.data.Preferences;
    6 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    7 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     6import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     7import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    88import org.openstreetmap.josm.tools.ListenableWeakReference;
    99import org.openstreetmap.josm.tools.bugreport.BugReport;
  • trunk/src/org/openstreetmap/josm/data/preferences/AbstractToStringProperty.java

    r12620 r12881  
    22package org.openstreetmap.josm.data.preferences;
    33
    4 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     4import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    55import org.openstreetmap.josm.tools.CheckParameterUtil;
    66import org.openstreetmap.josm.tools.Logging;
  • trunk/src/org/openstreetmap/josm/data/preferences/CachedProperty.java

    r12867 r12881  
    22package org.openstreetmap.josm.data.preferences;
    33
    4 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    5 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     4import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     5import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    66import org.openstreetmap.josm.spi.preferences.Config;
    77
  • trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java

    r12620 r12881  
    3232import org.openstreetmap.josm.io.CachedFile;
    3333import org.openstreetmap.josm.io.XmlStreamParsingException;
     34import org.openstreetmap.josm.spi.preferences.Setting;
     35import org.openstreetmap.josm.spi.preferences.ListListSetting;
     36import org.openstreetmap.josm.spi.preferences.ListSetting;
     37import org.openstreetmap.josm.spi.preferences.MapListSetting;
     38import org.openstreetmap.josm.spi.preferences.StringSetting;
    3439import org.openstreetmap.josm.tools.Logging;
    3540import org.xml.sax.SAXException;
  • trunk/src/org/openstreetmap/josm/data/preferences/PreferencesWriter.java

    r11746 r12881  
    1212import org.openstreetmap.josm.data.Version;
    1313import org.openstreetmap.josm.io.XmlWriter;
     14import org.openstreetmap.josm.spi.preferences.Setting;
     15import org.openstreetmap.josm.spi.preferences.ListListSetting;
     16import org.openstreetmap.josm.spi.preferences.SettingVisitor;
     17import org.openstreetmap.josm.spi.preferences.ListSetting;
     18import org.openstreetmap.josm.spi.preferences.MapListSetting;
     19import org.openstreetmap.josm.spi.preferences.StringSetting;
    1420
    1521/**
Note: See TracChangeset for help on using the changeset viewer.