Changeset 10114 in josm


Ignore:
Timestamp:
2016-04-06T23:32:07+02:00 (8 years ago)
Author:
Don-vip
Message:

refactor duplicated code

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r10035 r10114  
    113113    protected final transient List<SourceProvider> sourceProviders;
    114114
    115     protected JTable tblIconPaths;
    116     protected IconPathTableModel iconPathsModel;
     115    private JTable tblIconPaths;
     116    private IconPathTableModel iconPathsModel;
    117117
    118118    protected boolean sourcesInitiallyLoaded;
     
    412412     */
    413413    public abstract boolean finish();
     414
     415    protected boolean doFinish(SourcePrefHelper prefHelper, String iconPref) {
     416        boolean changed = prefHelper.put(activeSourcesModel.getSources());
     417
     418        if (tblIconPaths != null) {
     419            List<String> iconPaths = iconPathsModel.getIconPaths();
     420
     421            if (!iconPaths.isEmpty()) {
     422                if (Main.pref.putCollection(iconPref, iconPaths)) {
     423                    changed = true;
     424                }
     425            } else if (Main.pref.putCollection(iconPref, null)) {
     426                changed = true;
     427            }
     428        }
     429        return changed;
     430    }
    414431
    415432    /**
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r9231 r10114  
    8686    static class MapPaintSourceEditor extends SourceEditor {
    8787
    88         private static final String iconpref = "mappaint.icon.sources";
     88        private static final String ICONPREF = "mappaint.icon.sources";
    8989
    9090        MapPaintSourceEditor() {
     
    9999        @Override
    100100        public boolean finish() {
    101             List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    102 
    103             boolean changed = MapPaintPrefHelper.INSTANCE.put(activeStyles);
    104 
    105             if (tblIconPaths != null) {
    106                 List<String> iconPaths = iconPathsModel.getIconPaths();
    107 
    108                 if (!iconPaths.isEmpty()) {
    109                     if (Main.pref.putCollection(iconpref, iconPaths)) {
    110                         changed = true;
    111                     }
    112                 } else if (Main.pref.putCollection(iconpref, null)) {
    113                     changed = true;
    114                 }
    115             }
    116             return changed;
     101            return doFinish(MapPaintPrefHelper.INSTANCE, ICONPREF);
    117102        }
    118103
     
    124109        @Override
    125110        public Collection<String> getInitialIconPathsList() {
    126             return Main.pref.getCollection(iconpref, null);
     111            return Main.pref.getCollection(ICONPREF, null);
    127112        }
    128113
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java

    r9098 r10114  
    2828import org.openstreetmap.josm.gui.preferences.SourceEditor;
    2929import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    30 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    3130import org.openstreetmap.josm.gui.preferences.SourceEntry;
    3231import org.openstreetmap.josm.gui.preferences.SourceProvider;
     
    3433import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
    3534import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
     35import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    3636import org.openstreetmap.josm.tools.GBC;
    3737import org.xml.sax.SAXException;
     
    183183    static class TaggingPresetSourceEditor extends SourceEditor {
    184184
    185         private static final String iconpref = "taggingpreset.icon.sources";
     185        private static final String ICONPREF = "taggingpreset.icon.sources";
    186186
    187187        TaggingPresetSourceEditor() {
     
    196196        @Override
    197197        public boolean finish() {
    198             List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    199 
    200             boolean changed = PresetPrefHelper.INSTANCE.put(activeStyles);
    201 
    202             if (tblIconPaths != null) {
    203                 List<String> iconPaths = iconPathsModel.getIconPaths();
    204 
    205                 if (!iconPaths.isEmpty()) {
    206                     if (Main.pref.putCollection(iconpref, iconPaths)) {
    207                         changed = true;
    208                     }
    209                 } else if (Main.pref.putCollection(iconpref, null)) {
    210                     changed = true;
    211                 }
    212             }
    213             return changed;
     198            return doFinish(PresetPrefHelper.INSTANCE, ICONPREF);
    214199        }
    215200
     
    221206        @Override
    222207        public Collection<String> getInitialIconPathsList() {
    223             return Main.pref.getCollection(iconpref, null);
     208            return Main.pref.getCollection(ICONPREF, null);
    224209        }
    225210
Note: See TracChangeset for help on using the changeset viewer.