Changeset 1096 in josm for trunk/src/org


Ignore:
Timestamp:
2008-11-28T00:08:50+01:00 (15 years ago)
Author:
framm
Message:
  • added patch for optionally deleting .jar when the plugin is activated, and fix for plugin recency check, both by Stephan Knauss <osm@…>. Some reformatting. Closes #1796, #1795.
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r1095 r1096  
    181181
    182182        /**
    183          * Remove the specified layer from the map. If it is the last layer, remove the map as well.
     183         * Remove the specified layer from the map. If it is the last layer,
     184     * remove the map as well.
    184185         */
    185186        public final void removeLayer(final Layer layer) {
     
    217218
    218219        /**
    219          * Load all plugins specified in preferences. If the parameter is <code>true</code>, all
    220          * early plugins are loaded (before constructor).
     220         * Load all plugins specified in preferences. If the parameter is
     221     * <code>true</code>, all early plugins are loaded (before constructor).
    221222         */
    222223        public static void loadPlugins(boolean early) {
     
    229230
    230231                String [] oldplugins = new String[] {"mappaint", "unglueplugin", "lang-de","lang-en_GB","lang-fr","lang-it","lang-pl","lang-ro","lang-ru"};
    231                 for(String p : oldplugins)
    232                 {
    233                         if(plugins.contains(p))
    234                         {
     232                for (String p : oldplugins) {
     233                        if (plugins.contains(p)) {
    235234                                plugins.remove(p);
    236235                                Main.pref.removeFromCollection("plugins", p);
     
    248247                                if (info.early != early)
    249248                                        continue;
    250                                 if (info.mainversion != null && info.mainversion.compareTo(AboutAction.version) > 0)
    251                                 {
     249                                if (info.mainversion != null && info.mainversion.compareTo(AboutAction.version) > 0) {
    252250                                        JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName));
    253251                                        continue;
     
    264262                }
    265263
    266                 if(!early)
    267                 {
     264                if (!early) {
    268265                        long tim = System.currentTimeMillis();
    269266                        long last = Main.pref.getLong("pluginmanager.lastupdate", 0);
    270267                        Integer maxTime = Main.pref.getInteger("pluginmanager.warntime", 30);
    271                         if(last <= 0)
    272                         {
     268                        if (last <= 0) {
    273269                                Main.pref.put("pluginmanager.lastupdate",Long.toString(tim));
    274                         }
    275                         else if(tim - last >= maxTime*1000*24*60*60)
    276                         {
    277                                 long d = (tim - last)/(24*60*60*1000);
    278                                 JOptionPane.showMessageDialog(Main.parent, tr("Last plugin update more than {0} days ago.", d));
     270                        } else if (tim - last >= maxTime*1000l*24*60*60) {
     271                                long d = (tim - last)/(24*60*60*1000l);
     272                                JOptionPane.showMessageDialog(Main.parent,
     273                    tr("Last plugin update more than {0} days ago.", d));
    279274                        }
    280275                }
     
    348343        }
    349344
    350 
    351 
    352 
    353345        /**
    354346         * Use this to register shortcuts to
     
    357349
    358350
    359         ////////////////////////////////////////////////////////////////////////////////////////
     351        ///////////////////////////////////////////////////////////////////////////
    360352        //  Implementation part
    361         ////////////////////////////////////////////////////////////////////////////////////////
     353        ///////////////////////////////////////////////////////////////////////////
    362354
    363355        public static JPanel panel = new JPanel(new BorderLayout());
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r1073 r1096  
    1212import java.io.File;
    1313import java.io.FileReader;
     14import java.io.IOException;
    1415import java.util.Arrays;
    1516import java.util.Collection;
     
    113114                JButton morePlugins = new JButton(tr("Download List"));
    114115                morePlugins.addActionListener(new ActionListener(){
    115                         public void actionPerformed(ActionEvent e) {
    116                                 int count = PluginDownloader.downloadDescription();
    117                                 if (count > 0)
    118                                         JOptionPane.showMessageDialog(Main.parent,
    119                                                         trn("Downloaded plugin information from {0} site",
    120                                                                         "Downloaded plugin information from {0} sites", count, count));
    121                                 else
    122                                         JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found."));
    123                                 refreshPluginPanel(gui);
     116                    public void actionPerformed(ActionEvent e) {
     117                        int count = PluginDownloader.downloadDescription();
     118                        if (count > 0)
     119                            JOptionPane.showMessageDialog(Main.parent,
     120                                trn("Downloaded plugin information from {0} site",
     121                                    "Downloaded plugin information from {0} sites", count, count));
     122                        else
     123                            JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found."));
     124                        refreshPluginPanel(gui);
    124125                        }
    125126                });
     
    132133                                refreshPluginPanel(gui);
    133134                        }
    134 
    135135                });
    136136                plugin.add(update, GBC.std().insets(0,0,10,0));
     
    141141                                configureSites();
    142142                        }
    143 
    144143                });
    145144                plugin.add(configureSites, GBC.std());
     
    286285                        pluginCheck.addActionListener(new ActionListener(){
    287286                                public void actionPerformed(ActionEvent e) {
     287                    // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar
     288                    if (pluginCheck.isSelected()) {
     289                        PluginInformation plinfo = PluginInformation.findPlugin(plugin.name);
     290                        if ((PluginInformation.getLoaded(plugin.name) == null) && (plinfo != null)) {
     291                            try {
     292                                int answer = JOptionPane.showConfirmDialog(Main.parent,
     293                                    tr("Plugin archive already available. Do you want to download current version by deleting existing archive?\n\n{0}",
     294                                    plinfo.file.getCanonicalPath()), tr("Plugin already exists"), JOptionPane.OK_CANCEL_OPTION);
     295                                if (answer == JOptionPane.OK_OPTION) {
     296                                    if (!plinfo.file.delete()) {
     297                                        JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath()));
     298                                    }
     299                                }
     300                            } catch (IOException e1) {
     301                                e1.printStackTrace();
     302                                JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage()));
     303                            }
     304                        }
     305                    }
    288306                                        pluginMap.put(plugin, pluginCheck.isSelected());
    289307                                }
Note: See TracChangeset for help on using the changeset viewer.