Changeset 4016 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2011-04-06T14:57:45+02:00 (14 years ago)
Author:
Upliner
Message:

fix #5863 add ability to cancel changes in Imagery providers list

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

Legend:

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

    r3978 r4016  
    2323    public static final ImageryLayerInfo instance = new ImageryLayerInfo();
    2424    ArrayList<ImageryInfo> layers = new ArrayList<ImageryInfo>();
    25     ArrayList<ImageryInfo> defaultLayers = new ArrayList<ImageryInfo>();
     25    static ArrayList<ImageryInfo> defaultLayers = new ArrayList<ImageryInfo>();
    2626
    2727    private final static String[] DEFAULT_LAYER_SITES = {
     
    2929    };
    3030
    31     public void load(boolean clearCache) {
     31    private ImageryLayerInfo() {
     32    }
     33
     34    public ImageryLayerInfo(ImageryLayerInfo info) {
     35        layers.addAll(info.layers);
     36    }
     37
     38    public void load() {
    3239        layers.clear();
    33         defaultLayers.clear();
    34         Collection<String> defaults = Main.pref.getCollection(
    35                 "imagery.layers.default", Collections.<String>emptySet());
    3640        for(Collection<String> c : Main.pref.getArray("imagery.layers",
    3741                Collections.<Collection<String>>emptySet())) {
    3842            add(new ImageryInfo(c));
    3943        }
     44        Collections.sort(layers);
     45    }
    4046
     47    public void loadDefaults(boolean clearCache) {
     48        defaultLayers.clear();
     49        Collection<String> defaults = Main.pref.getCollection(
     50                "imagery.layers.default", Collections.<String>emptySet());
    4151        ArrayList<String> defaultsSave = new ArrayList<String>();
    4252        for(String source : Main.pref.getCollection("imagery.layers.sites", Arrays.asList(DEFAULT_LAYER_SITES)))
     
    97107        }
    98108
     109        Collections.sort(defaultLayers);
    99110        Main.pref.putCollection("imagery.layers.default", defaultsSave.size() > 0
    100111                ? defaultsSave : defaults);
    101         Collections.sort(layers);
    102         Collections.sort(defaultLayers);
    103         save();
    104112    }
    105113
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r3978 r4016  
    7171    }
    7272    ImageryProvidersPanel imageryProviders;
     73    ImageryLayerInfo layerInfo;
    7374
    7475    static ImagerySettingsMigration settingsMigration;
     
    269270        JPanel p = gui.createPreferenceTab("imagery", tr("Imagery Preferences"), tr("Modify list of imagery layers displayed in the Imagery menu"));
    270271        JTabbedPane pane = new JTabbedPane();
    271         imageryProviders = new ImageryProvidersPanel(gui, ImageryLayerInfo.instance);
     272        layerInfo = new ImageryLayerInfo(ImageryLayerInfo.instance);
     273        imageryProviders = new ImageryProvidersPanel(gui, layerInfo);
    272274        pane.add(imageryProviders);
    273275        pane.add(buildSettingsPanel(gui));
     
    308310    public boolean ok() {
    309311        boolean restartRequired = false;
    310         ImageryLayerInfo.instance.save();
     312        layerInfo.save();
     313        ImageryLayerInfo.instance.load();
    311314        Main.main.menu.imageryMenu.refreshImageryMenu();
    312315        Main.main.menu.imageryMenu.refreshOffsetMenu();
     
    567570
    568571            public void actionPerformed(ActionEvent evt) {
    569                 layerInfo.load(true);
     572                layerInfo.loadDefaults(true);
    570573                modeldef.fireTableDataChanged();
    571574            }
     
    857860            settingsMigration = null;
    858861        }
    859         ImageryLayerInfo.instance.load(false);
     862        ImageryLayerInfo.instance.load();
     863        ImageryLayerInfo.instance.loadDefaults(false);
    860864        OffsetBookmark.loadBookmarks();
    861865        Main.main.menu.imageryMenu.refreshImageryMenu();
Note: See TracChangeset for help on using the changeset viewer.