Ignore:
Timestamp:
2009-07-27T18:36:17+02:00 (15 years ago)
Author:
Gubaer
Message:

partial fix for #3109: window order generally messed up?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r1837 r1860  
    3434import org.openstreetmap.josm.gui.ExtendedDialog;
    3535import org.openstreetmap.josm.gui.MapFrame;
     36import org.openstreetmap.josm.gui.OptionPaneUtil;
    3637import org.openstreetmap.josm.gui.download.DownloadSelection;
    3738import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
     
    5152        List<String> plugins = new LinkedList<String>();
    5253        Collection<String> cp = Main.pref.getCollection("plugins", null);
    53         if (cp != null)
     54        if (cp != null) {
    5455            plugins.addAll(cp);
    55         if (System.getProperty("josm.plugins") != null)
     56        }
     57        if (System.getProperty("josm.plugins") != null) {
    5658            plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(",")));
     59        }
    5760
    5861        String [] oldplugins = new String[] {"mappaint", "unglueplugin",
    59         "lang-de", "lang-en_GB", "lang-fr", "lang-it", "lang-pl", "lang-ro",
    60         "lang-ru", "ewmsplugin", "ywms", "tways-0.2", "geotagged", "landsat",
    61         "namefinder", "waypoints", "slippy_map_chooser", "tcx-support"};
     62                "lang-de", "lang-en_GB", "lang-fr", "lang-it", "lang-pl", "lang-ro",
     63                "lang-ru", "ewmsplugin", "ywms", "tways-0.2", "geotagged", "landsat",
     64                "namefinder", "waypoints", "slippy_map_chooser", "tcx-support"};
    6265        for (String p : oldplugins) {
    6366            if (plugins.contains(p)) {
    6467                plugins.remove(p);
    6568                Main.pref.removeFromCollection("plugins", p);
    66                 JOptionPane.showMessageDialog(Main.parent, tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p));
     69                OptionPaneUtil.showMessageDialog(
     70                        Main.parent,
     71                        tr("Loading of {0} plugin was requested. This plugin is no longer required.", p),
     72                        tr("Warning"),
     73                        JOptionPane.WARNING_MESSAGE
     74                );
    6775            }
    6876        }
     
    7583            PluginInformation info = PluginInformation.findPlugin(pluginName);
    7684            if (info != null) {
    77                 if (info.early != early)
     85                if (info.early != early) {
    7886                    continue;
     87                }
    7988                if (info.mainversion > AboutAction.getVersionNumber()) {
    80                     JOptionPane.showMessageDialog(Main.parent, tr("Plugin {0} requires JOSM update to version {1}.", pluginName,
    81                     info.mainversion));
     89                    OptionPaneUtil.showMessageDialog(
     90                            Main.parent,
     91                            tr("Plugin {0} requires JOSM update to version {1}.", pluginName,
     92                                    info.mainversion),
     93                                    tr("Warning"),
     94                                    JOptionPane.WARNING_MESSAGE
     95                    );
    8296                    continue;
    8397                }
     
    92106                    if(warn != null)
    93107                    {
    94                         JOptionPane.showMessageDialog(Main.parent,
    95                         tr("Plugin {0} is required by plugin {1} but was not found.",
    96                         warn, pluginName));
     108                        OptionPaneUtil.showMessageDialog(Main.parent,
     109                                tr("Plugin {0} is required by plugin {1} but was not found.",
     110                                        warn, pluginName),
     111                                        tr("Error"),
     112                                        JOptionPane.ERROR_MESSAGE
     113                        );
    97114                        continue;
    98115                    }
    99116                }
    100                 if (!p.containsKey(info.stage))
     117                if (!p.containsKey(info.stage)) {
    101118                    p.put(info.stage, new LinkedList<PluginInformation>());
     119                }
    102120                p.get(info.stage).add(info);
    103121            } else if(early) {
    104                 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName));
     122                OptionPaneUtil.showMessageDialog(
     123                        Main.parent,
     124                        tr("Plugin not found: {0}.", pluginName),
     125                        tr("Error"),
     126                        JOptionPane.ERROR_MESSAGE
     127                );
    105128            }
    106129        }
     
    114137                Main.pref.put("pluginmanager.lastupdate",Long.toString(tim));
    115138            } else if (d > maxTime) {
    116                 JOptionPane.showMessageDialog(Main.parent,
    117                    "<html>" +
    118                    tr("Last plugin update more than {0} days ago.", d) +
    119                    "<br><em>" +
    120                    tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") +
    121                    "</html>");
     139                OptionPaneUtil.showMessageDialog(Main.parent,
     140                        "<html>" +
     141                        tr("Last plugin update more than {0} days ago.", d) +
     142                        "<br><em>" +
     143                        tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") +
     144                        "</html>",
     145                        tr("Warning"),
     146                        JOptionPane.WARNING_MESSAGE
     147                );
    122148            }
    123149        }
     
    125151        // iterate all plugins and collect all libraries of all plugins:
    126152        List<URL> allPluginLibraries = new ArrayList<URL>();
    127         for (Collection<PluginInformation> c : p.values())
    128             for (PluginInformation info : c)
     153        for (Collection<PluginInformation> c : p.values()) {
     154            for (PluginInformation info : c) {
    129155                allPluginLibraries.addAll(info.libraries);
     156            }
     157        }
    130158        // create a classloader for all plugins:
    131159        URL[] jarUrls = new URL[allPluginLibraries.size()];
     
    146174
    147175                    int result = new ExtendedDialog(Main.parent,
    148                         tr("Disable plugin"),
    149                         tr("Could not load plugin {0}. Delete from preferences?", info.name),
    150                         new String[] {tr("Disable plugin"), tr("Keep plugin")},
    151                         new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
     176                            tr("Disable plugin"),
     177                            tr("Could not load plugin {0}. Delete from preferences?", info.name),
     178                            new String[] {tr("Disable plugin"), tr("Keep plugin")},
     179                            new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
    152180
    153181                    if(result == 1)
     
    161189    }
    162190    public static void setMapFrame(MapFrame old, MapFrame map) {
    163         for (PluginProxy plugin : pluginList)
     191        for (PluginProxy plugin : pluginList) {
    164192            plugin.mapFrameInitialized(old, map);
     193        }
    165194    }
    166195
     
    174203    public static void addDownloadSelection(List<DownloadSelection> downloadSelections)
    175204    {
    176         for (PluginProxy p : pluginList)
     205        for (PluginProxy p : pluginList) {
    177206            p.addDownloadSelection(downloadSelections);
     207        }
    178208    }
    179209    public static void getPreferenceSetting(Collection<PreferenceSettingFactory> settings)
     
    187217    {
    188218        if (!PluginDownloader.moveUpdatedPlugins()) {
    189             JOptionPane.showMessageDialog(null,
     219            OptionPaneUtil.showMessageDialog(
     220                    Main.parent,
    190221                    tr("Activating the updated plugins failed. Check if JOSM has the permission to overwrite the existing ones."),
    191222                    tr("Plugins"), JOptionPane.ERROR_MESSAGE);
     
    197228
    198229        // Check for an explicit problem when calling a plugin function
    199         if (e instanceof PluginException)
     230        if (e instanceof PluginException) {
    200231            plugin = ((PluginException)e).plugin;
     232        }
    201233
    202234        if (plugin == null)
     
    204236            String name = null;
    205237            /**
    206             * Analyze the stack of the argument and find a name of a plugin, if
    207             * some known problem pattern has been found.
    208             *
    209             * Note: This heuristic is not meant as discrimination against specific
    210             * plugins, but only to stop the flood of similar bug reports about plugins.
    211             * Of course, plugin writers are free to install their own version of
    212             * an exception handler with their email address listed to receive
    213             * bug reports ;-).
    214             */
     238             * Analyze the stack of the argument and find a name of a plugin, if
     239             * some known problem pattern has been found.
     240             *
     241             * Note: This heuristic is not meant as discrimination against specific
     242             * plugins, but only to stop the flood of similar bug reports about plugins.
     243             * Of course, plugin writers are free to install their own version of
     244             * an exception handler with their email address listed to receive
     245             * bug reports ;-).
     246             */
    215247            for (StackTraceElement element : e.getStackTrace()) {
    216248                String c = element.getClassName();
    217249
    218                 if (c.contains("wmsplugin.") || c.contains(".WMSLayer"))
     250                if (c.contains("wmsplugin.") || c.contains(".WMSLayer")) {
    219251                    name = "wmsplugin";
    220                 if (c.contains("livegps."))
     252                }
     253                if (c.contains("livegps.")) {
    221254                    name = "livegps";
    222                 if (c.startsWith("UtilsPlugin."))
     255                }
     256                if (c.startsWith("UtilsPlugin.")) {
    223257                    name = "UtilsPlugin";
     258                }
    224259
    225260                if (c.startsWith("org.openstreetmap.josm.plugins.")) {
     
    229264                    }
    230265                }
    231                 if(name != null)
    232                   break;
     266                if(name != null) {
     267                    break;
     268                }
    233269            }
    234270            for (PluginProxy p : pluginList)
     
    244280        if (plugin != null) {
    245281            int answer = new ExtendedDialog(Main.parent,
    246                 tr("Disable plugin"),
    247                 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.info.name)
     282                    tr("Disable plugin"),
     283                    tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.info.name)
    248284                    + "\n"
    249285                    + (plugin.info.author != null
    250                         ? tr("According to the information within the plugin, the author is {0}.", plugin.info.author)
    251                         : "")
    252                     + "\n"
    253                     + tr("Try updating to the newest version of this plugin before reporting a bug.")
    254                     + "\n"
    255                     + tr("Should the plugin be disabled?"),
    256                 new String[] {tr("Disable plugin"), tr("Cancel")},
    257                 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
     286                            ? tr("According to the information within the plugin, the author is {0}.", plugin.info.author)
     287                                    : "")
     288                                    + "\n"
     289                                    + tr("Try updating to the newest version of this plugin before reporting a bug.")
     290                                    + "\n"
     291                                    + tr("Should the plugin be disabled?"),
     292                                    new String[] {tr("Disable plugin"), tr("Cancel")},
     293                                    new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
    258294            if (answer == 1) {
    259295                List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections.<String>emptyList()));
     
    261297                    while (plugins.remove(plugin.info.name)) {}
    262298                    Main.pref.putCollection("plugins", plugins);
    263                     JOptionPane.showMessageDialog(Main.parent,
    264                     tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."));
     299                    OptionPaneUtil.showMessageDialog(Main.parent,
     300                            tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
     301                            tr("Information"),
     302                            JOptionPane.INFORMATION_MESSAGE);
    265303                } else {
    266                     JOptionPane.showMessageDialog(Main.parent,
    267                     tr("The plugin could not be removed. Probably it was already disabled"));
     304                    OptionPaneUtil.showMessageDialog(
     305                            Main.parent,
     306                            tr("The plugin could not be removed. Probably it was already disabled"),
     307                            tr("Error"),
     308                            JOptionPane.ERROR_MESSAGE
     309                    );
    268310                }
    269311                return true;
     
    276318        String text = "";
    277319        String pl = Main.pref.get("plugins");
    278         if(pl != null && pl.length() != 0)
     320        if(pl != null && pl.length() != 0) {
    279321            text += "Plugins: "+pl+"\n";
     322        }
    280323        for (final PluginProxy pp : pluginList) {
    281324            text += "Plugin " + pp.info.name + (pp.info.version != null && !pp.info.version.equals("") ? " Version: "+pp.info.version+"\n" : "\n");
     
    302345                    a.setEditable(false);
    303346                    a.setText(b.toString());
    304                     JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a));
     347                    OptionPaneUtil.showMessageDialog(
     348                            Main.parent,
     349                            new JScrollPane(a),
     350                            tr("Plugin information"),
     351                            JOptionPane.INFORMATION_MESSAGE
     352                    );
    305353                }
    306354            }), GBC.eol());
Note: See TracChangeset for help on using the changeset viewer.