Changeset 1187 in josm


Ignore:
Timestamp:
2008-12-28T14:13:50+01:00 (15 years ago)
Author:
stoecker
Message:

fixed bug #1677. Patch by Matthew W. S. Bell

File:
1 edited

Legend:

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

    r1180 r1187  
    7979    }
    8080
    81     private Map<PluginDescription, Boolean> pluginMap;
     81    private Map<String, Boolean> pluginMap;
     82    private Map<String, PluginDescription> availablePlugins;
    8283    private JPanel plugin;
    8384    private class MyBox extends Box {
     
    204205        StringBuilder toUpdateStr = new StringBuilder();
    205206        for (PluginProxy proxy : Main.plugins) {
    206             PluginDescription description = findDescription(proxy.info.name);
    207             if (description != null && (description.version == null || description.version.equals(""))
    208             ? (proxy.info.version != null && proxy.info.version.equals("")) : !description.version.equals(proxy.info.version)) {
     207            PluginDescription description = availablePlugins.get(proxy.info.name);
     208            if (description != null && (description.version == null || description.version.equals("")) ?
     209            (proxy.info.version != null && proxy.info.version.equals("")) : !description.version.equals(proxy.info.version)) {
    209210                toUpdate.add(description);
    210211                toUpdateStr.append(description.name+"\n");
     
    214215            JOptionPane.showMessageDialog(Main.parent, tr("All installed plugins are up to date."));
    215216            done = true;
    216         }
    217         else
    218         {
     217        } else {
    219218            int answer = JOptionPane.showConfirmDialog(Main.parent, tr("Update the following plugins:\n\n{0}",
    220219            toUpdateStr.toString()), tr("Update"), JOptionPane.OK_CANCEL_OPTION);
    221             if (answer == JOptionPane.OK_OPTION)
    222             {
     220            if (answer == JOptionPane.OK_OPTION) {
    223221                PluginDownloader.update(toUpdate);
    224222                done = true;
    225223            }
    226224        }
    227         if(done && num >= 1)
     225        if (done && num >= 1)
    228226            Main.pref.put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis()));
    229227    }
    230228
    231     private PluginDescription findDescription(String name) {
    232         for (PluginDescription d : pluginMap.keySet())
    233             if (d.name.equals(name))
    234                 return d;
    235         return null;
    236     }
    237 
    238229    private void refreshPluginPanel(final PreferenceDialog gui) {
    239         Collection<PluginDescription> availablePlugins = getAvailablePlugins();
    240         pluginMap = new HashMap<PluginDescription, Boolean>();
     230        availablePlugins = getAvailablePlugins();
     231        Collection<String> enabledPlugins = Main.pref.getCollection("plugins", null);
     232
     233        if (pluginMap == null)
     234            pluginMap = new HashMap<String, Boolean>();
     235        else
     236            // Keep the map in bounds; possibly slightly pointless.
     237            for (final String pname : pluginMap.keySet())
     238                if (availablePlugins.get(pname) == null) pluginMap.remove(pname);
     239
    241240        pluginPanel.removeAll();
    242241        int width = pluginPanel.myGetWidth();
    243242
    244         Collection<String> enabledPlugins = Main.pref.getCollection("plugins", null);
    245 
    246         for (final PluginDescription plugin : availablePlugins) {
    247             boolean enabled = enabledPlugins != null && enabledPlugins.contains(plugin.name);
     243        for (final PluginDescription plugin : availablePlugins.values()) {
     244            boolean enabled = (enabledPlugins != null) && enabledPlugins.contains(plugin.name);
     245            if (pluginMap.get(plugin.name) == null)
     246                pluginMap.put(plugin.name, enabled);
     247
    248248            String remoteversion = plugin.version;
    249             if(remoteversion == null || remoteversion.equals(""))
     249            if ((remoteversion == null) || remoteversion.equals(""))
    250250                remoteversion = tr("unknown");
    251251
    252252            String localversion;
    253253            PluginInformation p = PluginInformation.findPlugin(plugin.name);
    254             if(p != null)
    255             {
    256                 if(p.version != null && !p.version.equals(""))
     254            if (p != null) {
     255                if (p.version != null && !p.version.equals(""))
    257256                    localversion = p.version;
    258257                else
    259258                    localversion = tr("unknown");
    260259                localversion = " (" + localversion + ")";
    261             }
    262             else
     260            } else
    263261                localversion = "";
    264262
    265             final JCheckBox pluginCheck = new JCheckBox(tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion), enabled);
     263            final JCheckBox pluginCheck = new JCheckBox(
     264                    tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion),
     265                    pluginMap.get(plugin.name));
    266266            pluginPanel.add(pluginCheck);
    267267
    268             pluginCheck.setToolTipText(plugin.resource != null ? ""+plugin.resource : tr("Plugin bundled with JOSM"));
    269             JLabel label = new JLabel("<html><i>"+(plugin.description==null?tr("no description available"):plugin.description)+"</i></html>");
    270             label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0));
    271             label.setMaximumSize(new Dimension(width,1000));
     268            pluginCheck.setToolTipText(plugin.resource != null ? "" + plugin.resource : tr("Plugin bundled with JOSM"));
     269            JLabel label = new JLabel("<html><i>" + (plugin.description == null ? tr("no description available") : plugin.description) + "</i></html>");
     270            label.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
     271            label.setMaximumSize(new Dimension(width, 1000));
    272272            pluginPanel.add(label);
    273273            pluginPanel.add(Box.createVerticalStrut(5));
    274274
    275             pluginMap.put(plugin, enabled);
    276275            pluginCheck.addActionListener(new ActionListener(){
    277276                public void actionPerformed(ActionEvent e) {
     
    295294                        }
    296295                    }
    297                     pluginMap.put(plugin, pluginCheck.isSelected());
     296                    pluginMap.put(plugin.name, pluginCheck.isSelected());
    298297                }
    299298            });
     
    302301    }
    303302
    304     private Collection<PluginDescription> getAvailablePlugins() {
     303    private Map<String, PluginDescription> getAvailablePlugins() {
    305304        SortedMap<String, PluginDescription> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){
    306305            public int compare(String o1, String o2) {
     
    348347                            PluginInformation.fileToURL(proxy.info.file).toString(),
    349348                        proxy.info.version));
    350         return availablePlugins.values();
     349        return availablePlugins;
    351350    }
    352351
     
    354353        Collection<PluginDescription> toDownload = new LinkedList<PluginDescription>();
    355354        String msg = "";
    356         for (Entry<PluginDescription, Boolean> entry : pluginMap.entrySet()) {
    357             if (entry.getValue() && PluginInformation.findPlugin(entry.getKey().name) == null) {
    358                 toDownload.add(entry.getKey());
    359                 msg += entry.getKey().name+"\n";
     355        for (Entry<String, Boolean> entry : pluginMap.entrySet()) {
     356            if (entry.getValue() && PluginInformation.findPlugin(entry.getKey()) == null) {
     357                toDownload.add(availablePlugins.get(entry.getKey()));
     358                msg += entry.getKey() + "\n";
    360359            }
    361360        }
     
    367366            if (answer != JOptionPane.OK_OPTION)
    368367                for (PluginDescription pd : toDownload)
    369                     pluginMap.put(pd, false);
     368                    pluginMap.put(pd.name, false);
    370369            else
    371370                for (PluginDescription pd : toDownload)
    372371                    if (!PluginDownloader.downloadPlugin(pd))
    373                         pluginMap.put(pd, false);
     372                        pluginMap.put(pd.name, false);
    374373
    375374        }
    376375
    377376        LinkedList<String> plugins = new LinkedList<String>();
    378         Object pd[] = pluginMap.keySet().toArray();
    379         Arrays.sort(pd);
    380         for (Object d : pd) {
    381             if (pluginMap.get(d))
    382                 plugins.add(((PluginDescription)d).name);
     377        Object pds[] = pluginMap.keySet().toArray();
     378        Arrays.sort(pds);
     379        for (Object d : pds) {
     380            PluginDescription pd = (PluginDescription)d;
     381            if (pluginMap.get(pd.name))
     382                plugins.add(pd.name);
    383383        }
    384384
Note: See TracChangeset for help on using the changeset viewer.