Changeset 3718 in josm for trunk


Ignore:
Timestamp:
2010-12-12T12:55:57+01:00 (13 years ago)
Author:
Upliner
Message:

Add WMSPlugin/SlippyMap settings migration dialog, fixes #5732

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

Legend:

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

    r3715 r3718  
    1515
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    1718import org.openstreetmap.josm.io.MirroredInputStream;
    1819
     
    6869                            if(!defaults.contains(url)) {
    6970                                for(ImageryInfo i : layers) {
    70                                     if(url.equals(i.url)) {
     71                                    if ((i.getImageryType() == ImageryType.WMS && url.equals(i.getURL()))
     72                                            || url.equals(i.getFullURL())) {
    7173                                        force = false;
    7274                                    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r3715 r3718  
    1919import java.util.List;
    2020import java.util.Locale;
    21 import java.util.Map;
    2221
    2322import javax.swing.BorderFactory;
     
    6261    ImageryProvidersPanel imageryProviders;
    6362
     63    static ImagerySettingsMigration settingsMigration;
     64
    6465    // Common settings
    6566    private Color colFadeColor;
     
    8788        this.colFadeColor = ImageryLayer.getFadeColor();
    8889        this.btnFadeColor = new JButton();
    89         this.btnFadeColor.setBackground(colFadeColor);
    90         this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
    9190
    9291        this.btnFadeColor.addActionListener(new ActionListener() {
     
    114113        p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
    115114        p.add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
    116         this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get());
    117115
    118116        this.sharpen = new JComboBox(new String[] {
     
    122120        p.add(new JLabel(tr("Sharpen (requires layer re-add): ")));
    123121        p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
    124         p.add(this.sharpen, GBC.std().fill(GBC.HORIZONTAL));
    125         this.sharpen.setSelectedIndex(ImageryLayer.PROP_SHARPEN_LEVEL.get());
    126 
     122        p.add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL));
     123
     124        if (settingsMigration != null) {
     125            final JButton btnSettingsMigration = new JButton(tr("WMSPlugin/SlippyMap settings migration"));
     126            btnSettingsMigration.addActionListener(new ActionListener() {
     127                @Override
     128                public void actionPerformed(ActionEvent e) {
     129                    if (settingsMigration == null) return;
     130                    settingsMigration.settingsMigrationDialog(gui);
     131                    loadSettings();
     132                    imageryProviders.model.fireTableDataChanged();
     133                    if (!settingsMigration.hasConflicts()) {
     134                        btnSettingsMigration.setEnabled(false);
     135                        settingsMigration = null;
     136                    }
     137                }
     138            });
     139            p.add(btnSettingsMigration,GBC.eol().insets(0,5,0,5));
     140        }
    127141        return p;
    128142    }
     
    136150        "webkit-image-gtk {0}"});
    137151        browser.setEditable(true);
    138         browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get());
    139152        p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));
    140153        p.add(browser);
     
    143156        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
    144157
    145         overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSLayer.PROP_OVERLAP.get());
     158        overlapCheckBox = new JCheckBox(tr("Overlap tiles"));
    146159        JLabel labelEast = new JLabel(tr("% of east:"));
    147160        JLabel labelNorth = new JLabel(tr("% of north:"));
     
    196209        tmsTab.add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL));
    197210
    198         this.autozoomActive.setSelected(TMSLayer.PROP_DEFAULT_AUTOZOOM.get());
    199         this.autoloadTiles.setSelected(TMSLayer.PROP_DEFAULT_AUTOLOAD.get());
    200         this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get());
    201         this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
    202         this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
    203211        return tmsTab;
    204212    }
     
    232240        pane.add(buildSettingsPanel(gui));
    233241        pane.add(new OffsetBookmarksPanel(gui));
     242        loadSettings();
    234243        pane.setTitleAt(0, tr("Imagery providers"));
    235244        pane.setTitleAt(1, tr("Settings"));
    236245        pane.setTitleAt(2, tr("Offset bookmarks"));
    237246        p.add(pane,GBC.std().fill(GBC.BOTH));
     247    }
     248
     249    private void loadSettings() {
     250        // Common settings
     251        this.btnFadeColor.setBackground(colFadeColor);
     252        this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
     253        this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get());
     254        this.sharpen.setSelectedIndex(ImageryLayer.PROP_SHARPEN_LEVEL.get());
     255
     256        // WMS Settings
     257        this.browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get());
     258        this.overlapCheckBox.setSelected(WMSLayer.PROP_OVERLAP.get());
     259        this.spinEast.setValue(WMSLayer.PROP_OVERLAP_EAST.get());
     260        this.spinNorth.setValue(WMSLayer.PROP_OVERLAP_NORTH.get());
     261        this.spinSimConn.setValue(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get());
     262
     263        // TMS Settings
     264        this.autozoomActive.setSelected(TMSLayer.PROP_DEFAULT_AUTOZOOM.get());
     265        this.autoloadTiles.setSelected(TMSLayer.PROP_DEFAULT_AUTOLOAD.get());
     266        this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get());
     267        this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
     268        this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
    238269    }
    239270
     
    707738
    708739    public static void initialize() {
    709         migrateWMSPlugin();
    710         migrateSlippyMapPlugin();
     740        settingsMigration = new ImagerySettingsMigration();
     741        settingsMigration.migrateSettings();
     742        if (!settingsMigration.hasConflicts()) {
     743            settingsMigration = null;
     744        }
    711745        ImageryLayerInfo.instance.load();
    712746        OffsetBookmark.loadBookmarks();
     
    714748        Main.main.menu.imageryMenuUpdater.refreshOffsetMenu();
    715749    }
    716 
    717     // Migration of WMSPlugin and SlippyMap settings
    718     static boolean wmsLayersConflict;
    719     static boolean wmsSettingsConflict;
    720     static boolean tmsSettingsConflict;
    721 
    722     static class SettingsConflictException extends Exception {
    723     }
    724 
    725     static void migrateProperty(String oldProp, String newProp)
    726     throws SettingsConflictException {
    727         String oldValue = Main.pref.get(oldProp, null);
    728         if (oldValue == null) return;
    729         String newValue = Main.pref.get(newProp, null);
    730         if (newValue != null && !oldValue.equals(newValue)) {
    731             System.out.println(tr("Imagery settings migration: conflict when moving property {0} -> {1}",
    732                     oldProp, newProp));
    733             throw new SettingsConflictException();
    734         }
    735         Main.pref.put(newProp, oldValue);
    736         Main.pref.put(oldProp, null);
    737     }
    738 
    739     static void migrateWMSPlugin() {
    740         try {
    741             migrateProperty("wmslayers", "imagery.layers");
    742         } catch (SettingsConflictException e) {
    743             wmsLayersConflict = true;
    744         }
    745         try {
    746             Main.pref.put("wmslayers.default", null);
    747             migrateProperty("imagery.remotecontrol", "remotecontrol.permission.imagery");
    748             migrateProperty("wmsplugin.remotecontrol", "remotecontrol.permission.imagery");
    749             migrateProperty("wmsplugin.alpha_channel", "imagery.wms.alpha_channel");
    750             migrateProperty("wmsplugin.browser", "imagery.wms.browser");
    751             migrateProperty("wmsplugin.user_agent", "imagery.wms.user_agent");
    752             migrateProperty("wmsplugin.timeout.connect", "imagery.wms.timeout.connect");
    753             migrateProperty("wmsplugin.timeout.read", "imagery.wms.timeout.read");
    754             migrateProperty("wmsplugin.simultaneousConnections", "imagery.wms.simultaneousConnections");
    755             migrateProperty("wmsplugin.overlap", "imagery.wms.overlap");
    756             migrateProperty("wmsplugin.overlapEast", "imagery.wms.overlapEast");
    757             migrateProperty("wmsplugin.overlapNorth", "imagery.wms.overlapNorth");
    758             Map<String, String> unknownProps = Main.pref.getAllPrefix("wmsplugin");
    759             if (!unknownProps.isEmpty()) {
    760                 System.out.println(tr("There are {0} unknown WMSPlugin settings", unknownProps.size()));
    761                 wmsSettingsConflict = true;
    762             }
    763         } catch (SettingsConflictException e) {
    764             wmsSettingsConflict = true;
    765         }
    766     }
    767 
    768     static void migrateSlippyMapPlugin() {
    769         try {
    770             Main.pref.put("slippymap.tile_source", null);
    771             Main.pref.put("slippymap.last_zoom_lvl", null);
    772             migrateProperty("slippymap.draw_debug", "imagery.tms.draw_debug");
    773             migrateProperty("slippymap.autoload_tiles", "imagery.tms.autoload");
    774             migrateProperty("slippymap.autozoom", "imagery.tms.autozoom");
    775             migrateProperty("slippymap.min_zoom_lvl", "imagery.tms.min_zoom_lvl");
    776             migrateProperty("slippymap.max_zoom_lvl", "imagery.tms.max_zoom_lvl");
    777             if (Main.pref.get("slippymap.fade_background_100", null) == null) {
    778                 try {
    779                     Main.pref.putInteger("slippymap.fade_background_100", (int)Math.round(
    780                             Double.valueOf(Main.pref.get("slippymap.fade_background", "0"))*100.0));
    781                 } catch (NumberFormatException e) {
    782                 }
    783             }
    784             Main.pref.put("slippymap.fade_background", null);
    785             migrateProperty("slippymap.fade_background_100", "imagery.fade_amount");
    786             Map<String, String> unknownProps = Main.pref.getAllPrefix("slippymap");
    787             if (!unknownProps.isEmpty()) {
    788                 System.out.println(tr("There are {0} unknown slippymap plugin settings", unknownProps.size()));
    789                 wmsSettingsConflict = true;
    790             }
    791         } catch (SettingsConflictException e) {
    792             tmsSettingsConflict = true;
    793         }
    794     }
    795 
    796750}
Note: See TracChangeset for help on using the changeset viewer.