Changeset 1187 in josm
- Timestamp:
- 2008-12-28T14:13:50+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r1180 r1187 79 79 } 80 80 81 private Map<PluginDescription, Boolean> pluginMap; 81 private Map<String, Boolean> pluginMap; 82 private Map<String, PluginDescription> availablePlugins; 82 83 private JPanel plugin; 83 84 private class MyBox extends Box { … … 204 205 StringBuilder toUpdateStr = new StringBuilder(); 205 206 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)) { 209 210 toUpdate.add(description); 210 211 toUpdateStr.append(description.name+"\n"); … … 214 215 JOptionPane.showMessageDialog(Main.parent, tr("All installed plugins are up to date.")); 215 216 done = true; 216 } 217 else 218 { 217 } else { 219 218 int answer = JOptionPane.showConfirmDialog(Main.parent, tr("Update the following plugins:\n\n{0}", 220 219 toUpdateStr.toString()), tr("Update"), JOptionPane.OK_CANCEL_OPTION); 221 if (answer == JOptionPane.OK_OPTION) 222 { 220 if (answer == JOptionPane.OK_OPTION) { 223 221 PluginDownloader.update(toUpdate); 224 222 done = true; 225 223 } 226 224 } 227 if (done && num >= 1)225 if (done && num >= 1) 228 226 Main.pref.put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis())); 229 227 } 230 228 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 238 229 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 241 240 pluginPanel.removeAll(); 242 241 int width = pluginPanel.myGetWidth(); 243 242 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 248 248 String remoteversion = plugin.version; 249 if (remoteversion == null|| remoteversion.equals(""))249 if ((remoteversion == null) || remoteversion.equals("")) 250 250 remoteversion = tr("unknown"); 251 251 252 252 String localversion; 253 253 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("")) 257 256 localversion = p.version; 258 257 else 259 258 localversion = tr("unknown"); 260 259 localversion = " (" + localversion + ")"; 261 } 262 else 260 } else 263 261 localversion = ""; 264 262 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)); 266 266 pluginPanel.add(pluginCheck); 267 267 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)); 272 272 pluginPanel.add(label); 273 273 pluginPanel.add(Box.createVerticalStrut(5)); 274 274 275 pluginMap.put(plugin, enabled);276 275 pluginCheck.addActionListener(new ActionListener(){ 277 276 public void actionPerformed(ActionEvent e) { … … 295 294 } 296 295 } 297 pluginMap.put(plugin , pluginCheck.isSelected());296 pluginMap.put(plugin.name, pluginCheck.isSelected()); 298 297 } 299 298 }); … … 302 301 } 303 302 304 private Collection<PluginDescription> getAvailablePlugins() {303 private Map<String, PluginDescription> getAvailablePlugins() { 305 304 SortedMap<String, PluginDescription> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){ 306 305 public int compare(String o1, String o2) { … … 348 347 PluginInformation.fileToURL(proxy.info.file).toString(), 349 348 proxy.info.version)); 350 return availablePlugins .values();349 return availablePlugins; 351 350 } 352 351 … … 354 353 Collection<PluginDescription> toDownload = new LinkedList<PluginDescription>(); 355 354 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"; 360 359 } 361 360 } … … 367 366 if (answer != JOptionPane.OK_OPTION) 368 367 for (PluginDescription pd : toDownload) 369 pluginMap.put(pd , false);368 pluginMap.put(pd.name, false); 370 369 else 371 370 for (PluginDescription pd : toDownload) 372 371 if (!PluginDownloader.downloadPlugin(pd)) 373 pluginMap.put(pd , false);372 pluginMap.put(pd.name, false); 374 373 375 374 } 376 375 377 376 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); 383 383 } 384 384
Note:
See TracChangeset
for help on using the changeset viewer.