Changeset 1326 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-01-23T22:22:10+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1307 r1326 12 12 import java.net.URI; 13 13 import java.net.URISyntaxException; 14 import java.net.URL;15 import java.net.URLClassLoader;16 import java.util.ArrayList;17 import java.util.Arrays;18 14 import java.util.Collection; 19 import java.util.LinkedList;20 import java.util.List;21 15 import java.util.Locale; 22 16 import java.util.Map; 23 import java.util.SortedMap;24 17 import java.util.StringTokenizer; 25 import java.util.TreeMap;26 18 import java.util.concurrent.Executor; 27 19 import java.util.concurrent.Executors; … … 34 26 import javax.swing.UIManager; 35 27 36 import org.openstreetmap.josm.actions.AboutAction;37 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 38 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; … … 57 48 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 58 49 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 59 import org.openstreetmap.josm.plugins.PluginInformation; 60 import org.openstreetmap.josm.plugins.PluginProxy; 50 import org.openstreetmap.josm.plugins.PluginHandler; 61 51 import org.openstreetmap.josm.tools.ImageProvider; 62 52 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … 102 92 */ 103 93 public static MapFrame map; 104 /**105 * All installed and loaded plugins (resp. their main classes)106 */107 public final static Collection<PluginProxy> plugins = new LinkedList<PluginProxy>();108 94 /** 109 95 * The dialog that gets displayed during background task execution. … … 164 150 redoUndoListener.commandChanged(0,0); 165 151 166 for (PluginProxy plugin : plugins) 167 plugin.mapFrameInitialized(old, map); 168 } 169 170 /** 171 * Set the layer menu (changed when active layer changes). 172 */ 173 public final void setLayerMenu(Component[] entries) { 174 //if (entries == null || entries.length == 0) 175 //menu.layerMenu.setVisible(false); 176 //else { 177 //menu.layerMenu.removeAll(); 178 //for (Component c : entries) 179 //menu.layerMenu.add(c); 180 //menu.layerMenu.setVisible(true); 181 //} 152 PluginHandler.setMapFrame(old, map); 182 153 } 183 154 … … 197 168 this(null); 198 169 } 199 170 200 171 public Main(SplashScreen splash) { 201 172 main = this; … … 205 176 if(splash != null) splash.setStatus(tr("Download \"Message of the day\"")); 206 177 panel.add(new GettingStarted(), BorderLayout.CENTER); 207 178 208 179 if(splash != null) splash.setStatus(tr("Creating main GUI")); 209 180 menu = new MainMenu(); … … 214 185 contentPane.add(toolbar.control, BorderLayout.NORTH); 215 186 216 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help"); 187 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 188 .put(Shortcut.registerShortcut("system:help", tr("Help"), 189 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help"); 217 190 contentPane.getActionMap().put("Help", menu.help); 218 191 … … 224 197 toolbar.control.updateUI(); 225 198 contentPane.updateUI(); 226 }227 228 /**229 * Load all plugins specified in preferences. If the parameter is230 * <code>true</code>, all early plugins are loaded (before constructor).231 */232 public static void loadPlugins(boolean early) {233 List<String> plugins = new LinkedList<String>();234 Collection<String> cp = Main.pref.getCollection("plugins", null);235 if (cp != null)236 plugins.addAll(cp);237 if (System.getProperty("josm.plugins") != null)238 plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(",")));239 240 String [] oldplugins = new String[] {"mappaint", "unglueplugin",241 "lang-de", "lang-en_GB", "lang-fr", "lang-it", "lang-pl", "lang-ro",242 "lang-ru", "ewmsplugin", "ywms", "tways-0.2", "geotagged", "landsat"};243 for (String p : oldplugins) {244 if (plugins.contains(p)) {245 plugins.remove(p);246 Main.pref.removeFromCollection("plugins", p);247 System.out.println(tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p));248 }249 }250 251 if (plugins.isEmpty())252 return;253 254 SortedMap<Integer, Collection<PluginInformation>> p = new TreeMap<Integer, Collection<PluginInformation>>();255 for (String pluginName : plugins) {256 PluginInformation info = PluginInformation.findPlugin(pluginName);257 if (info != null) {258 if (info.early != early)259 continue;260 if (info.mainversion != null) {261 int requiredJOSMVersion = 0;262 try {263 requiredJOSMVersion = Integer.parseInt(info.mainversion);264 } catch(NumberFormatException e) {265 e.printStackTrace();266 }267 if (requiredJOSMVersion > AboutAction.getVersionNumber()) {268 JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName));269 continue;270 }271 }272 if (!p.containsKey(info.stage))273 p.put(info.stage, new LinkedList<PluginInformation>());274 p.get(info.stage).add(info);275 } else {276 if (early)277 System.out.println("Plugin not found: "+pluginName); // do not translate278 else279 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName));280 }281 }282 283 if (!early) {284 long tim = System.currentTimeMillis();285 long last = Main.pref.getLong("pluginmanager.lastupdate", 0);286 Integer maxTime = Main.pref.getInteger("pluginmanager.warntime", 30);287 long d = (tim - last)/(24*60*60*1000l);288 if ((last <= 0) || (maxTime <= 0)) {289 Main.pref.put("pluginmanager.lastupdate",Long.toString(tim));290 } else if (d > maxTime) {291 JOptionPane.showMessageDialog(Main.parent,292 "<html>" +293 tr("Last plugin update more than {0} days ago.", d) +294 "<br><em>" +295 tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") +296 "</html>");297 }298 }299 300 // iterate all plugins and collect all libraries of all plugins:301 List<URL> allPluginLibraries = new ArrayList<URL>();302 for (Collection<PluginInformation> c : p.values())303 for (PluginInformation info : c)304 allPluginLibraries.addAll(info.libraries);305 // create a classloader for all plugins:306 URL[] jarUrls = new URL[allPluginLibraries.size()];307 jarUrls = allPluginLibraries.toArray(jarUrls);308 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader());309 ImageProvider.sources.add(0, pluginClassLoader);310 311 for (Collection<PluginInformation> c : p.values()) {312 for (PluginInformation info : c) {313 try {314 Class<?> klass = info.loadClass(pluginClassLoader);315 if (klass != null) {316 System.out.println("loading "+info.name);317 Main.plugins.add(info.load(klass));318 }319 } catch (Throwable e) {320 e.printStackTrace();321 boolean remove = true;322 if (early)323 System.out.println("Could not load plugin: "+info.name+" - deleted from preferences"); // do not translate324 else {325 int answer = JOptionPane.showConfirmDialog(Main.parent,326 tr("Could not load plugin {0}. Delete from preferences?", info.name,327 JOptionPane.YES_NO_OPTION));328 if (answer != JOptionPane.OK_OPTION) {329 remove = false;330 }331 }332 if (remove) {333 plugins.remove(info.name);334 String plist = null;335 for (String pn : plugins) {336 if (plist==null) plist=""; else plist=plist+",";337 plist=plist+pn;338 }339 Main.pref.put("plugins", plist);340 }341 }342 }343 }344 199 } 345 200 … … 370 225 */ 371 226 public static final JPanel contentPane = new JPanel(new BorderLayout()); 372 373 227 374 228 /////////////////////////////////////////////////////////////////////////// -
trunk/src/org/openstreetmap/josm/actions/AboutAction.java
r1301 r1326 15 15 import java.net.MalformedURLException; 16 16 import java.net.URL; 17 import java.util.Map.Entry;18 17 import java.util.regex.Matcher; 19 18 import java.util.regex.Pattern; 20 19 21 import javax.swing.AbstractAction;22 20 import javax.swing.BorderFactory; 23 import javax.swing.Box;24 import javax.swing.JButton;25 21 import javax.swing.JLabel; 26 22 import javax.swing.JOptionPane; … … 29 25 import javax.swing.JTabbedPane; 30 26 import javax.swing.JTextArea; 31 import javax.swing.UIManager;32 27 33 28 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.plugins.Plugin Proxy;29 import org.openstreetmap.josm.plugins.PluginHandler; 35 30 import org.openstreetmap.josm.tools.GBC; 36 31 import org.openstreetmap.josm.tools.ImageProvider; … … 145 140 about.addTab(tr("Revision"), createScrollPane(revision)); 146 141 about.addTab(tr("Contribution"), createScrollPane(contribution)); 147 148 JPanel pluginTab = new JPanel(new GridBagLayout()); 149 for (final PluginProxy p : Main.plugins) { 150 String name = p.info.name + (p.info.version != null && !p.info.version.equals("") ? " Version: "+p.info.version : ""); 151 pluginTab.add(new JLabel(name), GBC.std()); 152 pluginTab.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL)); 153 pluginTab.add(new JButton(new AbstractAction(tr("Information")){ 154 public void actionPerformed(ActionEvent event) { 155 StringBuilder b = new StringBuilder(); 156 for (Entry<String,String> e : p.info.attr.entrySet()) { 157 b.append(e.getKey()); 158 b.append(": "); 159 b.append(e.getValue()); 160 b.append("\n"); 161 } 162 JTextArea a = new JTextArea(10,40); 163 a.setEditable(false); 164 a.setText(b.toString()); 165 JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a)); 166 } 167 }), GBC.eol()); 168 169 JTextArea description = new JTextArea((p.info.description==null? tr("no description available"):p.info.description)); 170 description.setEditable(false); 171 description.setFont(new JLabel().getFont().deriveFont(Font.ITALIC)); 172 description.setLineWrap(true); 173 description.setWrapStyleWord(true); 174 description.setBorder(BorderFactory.createEmptyBorder(0,20,0,0)); 175 description.setBackground(UIManager.getColor("Panel.background")); 176 177 pluginTab.add(description, GBC.eop().fill(GBC.HORIZONTAL)); 178 } 179 about.addTab(tr("Plugins"), new JScrollPane(pluginTab)); 142 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel())); 180 143 181 144 about.setPreferredSize(new Dimension(500,300)); 182 145 183 146 JOptionPane.showMessageDialog(Main.parent, about, tr("About JOSM..."), 184 147 JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo")); 185 148 } 186 149 -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1245 r1326 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.Color; … … 22 24 import java.util.regex.Pattern; 23 25 26 import javax.swing.JOptionPane; 27 24 28 import org.openstreetmap.josm.Main; 25 29 import org.openstreetmap.josm.actions.AboutAction; … … 298 302 properties.put(line.substring(0,i), line.substring(i+1)); 299 303 } 300 if (!errLines.isEmpty()) { 301 throw new IOException("Malformed config file at lines " + errLines); 302 } 304 if (!errLines.isEmpty()) 305 throw new IOException(tr("Malformed config file at lines {0}", errLines)); 303 306 setSystemProperties(); 307 } 308 309 public void init(Boolean reset) 310 { 311 // get the preferences. 312 File prefDir = getPreferencesDirFile(); 313 if (prefDir.exists()) { 314 if(!prefDir.isDirectory()) { 315 JOptionPane.showMessageDialog(null, tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir())); 316 return; 317 } 318 } 319 else 320 prefDir.mkdirs(); 321 322 if (!new File(getPreferencesDir()+"preferences").exists()) 323 resetToDefault(); 324 325 try { 326 if (reset) 327 resetToDefault(); 328 else 329 load(); 330 } catch (final IOException e1) { 331 e1.printStackTrace(); 332 String backup = getPreferencesDir() + "preferences.bak"; 333 JOptionPane.showMessageDialog(null, tr("Preferences file had errors. Making backup of old one to {0}.", backup)); 334 new File(getPreferencesDir() + "preferences").renameTo(new File(backup)); 335 save(); 336 } 304 337 } 305 338 … … 448 481 /* handle space separated stuff - remove in future */ 449 482 else if(s.indexOf(' ') >= 0) 450 return Arrays.asList(s.split(" ,"));483 return Arrays.asList(s.split(" ")); 451 484 else 452 485 return Arrays.asList(s.split(";")); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r1286 r1326 6 6 import static org.openstreetmap.josm.tools.I18n.i18n; 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 9 8 10 9 import java.awt.EventQueue; … … 24 23 25 24 import javax.swing.JFrame; 26 import javax.swing.JOptionPane;27 25 28 26 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.plugins.Plugin Downloader;27 import org.openstreetmap.josm.plugins.PluginHandler; 30 28 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 31 29 import org.openstreetmap.josm.tools.ImageProvider; … … 67 65 */ 68 66 public static void main(final String[] argArray) { 69 ///////////////////////////////////////////////////////////////////////// 70 // TO ALL TRANSLATORS 71 ///////////////////////////////////////////////////////////////////////// 72 // Do not translate the early strings below until the locale is set up. 73 // (By the eager loaded plugins) 74 // 75 // These strings cannot be translated. That's life. Really. Sorry. 76 // 77 // Imi. 78 ///////////////////////////////////////////////////////////////////////// 67 /* try initial language settings, may be changed later again */ 68 try { i18n = I18nFactory.getI18n(MainApplication.class); } 69 catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH);} 79 70 80 71 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); … … 101 92 } 102 93 94 Main.pref.init(args.containsKey("reset-preferences")); 95 96 String localeName = null; // The locale to use 97 98 //Check if passed as parameter 99 if(args.containsKey("language")) 100 localeName = (String)(args.get("language").toArray()[0]); 101 102 if (localeName == null) 103 localeName = Main.pref.get("language", null); 104 105 if (localeName != null) { 106 Locale l; 107 Locale d = Locale.getDefault(); 108 if(localeName.equals("he")) localeName = "iw_IL"; 109 int i = localeName.indexOf('_'); 110 if (i > 0) { 111 l = new Locale(localeName.substring(0, i), localeName.substring(i + 1)); 112 } else { 113 l = new Locale(localeName); 114 } 115 try { 116 Locale.setDefault(l); 117 i18n = I18nFactory.getI18n(MainApplication.class); 118 } catch (MissingResourceException ex) { 119 if(!l.getLanguage().equals("en")) 120 { 121 System.out.println(tr("Unable to find translation for the locale {0}. Reverting to {1}.", 122 l.getDisplayName(), d.getDisplayName())); 123 Locale.setDefault(d); 124 } 125 } 126 } 127 103 128 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) { 104 129 // TODO: put in a platformHook for system that have no console by default … … 122 147 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+ 123 148 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+ 124 125 149 tr("Parameters are read in the order they are specified, so make sure you load\n"+ 126 150 "some data before --selection")+"\n\n"+ … … 129 153 } 130 154 131 // get the preferences.132 final File prefDir = new File(Main.pref.getPreferencesDir());133 if (prefDir.exists()) {134 if(!prefDir.isDirectory()) {135 JOptionPane.showMessageDialog(null, tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir()));136 return;137 }138 }139 else140 prefDir.mkdirs();141 142 if (!new File(Main.pref.getPreferencesDir()+"preferences").exists()) {143 Main.pref.resetToDefault();144 }145 146 try {147 if (args.containsKey("reset-preferences")) {148 Main.pref.resetToDefault();149 } else {150 Main.pref.load();151 }152 } catch (final IOException e1) {153 e1.printStackTrace();154 String backup = Main.pref.getPreferencesDir() + "preferences.bak";155 JOptionPane.showMessageDialog(null, tr("Preferences file had errors. Making backup of old one to {0}.", backup));156 new File(Main.pref.getPreferencesDir() + "preferences").renameTo(new File(backup));157 Main.pref.save();158 }159 160 String localeName = null; //The locale to use161 162 //Check if passed as parameter163 if(args.containsKey("language"))164 localeName = (String)(args.get("language").toArray()[0]);165 166 if (localeName == null) {167 localeName = Main.pref.get("language", null);168 }169 170 if (localeName != null) {171 if(localeName.equals("he")) localeName = "iw_IL";172 Locale l;173 int i = localeName.indexOf('_');174 if (i > 0) {175 l = new Locale(localeName.substring(0, i), localeName.substring(i + 1));176 } else {177 l = new Locale(localeName);178 }179 Locale.setDefault(l);180 }181 try {182 i18n = I18nFactory.getI18n(MainApplication.class);183 } catch (MissingResourceException ex) {184 if(!Locale.getDefault().getLanguage().equals("en"))185 {186 System.out.println("Unable to find translation for the locale: "187 + Locale.getDefault().getDisplayName() + " reverting to English.");188 Locale.setDefault(Locale.ENGLISH);189 }190 }191 192 155 SplashScreen splash = new SplashScreen(Main.pref.getBoolean("draw.splashscreen", true)); 193 156 194 157 splash.setStatus(tr("Activating updated plugins")); 195 if (!PluginDownloader.moveUpdatedPlugins()) { 196 JOptionPane.showMessageDialog(null, 197 tr("Activating the updated plugins failed. Check if JOSM has the permission to overwrite the existing ones."), 198 tr("Plugins"), JOptionPane.ERROR_MESSAGE); 199 } 158 PluginHandler.earlyCleanup(); 200 159 201 // load the early plugins202 160 splash.setStatus(tr("Loading early plugins")); 203 Main.loadPlugins(true);161 PluginHandler.loadPlugins(true); 204 162 205 163 splash.setStatus(tr("Setting defaults")); … … 210 168 final Main main = new MainApplication(mainFrame, splash); 211 169 splash.setStatus(tr("Loading plugins")); 212 Main.loadPlugins(false);170 PluginHandler.loadPlugins(false); 213 171 toolbar.refreshToolbarControl(); 214 172 -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r1307 r1326 30 30 import org.openstreetmap.josm.data.Bounds; 31 31 import org.openstreetmap.josm.gui.MapView; 32 import org.openstreetmap.josm.plugins.Plugin Proxy;32 import org.openstreetmap.josm.plugins.PluginHandler; 33 33 import org.openstreetmap.josm.tools.GBC; 34 34 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … 107 107 108 108 // add selections from plugins 109 for (PluginProxy p : Main.plugins) { 110 p.addDownloadSelection(downloadSelections); 111 } 109 PluginHandler.addDownloadSelection(downloadSelections); 112 110 113 111 // now everybody may add their tab to the tabbed pane -
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r1212 r1326 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn;6 5 7 6 import java.awt.Dimension; 8 import java.awt.GridBagConstraints;9 7 import java.awt.GridBagLayout; 10 import java.awt.Insets;11 8 import java.awt.Rectangle; 12 9 import java.awt.event.ActionEvent; 13 10 import java.awt.event.ActionListener; 14 import java.io.File;15 import java.io.FileReader;16 import java.io.IOException;17 import java.util.Arrays;18 11 import java.util.Collection; 19 import java.util.Collections;20 import java.util.Comparator;21 import java.util.HashMap;22 import java.util.HashSet;23 12 import java.util.LinkedList; 24 import java.util.Map;25 import java.util.Set;26 import java.util.SortedMap;27 import java.util.TreeMap;28 import java.util.Map.Entry;29 13 30 14 import javax.swing.AbstractAction; 31 import javax.swing.BorderFactory;32 15 import javax.swing.DefaultListModel; 33 16 import javax.swing.JButton; 34 import javax.swing.JCheckBox;35 import javax.swing.JEditorPane;36 17 import javax.swing.JLabel; 37 18 import javax.swing.JList; … … 40 21 import javax.swing.JScrollPane; 41 22 import javax.swing.Scrollable; 42 import javax.swing.UIManager;43 import javax.swing.event.HyperlinkEvent;44 import javax.swing.event.HyperlinkListener;45 import javax.swing.event.HyperlinkEvent.EventType;46 23 47 24 import org.openstreetmap.josm.Main; 48 25 import org.openstreetmap.josm.plugins.PluginDownloader; 49 import org.openstreetmap.josm.plugins.PluginException; 50 import org.openstreetmap.josm.plugins.PluginInformation; 51 import org.openstreetmap.josm.plugins.PluginProxy; 26 import org.openstreetmap.josm.plugins.PluginSelection; 52 27 import org.openstreetmap.josm.tools.GBC; 53 import org.openstreetmap.josm.tools.OpenBrowser;54 import org.openstreetmap.josm.tools.XmlObjectParser.Uniform;55 28 56 29 public class PluginPreference implements PreferenceSetting { 57 30 58 /**59 * Only the plugin name, its jar location and the description.60 * In other words, this is the minimal requirement the plugin preference page61 * needs to show the plugin as available62 *63 * @author imi64 */65 public static class PluginDescription implements Comparable<Object> {66 // Note: All the following need to be public instance variables of67 // type String. (Plugin description XMLs from the server are parsed68 // with tools.XmlObjectParser, which uses reflection to access them.)69 public String name;70 public String description;71 public String resource;72 public String version;73 public PluginDescription(String name, String description, String resource, String version) {74 this.name = name;75 this.description = description;76 this.resource = resource;77 this.version = version;78 }79 public PluginDescription() {80 }81 public int compareTo(Object n) {82 if(n instanceof PluginDescription)83 return name.compareToIgnoreCase(((PluginDescription)n).name);84 return -1;85 }86 }87 88 private Map<String, Boolean> pluginMap;89 private Map<String, PluginDescription> availablePlugins;90 31 private JPanel plugin; 91 32 private JPanel pluginPanel = new NoHorizontalScrollPanel(new GridBagLayout()); 92 33 private PreferenceDialog gui; 93 34 private JScrollPane pluginPane; 35 private PluginSelection selection = new PluginSelection(); 94 36 95 37 public void addGui(final PreferenceDialog gui) { … … 103 45 morePlugins.addActionListener(new ActionListener(){ 104 46 public void actionPerformed(ActionEvent e) { 105 int count = PluginDownloader.downloadDescription(); 106 if (count > 0) 107 JOptionPane.showMessageDialog(Main.parent, 108 trn("Downloaded plugin information from {0} site", 109 "Downloaded plugin information from {0} sites", count, count)); 110 else 111 JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found.")); 112 refreshPluginPanel(gui); 47 selection.updateDescription(pluginPanel); 113 48 } 114 49 }); … … 118 53 update.addActionListener(new ActionListener(){ 119 54 public void actionPerformed(ActionEvent e) { 120 update(); 121 refreshPluginPanel(gui); 55 selection.update(pluginPanel); 122 56 } 123 57 }); … … 132 66 plugin.add(configureSites, GBC.std()); 133 67 134 refreshPluginPanel(gui);68 selection.drawPanel(pluginPanel); 135 69 } 136 70 … … 174 108 if (answer != JOptionPane.OK_OPTION) 175 109 return; 176 StringBuilder b = new StringBuilder(); 177 for (int i = 0; i < model.getSize(); ++i) { 178 b.append(model.getElementAt(i)); 179 if (i < model.getSize()-1) 180 b.append(" "); 181 } 182 Main.pref.put("pluginmanager.sites", b.toString()); 183 } 184 185 private void update() { 186 // refresh description 187 int num = PluginDownloader.downloadDescription(); 188 Boolean done = false; 189 refreshPluginPanel(gui); 190 191 Set<PluginDescription> toUpdate = new HashSet<PluginDescription>(); 192 StringBuilder toUpdateStr = new StringBuilder(); 193 for (PluginProxy proxy : Main.plugins) { 194 PluginDescription description = availablePlugins.get(proxy.info.name); 195 if (description != null && (description.version == null || description.version.equals("")) ? 196 (proxy.info.version != null && proxy.info.version.equals("")) : !description.version.equals(proxy.info.version)) { 197 toUpdate.add(description); 198 toUpdateStr.append(description.name+"\n"); 199 } 200 } 201 if (toUpdate.isEmpty()) { 202 JOptionPane.showMessageDialog(Main.parent, tr("All installed plugins are up to date.")); 203 done = true; 204 } else { 205 int answer = JOptionPane.showConfirmDialog(Main.parent, tr("Update the following plugins:\n\n{0}", 206 toUpdateStr.toString()), tr("Update"), JOptionPane.OK_CANCEL_OPTION); 207 if (answer == JOptionPane.OK_OPTION) { 208 PluginDownloader.update(toUpdate); 209 done = true; 210 } 211 } 212 if (done && num >= 1) 213 Main.pref.put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis())); 214 } 215 216 private void refreshPluginPanel(final PreferenceDialog gui) { 217 availablePlugins = getAvailablePlugins(); 218 Collection<String> enabledPlugins = Main.pref.getCollection("plugins", null); 219 220 if (pluginMap == null) 221 pluginMap = new HashMap<String, Boolean>(); 222 else 223 // Keep the map in bounds; possibly slightly pointless. 224 for (final String pname : pluginMap.keySet()) 225 if (availablePlugins.get(pname) == null) pluginMap.remove(pname); 226 227 pluginPanel.removeAll(); 228 229 GridBagConstraints gbc = new GridBagConstraints(); 230 gbc.gridx = 0; 231 gbc.anchor = GridBagConstraints.NORTHWEST; 232 233 int row = 0; 234 for (final PluginDescription plugin : availablePlugins.values()) { 235 boolean enabled = (enabledPlugins != null) && enabledPlugins.contains(plugin.name); 236 if (pluginMap.get(plugin.name) == null) 237 pluginMap.put(plugin.name, enabled); 238 239 String remoteversion = plugin.version; 240 if ((remoteversion == null) || remoteversion.equals("")) 241 remoteversion = tr("unknown"); 242 243 String localversion; 244 PluginInformation p = PluginInformation.findPlugin(plugin.name); 245 if (p != null) { 246 if (p.version != null && !p.version.equals("")) 247 localversion = p.version; 248 else 249 localversion = tr("unknown"); 250 localversion = " (" + localversion + ")"; 251 } else 252 localversion = ""; 253 254 final JCheckBox pluginCheck = new JCheckBox( 255 tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion), 256 pluginMap.get(plugin.name)); 257 gbc.gridy = row++; 258 gbc.insets = new Insets(5,5,0,5); 259 gbc.weighty = 0.1; 260 gbc.fill = GridBagConstraints.NONE; 261 pluginPanel.add(pluginCheck, gbc); 262 263 pluginCheck.setToolTipText(plugin.resource != null ? ""+plugin.resource : tr("Plugin bundled with JOSM")); 264 265 JEditorPane description = new JEditorPane(); 266 description.setContentType("text/html"); 267 description.setEditable(false); 268 description.setText("<html><i>"+(plugin.description==null?tr("no description available"):plugin.description)+"</i></html>"); 269 description.setBorder(BorderFactory.createEmptyBorder(0,20,0,0)); 270 description.setBackground(UIManager.getColor("Panel.background")); 271 description.addHyperlinkListener(new HyperlinkListener() { 272 public void hyperlinkUpdate(HyperlinkEvent e) { 273 if(e.getEventType() == EventType.ACTIVATED) { 274 OpenBrowser.displayUrl(e.getURL().toString()); 275 } 276 } 277 }); 278 279 gbc.gridy = row++; 280 gbc.insets = new Insets(3,5,5,5); 281 gbc.weighty = 0.9; 282 gbc.weightx = 1.0; 283 gbc.anchor = GridBagConstraints.WEST; 284 gbc.fill = GridBagConstraints.HORIZONTAL; 285 pluginPanel.add(description, gbc); 286 287 pluginCheck.addActionListener(new ActionListener(){ 288 public void actionPerformed(ActionEvent e) { 289 // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar 290 if (pluginCheck.isSelected()) { 291 PluginInformation plinfo = PluginInformation.findPlugin(plugin.name); 292 if ((PluginInformation.getLoaded(plugin.name) == null) && (plinfo != null)) { 293 try { 294 int answer = JOptionPane.showConfirmDialog(Main.parent, 295 tr("Plugin archive already available. Do you want to download the current version by deleting existing archive?\n\n{0}", 296 plinfo.file.getCanonicalPath()), tr("Plugin already exists"), JOptionPane.OK_CANCEL_OPTION); 297 if (answer == JOptionPane.OK_OPTION) { 298 if (!plinfo.file.delete()) { 299 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath())); 300 } 301 } 302 } catch (IOException e1) { 303 e1.printStackTrace(); 304 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage())); 305 } 306 } 307 } 308 pluginMap.put(plugin.name, pluginCheck.isSelected()); 309 } 310 }); 311 } 312 plugin.updateUI(); 313 } 314 315 private Map<String, PluginDescription> getAvailablePlugins() { 316 SortedMap<String, PluginDescription> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){ 317 public int compare(String o1, String o2) { 318 return o1.compareToIgnoreCase(o2); 319 } 320 }); 321 for (String location : PluginInformation.getPluginLocations()) { 322 File[] pluginFiles = new File(location).listFiles(); 323 if (pluginFiles != null) { 324 Arrays.sort(pluginFiles); 325 for (File f : pluginFiles) { 326 if (!f.isFile()) 327 continue; 328 if (f.getName().endsWith(".jar")) { 329 try { 330 PluginInformation info = new PluginInformation(f); 331 if (!availablePlugins.containsKey(info.name)) 332 availablePlugins.put(info.name, new PluginDescription( 333 info.name, 334 info.description, 335 PluginInformation.fileToURL(f).toString(), 336 info.version)); 337 } catch (PluginException x) { 338 } 339 } else if (f.getName().matches("^[0-9]+-site.*\\.xml$")) { 340 try { 341 Uniform<PluginDescription> parser = new Uniform<PluginDescription>(new FileReader(f), "plugin", PluginDescription.class); 342 for (PluginDescription pd : parser) 343 if (!availablePlugins.containsKey(pd.name)) 344 availablePlugins.put(pd.name, pd); 345 } catch (Exception e) { 346 e.printStackTrace(); 347 JOptionPane.showMessageDialog(Main.parent, tr("Error reading plugin information file: {0}", f.getName())); 348 } 349 } 350 } 351 } 352 } 353 for (PluginProxy proxy : Main.plugins) 354 if (!availablePlugins.containsKey(proxy.info.name)) 355 availablePlugins.put(proxy.info.name, new PluginDescription( 356 proxy.info.name, 357 proxy.info.description, 358 proxy.info.file == null ? null : 359 PluginInformation.fileToURL(proxy.info.file).toString(), 360 proxy.info.version)); 361 return availablePlugins; 110 Collection<String> sites = new LinkedList<String>(); 111 for (int i = 0; i < model.getSize(); ++i) 112 sites.add((String)model.getElementAt(i)); 113 PluginDownloader.setSites(sites); 362 114 } 363 115 364 116 public boolean ok() { 365 Collection<PluginDescription> toDownload = new LinkedList<PluginDescription>(); 366 String msg = ""; 367 for (Entry<String, Boolean> entry : pluginMap.entrySet()) { 368 if (entry.getValue() && PluginInformation.findPlugin(entry.getKey()) == null) { 369 toDownload.add(availablePlugins.get(entry.getKey())); 370 msg += entry.getKey() + "\n"; 371 } 372 } 373 if (!toDownload.isEmpty()) { 374 int answer = JOptionPane.showConfirmDialog(Main.parent, 375 tr("Download the following plugins?\n\n{0}", msg), 376 tr("Download missing plugins"), 377 JOptionPane.YES_NO_OPTION); 378 if (answer != JOptionPane.OK_OPTION) 379 for (PluginDescription pd : toDownload) 380 pluginMap.put(pd.name, false); 381 else 382 for (PluginDescription pd : toDownload) 383 if (!PluginDownloader.downloadPlugin(pd)) 384 pluginMap.put(pd.name, false); 117 return selection.finish(); 118 } 385 119 386 }387 LinkedList<String> plugins = new LinkedList<String>();388 for (Map.Entry<String, Boolean> d : pluginMap.entrySet()) {389 if (d.getValue())390 plugins.add(d.getKey());391 }392 393 Collections.sort(plugins);394 return Main.pref.putCollection("plugins", plugins);395 }396 397 120 class NoHorizontalScrollPanel extends JPanel implements Scrollable { 398 121 public NoHorizontalScrollPanel(GridBagLayout gridBagLayout) { -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r1180 r1326 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.plugins.PluginProxy; 24 import org.openstreetmap.josm.plugins.PluginHandler; 25 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 25 26 import org.openstreetmap.josm.tools.GBC; 26 27 import org.openstreetmap.josm.tools.I18n; … … 112 113 } catch (SecurityException e) { 113 114 it.remove(); 115 } catch (Throwable e) { 116 /* allow to change most settings even if e.g. a plugin fails */ 117 BugReportExceptionHandler.handleException(e); 114 118 } 115 119 } … … 133 137 settings.add(new ShortcutPreference()); 134 138 135 for (PluginProxy plugin : Main.plugins) { 136 PreferenceSetting p = plugin.getPreferenceSetting(); 137 if (p != null) 138 settings.add(p); 139 } 139 PluginHandler.getPreferenceSetting(settings); 140 140 141 141 // always the last: advanced tab -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r1212 r1326 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 31 import org.openstreetmap.josm.gui.preferences.PluginPreference.PluginDescription;32 31 import org.xml.sax.SAXException; 33 32 … … 76 75 public static Collection<String> getSites() { 77 76 return Main.pref.getCollection("pluginmanager.sites", Arrays.asList(pluginSites)); 77 } 78 public static void setSites(Collection<String> c) { 79 Main.pref.putCollection("pluginmanager.sites", c); 78 80 } 79 81 -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r1169 r1326 34 34 public final String mainversion; 35 35 public final String className; 36 public final String requires; 36 37 public final String description; 37 38 public final boolean early; … … 77 78 Attributes attr = manifest.getMainAttributes(); 78 79 className = attr.getValue("Plugin-Class"); 80 requires = attr.getValue("Plugin-Requires"); 79 81 description = attr.getValue("Plugin-Description"); 80 82 early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); … … 107 109 early = false; 108 110 stage = 50; 111 requires = null; 109 112 version = null; 110 113 author = null; … … 215 218 return all; 216 219 } 217 218 219 /**220 * Return information about a loaded plugin.221 *222 * Note that if you call this in your plugins bootstrap, you may get <code>null</code> if223 * the plugin requested is not loaded yet.224 *225 * @return The PluginInformation to a specific plugin, but only if the plugin is loaded.226 * If it is not loaded, <code>null</code> is returned.227 */228 public static PluginInformation getLoaded(String pluginName) {229 for (PluginProxy p : Main.plugins)230 if (p.info.name.equals(pluginName))231 return p.info;232 return null;233 }234 220 } 235 221 -
trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java
r1169 r1326 7 7 import org.openstreetmap.josm.gui.download.DownloadSelection; 8 8 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 9 9 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 10 10 11 11 /** … … 31 31 } catch (NoSuchMethodException e) { 32 32 } catch (Exception e) { 33 throw new PluginException(this, info.name, e);33 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e)); 34 34 } 35 35 } … … 41 41 return null; 42 42 } catch (Exception e) { 43 throw new PluginException(this, info.name, e);43 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e)); 44 44 } 45 return null; 45 46 } 46 47 … … 51 52 // ignore 52 53 } catch (Exception e) { 53 throw new PluginException(this, info.name, e);54 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e)); 54 55 } 55 56 } -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r1271 r1326 30 30 import org.openstreetmap.josm.Main; 31 31 import org.openstreetmap.josm.actions.AboutAction; 32 import org.openstreetmap.josm.plugins.PluginException; 33 import org.openstreetmap.josm.plugins.PluginProxy; 32 import org.openstreetmap.josm.plugins.PluginHandler; 34 33 35 34 /** … … 41 40 42 41 public void uncaughtException(Thread t, Throwable e) { 42 handleException(e); 43 } 44 public static void handleException(Throwable e) { 43 45 e.printStackTrace(); 44 46 if (Main.parent != null) { … … 52 54 } 53 55 54 PluginProxy plugin = null; 55 56 // Check for an explicit problem when calling a plugin function 57 if (e instanceof PluginException) 58 plugin = ((PluginException)e).plugin; 59 60 if (plugin == null) 61 plugin = guessPlugin(e); 62 63 if (plugin != null) { 64 int answer = JOptionPane.showConfirmDialog( 65 Main.parent, tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", 66 plugin.info.name) + "\n"+ (plugin.info.author != null ? 67 tr("According to the information within the plugin, the author is {0}.", 68 plugin.info.author) : "") + "\n" + 69 tr("Try updating to the newest version of this plugin before reporting a bug.") + "\n" + 70 tr("Should the plugin be disabled?"), 71 tr("Disable plugin"), 72 JOptionPane.YES_NO_OPTION); 73 if (answer == JOptionPane.OK_OPTION) { 74 LinkedList<String> plugins = new LinkedList<String>(Arrays.asList(Main.pref.get("plugins").split(","))); 75 if (plugins.contains(plugin.info.name)) { 76 while (plugins.remove(plugin.info.name)) {} 77 String p = ""; 78 for (String s : plugins) 79 p += ","+s; 80 if (p.length() > 0) 81 p = p.substring(1); 82 Main.pref.put("plugins", p); 83 JOptionPane.showMessageDialog(Main.parent, 84 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin.")); 85 } else { 86 JOptionPane.showMessageDialog(Main.parent, 87 tr("The plugin could not be removed. Please tell the people you got JOSM from about the problem.")); 88 } 89 return; 90 } 91 } 56 if(PluginHandler.checkException(e)) 57 return; 92 58 93 59 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; … … 103 69 104 70 String text = AboutAction.getTextBlock(); 105 String pl = Main.pref.get("plugins");106 71 text += "Java version: " + System.getProperty("java.version")+"\n"; 107 if(pl != null && pl.length() != 0) 108 text += "Plugins: "+pl+"\n"; 109 for (final PluginProxy pp : Main.plugins) { 110 text += "Plugin " + pp.info.name + (pp.info.version != null && !pp.info.version.equals("") ? " Version: "+pp.info.version+"\n" : "\n"); 111 } 72 text += PluginHandler.getBugReportText(); 112 73 text += "\n" + stack.getBuffer().toString(); 113 74 … … 137 98 } 138 99 } 139 140 private PluginProxy guessPlugin(Throwable e) {141 String name = guessPluginName(e);142 for (PluginProxy p : Main.plugins)143 if (p.info.name.equals(name))144 return p;145 return null;146 }147 148 /**149 * Analyze the stack of the argument and return a name of a plugin, if150 * some known problem pattern has been found or <code>null</code>, if151 * the stack does not contain plugin-code.152 *153 * Note: This heuristic is not meant as discrimination against specific154 * plugins, but only to stop the flood of similar bug reports about plugins.155 * Of course, plugin writers are free to install their own version of156 * an exception handler with their email address listed to receive157 * bug reports ;-).158 */159 private String guessPluginName(Throwable e) {160 for (StackTraceElement element : e.getStackTrace()) {161 String c = element.getClassName();162 163 if (c.contains("wmsplugin.") || c.contains(".WMSLayer"))164 return "wmsplugin";165 if (c.contains("livegps."))166 return "livegps";167 if (c.startsWith("UtilsPlugin."))168 return "UtilsPlugin";169 170 if (c.startsWith("org.openstreetmap.josm.plugins.")) {171 String p = c.substring("org.openstreetmap.josm.plugins.".length());172 if (p.indexOf('.') != -1 && p.matches("[a-z].*")) {173 return p.substring(0,p.indexOf('.'));174 }175 }176 }177 return null;178 }179 100 }
Note:
See TracChangeset
for help on using the changeset viewer.