- Timestamp:
- 2010-01-14T16:31:41+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r2839 r2856 101 101 } 102 102 103 private static Map<String, Collection<String>> buildCommandLineArgumentMap(String[] args) { 104 Map<String, Collection<String>> argMap = new HashMap<String, Collection<String>>(); 105 for (String arg : args) { 106 if ("-h".equals(arg) || "-?".equals(arg)) { 107 arg = "--help"; 108 } 109 // handle simple arguments like file names, URLs, bounds 110 if (!arg.startsWith("--")) { 111 arg = "--download="+arg; 112 } 113 int i = arg.indexOf('='); 114 String key = i == -1 ? arg.substring(2) : arg.substring(2,i); 115 String value = i == -1 ? "" : arg.substring(i+1); 116 Collection<String> v = argMap.get(key); 117 if (v == null) { 118 v = new LinkedList<String>(); 119 } 120 v.add(value); 121 argMap.put(key, v); 122 } 123 return argMap; 124 } 125 103 126 /** 104 127 * Main application Startup … … 115 138 116 139 // construct argument table 117 final Map<String, Collection<String>> args = new HashMap<String, Collection<String>>(); 118 for (String arg : argArray) { 119 if ("-h".equals(arg) || "-?".equals(arg)) { 120 arg = "--help"; 121 } 122 // handle simple arguments like file names, URLs, bounds 123 if (!arg.startsWith("--")) { 124 arg = "--download="+arg; 125 } 126 int i = arg.indexOf('='); 127 String key = i == -1 ? arg.substring(2) : arg.substring(2,i); 128 String value = i == -1 ? "" : arg.substring(i+1); 129 Collection<String> v = args.get(key); 130 if (v == null) { 131 v = new LinkedList<String>(); 132 } 133 v.add(value); 134 args.put(key, v); 135 } 140 final Map<String, Collection<String>> args = buildCommandLineArgumentMap(argArray); 136 141 137 142 Main.pref.init(args.containsKey("reset-preferences")); … … 162 167 splash.setVisible(Main.pref.getBoolean("draw.splashscreen", true)); 163 168 164 List<PluginInformation> pluginsToLoad = PluginHandler.buildListOfPluginsToLoad( monitor.createSubTaskMonitor(1, false));165 if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate( )) {169 List<PluginInformation> pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(splash,monitor.createSubTaskMonitor(1, false)); 170 if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) { 166 171 monitor.subTask(tr("Updating plugins...")); 167 PluginHandler.updatePlugins( pluginsToLoad, monitor.createSubTaskMonitor(1, false));172 PluginHandler.updatePlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 168 173 } 169 174 monitor.worked(1); … … 174 179 175 180 monitor.subTask(tr("Loading early plugins")); 176 PluginHandler.loadEarlyPlugins( pluginsToLoad, monitor.createSubTaskMonitor(1, false));181 PluginHandler.loadEarlyPlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 177 182 monitor.worked(1); 178 183 … … 189 194 190 195 monitor.subTask(tr("Loading plugins")); 191 PluginHandler.loadLatePlugins( pluginsToLoad, monitor.createSubTaskMonitor(1, false));196 PluginHandler.loadLatePlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 192 197 monitor.worked(1); 193 198 toolbar.refreshToolbarControl(); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r2855 r2856 6 6 7 7 import java.awt.Font; 8 import java.awt.GridBagConstraints; 8 9 import java.awt.GridBagLayout; 10 import java.awt.Insets; 11 import java.awt.Window; 9 12 import java.awt.event.ActionEvent; 10 13 import java.io.File; … … 34 37 import javax.swing.Box; 35 38 import javax.swing.JButton; 39 import javax.swing.JCheckBox; 36 40 import javax.swing.JLabel; 37 41 import javax.swing.JOptionPane; … … 43 47 import org.openstreetmap.josm.Main; 44 48 import org.openstreetmap.josm.data.Version; 45 import org.openstreetmap.josm.gui.ExtendedDialog; 49 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 50 import org.openstreetmap.josm.gui.JMultilineLabel; 46 51 import org.openstreetmap.josm.gui.MapFrame; 52 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 47 53 import org.openstreetmap.josm.gui.download.DownloadSelection; 54 import org.openstreetmap.josm.gui.help.HelpUtil; 48 55 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 49 56 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 82 89 * @param plugins the collection of plugins 83 90 */ 84 private static void filterDeprecatedPlugins( Collection<String> plugins) {91 private static void filterDeprecatedPlugins(Window parent, Collection<String> plugins) { 85 92 Set<String> removedPlugins = new HashSet<String>(); 86 93 for (String p : DEPRECATED_PLUGINS) { … … 110 117 sb.append("</html>"); 111 118 JOptionPane.showMessageDialog( 112 Main.parent,119 parent, 113 120 sb.toString(), 114 121 tr("Warning"), … … 126 133 * @param plugins the collection of plugins 127 134 */ 128 private static void filterUnmaintainedPlugins( Collection<String> plugins) {135 private static void filterUnmaintainedPlugins(Window parent, Collection<String> plugins) { 129 136 for (String unmaintained : UNMAINTAINED_PLUGINS) { 130 137 if (!plugins.contains(unmaintained)) { … … 134 141 + "<br>This plugin is no longer developed and very likely will produce errors." 135 142 +"<br>It should be disabled.<br>Delete from preferences?</html>", unmaintained); 136 if (confirmDisablePlugin( msg,unmaintained)) {143 if (confirmDisablePlugin(parent, msg,unmaintained)) { 137 144 Main.pref.removeFromCollection("plugins", unmaintained); 138 145 plugins.remove(unmaintained); … … 147 154 * if the plugins were last updated a long time ago. 148 155 * 156 * @param parent the parent window relative to which the confirmation dialog 157 * is to be displayed 149 158 * @return true if a plugin update should be run; false, otherwise 150 159 */ 151 public static boolean checkAndConfirmPluginUpdate( ) {160 public static boolean checkAndConfirmPluginUpdate(Window parent) { 152 161 String message = null; 153 162 String togglePreferenceKey = null; 154 163 int v = Version.getInstance().getVersion(); 155 164 if (Main.pref.getInteger("pluginmanager.version", 0) < v) { 156 message = tr("<html>You updated your JOSM software.<br>" 157 + "To prevent problems the plugins should be updated as well.<br><br>" 158 + "Update plugins now?" 159 + "</html>" 160 ); 165 message = 166 "<html>" 167 + tr("You updated your JOSM software.<br>" 168 + "To prevent problems the plugins should be updated as well.<br><br>" 169 + "Update plugins now?" 170 ) 171 + "</html>"; 161 172 togglePreferenceKey = "pluginmanager.version"; 162 173 } else { … … 168 179 Main.pref.put("pluginmanager.lastupdate", Long.toString(tim)); 169 180 } else if (d > maxTime) { 170 message = tr("Last plugin update more than {0} days ago.", d); 181 message = 182 "<html>" 183 + tr("Last plugin update more than {0} days ago.", d) 184 + "</html>"; 171 185 togglePreferenceKey = "pluginmanager.time"; 172 186 } … … 174 188 if (message == null) return false; 175 189 176 // ask whether update is fine 177 // 178 ExtendedDialog dialog = new ExtendedDialog( 179 Main.parent, 190 ButtonSpec [] options = new ButtonSpec[] { 191 new ButtonSpec( 192 tr("Update plugins"), 193 ImageProvider.get("dialogs", "refresh"), 194 tr("Click to update the activated plugins"), 195 null /* no specific help context */ 196 ), 197 new ButtonSpec( 198 tr("Skip update"), 199 ImageProvider.get("cancel"), 200 tr("Click to skip updating the activated plugins"), 201 null /* no specific help context */ 202 ) 203 }; 204 205 UpdatePluginsMessagePanel pnlMessage = new UpdatePluginsMessagePanel(); 206 pnlMessage.setMessage(message); 207 pnlMessage.initDontShowAgain(togglePreferenceKey); 208 209 int ret = HelpAwareOptionPane.showOptionDialog( 210 parent, 211 pnlMessage, 180 212 tr("Update plugins"), 181 new String[] { 182 tr("Update plugins"), tr("Skip update") 183 } 213 JOptionPane.WARNING_MESSAGE, 214 null, 215 options, 216 options[0], 217 ht("/Plugin/AutomaticUpdate") 184 218 ); 185 dialog.setContent(message); 186 dialog.toggleEnable(togglePreferenceKey); 187 dialog.setButtonIcons( new String[] {"dialogs/refresh.png", "cancel.png"}); 188 dialog.configureContextsensitiveHelp(ht("/Plugin/AutomaticUpdate"), true /* show help button */); 189 dialog.showDialog(); 190 return dialog.getValue() == 1; 219 220 pnlMessage.rememberDontShowAgain(togglePreferenceKey); 221 return ret == 0; 191 222 } 192 223 … … 197 228 * @param missingRequiredPlugin the missing required plugin 198 229 */ 199 private static void alertMissingRequiredPlugin( String plugin, Set<String> missingRequiredPlugin) {230 private static void alertMissingRequiredPlugin(Window parent, String plugin, Set<String> missingRequiredPlugin) { 200 231 StringBuilder sb = new StringBuilder(); 201 232 sb.append("<html>"); … … 212 243 sb.append("</ul>").append("</html>"); 213 244 JOptionPane.showMessageDialog( 214 Main.parent,245 parent, 215 246 sb.toString(), 216 247 tr("Error"), … … 219 250 } 220 251 252 private static void alertJOSMUpdateRequired(Window parent, String plugin, int requiredVersion) { 253 HelpAwareOptionPane.showOptionDialog( 254 parent, 255 tr("<html>Plugin {0} requires JOSM version {1}. The current JOSM version is {1}.<br>" 256 +"You have to update JOSM in order to use this plugin.</html>", 257 plugin, requiredVersion 258 ), 259 tr("Warning"), 260 JOptionPane.WARNING_MESSAGE, 261 HelpUtil.ht("/Plugin/Loading#JOSMUpdateRequired") 262 ); 263 } 264 221 265 /** 222 266 * Checks whether all preconditions for loading the plugin <code>plugin</code> are met. The … … 228 272 * @return true, if the preconditions are met; false otherwise 229 273 */ 230 public static boolean checkLoadPreconditions( Collection<PluginInformation> plugins, PluginInformation plugin) {274 public static boolean checkLoadPreconditions(Window parent, Collection<PluginInformation> plugins, PluginInformation plugin) { 231 275 232 276 // make sure the plugin is compatible with the current JOSM version … … 234 278 int josmVersion = Version.getInstance().getVersion(); 235 279 if (plugin.mainversion > josmVersion && josmVersion != Version.JOSM_UNKNOWN_VERSION) { 236 JOptionPane.showMessageDialog( 237 Main.parent, 238 tr("Plugin {0} requires JOSM update to version {1}.", plugin.name, 239 plugin.mainversion), 240 tr("Warning"), 241 JOptionPane.WARNING_MESSAGE 242 ); 280 alertJOSMUpdateRequired(parent, plugin.name, plugin.mainversion); 243 281 return false; 244 282 } … … 258 296 } 259 297 if (!missingPlugins.isEmpty()) { 260 alertMissingRequiredPlugin(p lugin.name, missingPlugins);298 alertMissingRequiredPlugin(parent, plugin.name, missingPlugins); 261 299 return false; 262 300 } … … 300 338 * @param pluginClassLoader the plugin class loader 301 339 */ 302 public static void loadPlugin( PluginInformation plugin, ClassLoader pluginClassLoader) {340 public static void loadPlugin(Window parent, PluginInformation plugin, ClassLoader pluginClassLoader) { 303 341 try { 304 342 Class<?> klass = plugin.loadClass(pluginClassLoader); … … 310 348 e.printStackTrace(); 311 349 String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name); 312 if (confirmDisablePlugin( msg, plugin.name)) {350 if (confirmDisablePlugin(parent, msg, plugin.name)) { 313 351 Main.pref.removeFromCollection("plugins", plugin.name); 314 352 } … … 323 361 * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null. 324 362 */ 325 public static void loadPlugins( Collection<PluginInformation> plugins, ProgressMonitor monitor) {363 public static void loadPlugins(Window parent,Collection<PluginInformation> plugins, ProgressMonitor monitor) { 326 364 if (monitor == null) { 327 365 monitor = NullProgressMonitor.INSTANCE; … … 345 383 monitor.subTask(tr("Checking plugin preconditions...")); 346 384 for (PluginInformation pi: plugins) { 347 if (checkLoadPreconditions(p lugins, pi)) {385 if (checkLoadPreconditions(parent, plugins, pi)) { 348 386 toLoad.add(pi); 349 387 } … … 357 395 for (PluginInformation info : toLoad) { 358 396 monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name)); 359 loadPlugin( info, pluginClassLoader);397 loadPlugin(parent, info, pluginClassLoader); 360 398 monitor.worked(1); 361 399 } … … 372 410 * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null. 373 411 */ 374 public static void loadEarlyPlugins( Collection<PluginInformation> plugins, ProgressMonitor monitor) {412 public static void loadEarlyPlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) { 375 413 List<PluginInformation> earlyPlugins = new ArrayList<PluginInformation>(plugins.size()); 376 414 for (PluginInformation pi: plugins) { … … 379 417 } 380 418 } 381 loadPlugins( earlyPlugins, monitor);419 loadPlugins(parent, earlyPlugins, monitor); 382 420 } 383 421 … … 389 427 * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null. 390 428 */ 391 public static void loadLatePlugins( Collection<PluginInformation> plugins, ProgressMonitor monitor) {429 public static void loadLatePlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) { 392 430 List<PluginInformation> latePlugins = new ArrayList<PluginInformation>(plugins.size()); 393 431 for (PluginInformation pi: plugins) { … … 396 434 } 397 435 } 398 loadPlugins( latePlugins, monitor);436 loadPlugins(parent, latePlugins, monitor); 399 437 } 400 438 … … 434 472 } 435 473 436 private static void alertMissingPluginInformation( Collection<String> plugins) {474 private static void alertMissingPluginInformation(Window parent, Collection<String> plugins) { 437 475 StringBuilder sb = new StringBuilder(); 438 476 sb.append("<html>"); … … 449 487 plugins.size())); 450 488 sb.append("</html>"); 451 JOptionPane.showMessageDialog(452 Main.parent,489 HelpAwareOptionPane.showOptionDialog( 490 parent, 453 491 sb.toString(), 454 492 tr("Warning"), 455 JOptionPane.WARNING_MESSAGE 493 JOptionPane.WARNING_MESSAGE, 494 HelpUtil.ht("/Plugin/Loading#MissingPluginInfos") 456 495 ); 457 496 } … … 465 504 * @return the set of plugins to load (as set of plugin names) 466 505 */ 467 public static List<PluginInformation> buildListOfPluginsToLoad( ProgressMonitor monitor) {506 public static List<PluginInformation> buildListOfPluginsToLoad(Window parent, ProgressMonitor monitor) { 468 507 if (monitor == null) { 469 508 monitor = NullProgressMonitor.INSTANCE; … … 477 516 } 478 517 monitor.subTask(tr("Removing deprecated plugins...")); 479 filterDeprecatedPlugins(p lugins);518 filterDeprecatedPlugins(parent, plugins); 480 519 monitor.subTask(tr("Removing umaintained plugins...")); 481 filterUnmaintainedPlugins(p lugins);520 filterUnmaintainedPlugins(parent, plugins); 482 521 Map<String, PluginInformation> infos = loadLocallyAvailablePluginInformation(monitor.createSubTaskMonitor(1,false)); 483 522 List<PluginInformation> ret = new LinkedList<PluginInformation>(); … … 490 529 } 491 530 if (!plugins.isEmpty()) { 492 alertMissingPluginInformation(p lugins);531 alertMissingPluginInformation(parent, plugins); 493 532 } 494 533 return ret; … … 498 537 } 499 538 500 private static void alertFailedPluginUpdate( Collection<PluginInformation> plugins) {539 private static void alertFailedPluginUpdate(Window parent, Collection<PluginInformation> plugins) { 501 540 StringBuffer sb = new StringBuffer(); 502 541 sb.append("<html>"); … … 512 551 } 513 552 sb.append("</ul>"); 514 sb.append(tr("Please open the Preference Dialog after JOSM has started and try to update them manually.")); 553 sb.append(trn( 554 "Please open the Preference Dialog after JOSM has started and try to update it manually.", 555 "Please open the Preference Dialog after JOSM has started and try to update them manually.", 556 plugins.size() 557 )); 515 558 sb.append("</html>"); 516 JOptionPane.showMessageDialog(517 Main.parent,559 HelpAwareOptionPane.showOptionDialog( 560 parent, 518 561 sb.toString(), 519 562 tr("Plugin update failed"), 520 JOptionPane.ERROR_MESSAGE 563 JOptionPane.ERROR_MESSAGE, 564 HelpUtil.ht("/Plugin/Loading#FailedPluginUpdated") 521 565 ); 522 566 } … … 529 573 * @throws IllegalArgumentException thrown if plugins is null 530 574 */ 531 public static void updatePlugins( Collection<PluginInformation> plugins, ProgressMonitor monitor) throws IllegalArgumentException{575 public static void updatePlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) throws IllegalArgumentException{ 532 576 CheckParameterUtil.ensureParameterNotNull(plugins, "plugins"); 533 577 if (monitor == null) { … … 550 594 } 551 595 if (! task.getFailedPlugins().isEmpty()) { 552 alertFailedPluginUpdate( task.getFailedPlugins());596 alertFailedPluginUpdate(parent, task.getFailedPlugins()); 553 597 return; 554 598 } … … 569 613 * @return true, if the plugin shall be disabled; false, otherwise 570 614 */ 571 public static boolean confirmDisablePlugin(String reason, String name) { 572 ExtendedDialog dialog = new ExtendedDialog( 573 Main.parent, 615 public static boolean confirmDisablePlugin(Window parent, String reason, String name) { 616 ButtonSpec [] options = new ButtonSpec[] { 617 new ButtonSpec( 618 tr("Disable plugin"), 619 ImageProvider.get("dialogs", "delete"), 620 tr("Click to delete the plugin ''{0}''", name), 621 null /* no specific help context */ 622 ), 623 new ButtonSpec( 624 tr("Keep plugin"), 625 ImageProvider.get("cancel"), 626 tr("Click to keep the plugin ''{0}''", name), 627 null /* no specific help context */ 628 ) 629 }; 630 int ret = HelpAwareOptionPane.showOptionDialog( 631 parent, 632 reason, 574 633 tr("Disable plugin"), 575 new String[] { 576 tr("Disable plugin"), tr("Keep plugin") 577 } 634 JOptionPane.WARNING_MESSAGE, 635 null, 636 options, 637 options[0], 638 null // FIXME: add help topic 578 639 ); 579 dialog.setContent(reason); 580 dialog.setButtonIcons(new String[] { "dialogs/delete.png", "cancel.png" }); 581 dialog.showDialog(); 582 return dialog.getValue() == 1; 640 return ret == 0; 583 641 } 584 642 … … 648 706 } 649 707 650 public static boolean checkException(Throwable e) 651 { 708 private static boolean confirmDisablingPluginAfterException(PluginProxy plugin) { 709 ButtonSpec [] options = new ButtonSpec[] { 710 new ButtonSpec( 711 tr("Disable plugin"), 712 ImageProvider.get("dialogs", "delete"), 713 tr("Click to disable the plugin ''{0}''", plugin.getPluginInformation().name), 714 null /* no specific help context */ 715 ), 716 new ButtonSpec( 717 tr("Keep plugin"), 718 ImageProvider.get("cancel"), 719 tr("Click to keep the plugin ''{0}''",plugin.getPluginInformation().name), 720 null /* no specific help context */ 721 ) 722 }; 723 724 StringBuffer msg = new StringBuffer(); 725 msg.append("<html>"); 726 msg.append(tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.getPluginInformation().name)); 727 msg.append("<br>"); 728 if(plugin.getPluginInformation().author != null) { 729 msg.append(tr("According to the information within the plugin, the author is {0}.", plugin.getPluginInformation().author)); 730 msg.append("<br>"); 731 } 732 msg.append(tr("Try updating to the newest version of this plugin before reporting a bug.")); 733 msg.append("<br>"); 734 msg.append(tr("Should the plugin be disabled?")); 735 msg.append("</html>"); 736 737 int ret = HelpAwareOptionPane.showOptionDialog( 738 Main.parent, 739 msg.toString(), 740 tr("Update plugins"), 741 JOptionPane.QUESTION_MESSAGE, 742 null, 743 options, 744 options[0], 745 ht("/ErrorMessages#ErrorInPlugin") 746 ); 747 return ret == 0; 748 } 749 750 private static PluginProxy getPluginCausingException(Throwable ex) { 751 for (PluginProxy p : pluginList) { 752 String baseClass = p.getPluginInformation().className; 753 int i = baseClass.lastIndexOf("."); 754 baseClass = baseClass.substring(0, i); 755 for (StackTraceElement element : ex.getStackTrace()) { 756 String c = element.getClassName(); 757 if (c.startsWith(baseClass)) 758 return p; 759 } 760 } 761 return null; 762 } 763 764 public static boolean checkException(Throwable e) { 652 765 PluginProxy plugin = null; 653 766 654 767 // Check for an explicit problem when calling a plugin function 655 768 if (e instanceof PluginException) { 656 plugin = ((PluginException) e).plugin;769 plugin = ((PluginException) e).plugin; 657 770 } 658 771 659 772 if (plugin == null) { 660 /** 661 * Analyze the stack of the argument and find a name of a plugin, if 662 * some known problem pattern has been found. 663 */ 664 for (PluginProxy p : pluginList) { 665 String baseClass = p.getPluginInformation().className; 666 int i = baseClass.lastIndexOf("."); 667 baseClass = baseClass.substring(0, i); 668 for (StackTraceElement element : e.getStackTrace()) { 669 String c = element.getClassName(); 670 if (c.startsWith(baseClass)) { 671 plugin = p; 672 break; 673 } 773 plugin = getPluginCausingException(e); 774 } 775 776 if (plugin != null && confirmDisablingPluginAfterException(plugin)) { 777 List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections 778 .<String> emptyList())); 779 if (plugins.contains(plugin.getPluginInformation().name)) { 780 while (plugins.remove(plugin.getPluginInformation().name)) { 674 781 } 675 if (plugin != null) { 676 break; 677 } 678 } 679 } 680 681 if (plugin != null) { 682 ExtendedDialog dialog = new ExtendedDialog( 683 Main.parent, 684 tr("Disable plugin"), 685 new String[] {tr("Disable plugin"), tr("Cancel")} 686 ); 687 dialog.setButtonIcons(new String[] {"dialogs/delete.png", "cancel.png"}); 688 dialog.setContent( 689 "<html>" + 690 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.getPluginInformation().name) 691 + "<br>" 692 + (plugin.getPluginInformation().author != null 693 ? tr("According to the information within the plugin, the author is {0}.", plugin.getPluginInformation().author) 694 : "") 695 + "<br>" 696 + tr("Try updating to the newest version of this plugin before reporting a bug.") 697 + "<br>" 698 + tr("Should the plugin be disabled?") 699 + "</html>" 700 ); 701 dialog.showDialog(); 702 int answer = dialog.getValue(); 703 704 if (answer == 1) { 705 List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections.<String>emptyList())); 706 if (plugins.contains(plugin.getPluginInformation().name)) { 707 while (plugins.remove(plugin.getPluginInformation().name)) {} 708 Main.pref.putCollection("plugins", plugins); 709 JOptionPane.showMessageDialog(Main.parent, 710 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."), 711 tr("Information"), 712 JOptionPane.INFORMATION_MESSAGE); 713 } else { 714 JOptionPane.showMessageDialog( 715 Main.parent, 716 tr("The plugin could not be removed. Probably it was already disabled"), 717 tr("Error"), 718 JOptionPane.ERROR_MESSAGE 719 ); 720 } 721 return true; 722 } 782 Main.pref.putCollection("plugins", plugins); 783 JOptionPane 784 .showMessageDialog( 785 Main.parent, 786 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."), 787 tr("Information"), JOptionPane.INFORMATION_MESSAGE); 788 } else { 789 JOptionPane.showMessageDialog(Main.parent, 790 tr("The plugin could not be removed. Probably it was already disabled"), tr("Error"), 791 JOptionPane.ERROR_MESSAGE); 792 } 793 return true; 723 794 } 724 795 return false; … … 778 849 return pluginTab; 779 850 } 851 852 static private class UpdatePluginsMessagePanel extends JPanel { 853 private JMultilineLabel lblMessage; 854 private JCheckBox cbDontShowAgain; 855 856 protected void build() { 857 setLayout(new GridBagLayout()); 858 GridBagConstraints gc = new GridBagConstraints(); 859 gc.anchor = GridBagConstraints.NORTHWEST; 860 gc.fill = GridBagConstraints.BOTH; 861 gc.weightx = 1.0; 862 gc.weighty = 1.0; 863 gc.insets = new Insets(5,5,5,5); 864 add(lblMessage = new JMultilineLabel(""), gc); 865 lblMessage.setFont(lblMessage.getFont().deriveFont(Font.PLAIN)); 866 867 gc.gridy = 1; 868 gc.fill = GridBagConstraints.HORIZONTAL; 869 gc.weighty = 0.0; 870 add(cbDontShowAgain = new JCheckBox(tr("Do not show again (remembers choice)")), gc); 871 cbDontShowAgain.setFont(cbDontShowAgain.getFont().deriveFont(Font.PLAIN)); 872 } 873 874 public UpdatePluginsMessagePanel() { 875 build(); 876 } 877 878 public void setMessage(String message) { 879 lblMessage.setText(message); 880 } 881 882 public void initDontShowAgain(String preferencesKey) { 883 cbDontShowAgain.setSelected(Main.pref.getBoolean(preferencesKey, false)); 884 } 885 886 public void rememberDontShowAgain(String preferenceKey) { 887 Main.pref.put(preferenceKey, cbDontShowAgain.isSelected()); 888 } 889 } 780 890 }
Note:
See TracChangeset
for help on using the changeset viewer.