- Timestamp:
- 2006-10-05T22:33:21+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 3 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r146 r149 57 57 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 58 58 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 59 import org.openstreetmap.josm.plugins.Plugin; 59 import org.openstreetmap.josm.plugins.PluginException; 60 import org.openstreetmap.josm.plugins.PluginLoader; 61 import org.openstreetmap.josm.plugins.PluginProxy; 60 62 import org.openstreetmap.josm.tools.ImageProvider; 61 63 … … 94 96 * All installed and loaded plugins (resp. their main classes) 95 97 */ 96 public final Collection<Plugin> plugins = new LinkedList<Plugin>(); 98 public final static Collection<PluginProxy> plugins = new LinkedList<PluginProxy>(); 97 99 98 100 /** … … 127 129 redoUndoListener.commandChanged(0,0); 128 130 129 for (Plugin plugin : plugins) 130 131 for (PluginProxy plugin : plugins) 132 plugin.mapFrameInitialized(old, map); 131 133 } 132 134 … … 248 250 contentPane.updateUI(); 249 251 252 250 253 // Plugins 251 if (pref.hasKey("plugins")) { 252 for (String pluginName : pref.get("plugins").split(",")) { 254 if (Main.pref.hasKey("plugins")) { 255 PluginLoader loader = new PluginLoader(); 256 for (String pluginName : Main.pref.get("plugins").split(",")) { 253 257 try { 254 plugins.add((Plugin)Class.forName(pluginName).newInstance()); 255 } catch (Exception e) { 256 e.printStackTrace(); 257 JOptionPane.showMessageDialog(parent, tr("Could not load plugin {0}.", pluginName)); 258 } 258 File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar"); 259 if (pluginFile.exists()) 260 plugins.add(loader.loadPlugin(loader.loadClassName(pluginFile), pluginFile)); 261 else 262 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 263 } catch (PluginException e) { 264 e.printStackTrace(); 265 JOptionPane.showMessageDialog(Main.parent, tr("Could not load plugin {0}.", pluginName)); 266 } 259 267 } 260 268 } -
src/org/openstreetmap/josm/data/Preferences.java
r137 r149 47 47 } 48 48 49 synchronized finalpublic boolean hasKey(final String key) {49 synchronized public boolean hasKey(final String key) { 50 50 return properties.containsKey(key); 51 51 } 52 synchronized finalpublic String get(final String key) {52 synchronized public String get(final String key) { 53 53 if (!properties.containsKey(key)) 54 54 return ""; 55 55 return properties.get(key); 56 56 } 57 synchronized finalpublic String get(final String key, final String def) {57 synchronized public String get(final String key, final String def) { 58 58 final String prop = properties.get(key); 59 59 if (prop == null || prop.equals("")) … … 61 61 return prop; 62 62 } 63 synchronized finalpublic Map<String, String> getAllPrefix(final String prefix) {63 synchronized public Map<String, String> getAllPrefix(final String prefix) { 64 64 final Map<String,String> all = new TreeMap<String,String>(); 65 65 for (final Entry<String,String> e : properties.entrySet()) … … 68 68 return all; 69 69 } 70 synchronized finalpublic boolean getBoolean(final String key) {70 synchronized public boolean getBoolean(final String key) { 71 71 return getBoolean(key, false); 72 72 } 73 synchronized finalpublic boolean getBoolean(final String key, final boolean def) {73 synchronized public boolean getBoolean(final String key, final boolean def) { 74 74 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def; 75 75 } 76 76 77 77 78 synchronized finalpublic void put(final String key, final String value) {78 synchronized public void put(final String key, final String value) { 79 79 if (value == null) 80 80 properties.remove(key); … … 84 84 firePreferenceChanged(key, value); 85 85 } 86 synchronized finalpublic void put(final String key, final boolean value) {86 synchronized public void put(final String key, final boolean value) { 87 87 properties.put(key, Boolean.toString(value)); 88 88 save(); -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r134 r149 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.ActionListener; 12 import java.io.File; 13 import java.util.Collection; 14 import java.util.HashMap; 15 import java.util.HashSet; 12 16 import java.util.Locale; 13 17 import java.util.Map; … … 44 48 import org.openstreetmap.josm.Main; 45 49 import org.openstreetmap.josm.data.projection.Projection; 50 import org.openstreetmap.josm.plugins.PluginProxy; 46 51 import org.openstreetmap.josm.tools.ColorHelper; 47 52 import org.openstreetmap.josm.tools.GBC; 48 53 import org.openstreetmap.josm.tools.ImageProvider; 54 import org.openstreetmap.josm.tools.UrlLabel; 49 55 50 56 /** … … 190 196 private JComboBox projectionCombo = new JComboBox(Projection.allProjections); 191 197 private JList annotationSources = new JList(new DefaultListModel()); 198 private Map<PluginProxy, Boolean> pluginMap = new HashMap<PluginProxy, Boolean>(); 192 199 193 200 … … 268 275 ((DefaultListModel)annotationSources.getModel()).addElement(st.nextToken()); 269 276 270 277 Box pluginPanel = Box.createVerticalBox(); 278 Collection<String> availablePlugins = new HashSet<String>(); 279 for (File f : new File(Main.pref.getPreferencesDir()+"plugins").listFiles()) { 280 if (!f.isFile() || !f.getName().endsWith(".jar")) 281 continue; 282 availablePlugins.add(f.getName().substring(0, f.getName().length()-4)); 283 } 284 for (PluginProxy plugin : Main.plugins) { 285 boolean available = availablePlugins.contains(plugin.name); 286 JCheckBox pluginCheck = new JCheckBox(plugin.name, available); 287 String desc = plugin.getDescription(); 288 pluginPanel.add(pluginCheck); 289 if (desc != null) { 290 pluginCheck.setToolTipText(desc); 291 JLabel label = new JLabel("<html><i>"+desc+"</i></html>"); 292 label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0)); 293 pluginPanel.add(label); 294 pluginPanel.add(Box.createVerticalStrut(5)); 295 } 296 pluginMap.put(plugin, available); 297 } 298 JScrollPane pluginPane = new JScrollPane(pluginPanel); 299 pluginPane.setBorder(null); 300 271 301 Map<String,String> allColors = new TreeMap<String, String>(Main.pref.getAllPrefix("color.")); 272 302 … … 436 466 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 437 467 468 469 // Plugin tab 470 JPanel plugin = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins.")); 471 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH)); 472 plugin.add(GBC.glue(0,10), GBC.eol()); 473 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std()); 438 474 439 475 tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); … … 467 503 private JPanel createPreferenceTab(String icon, String title, String desc) { 468 504 JPanel p = new JPanel(new GridBagLayout()); 505 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 469 506 p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10)); 470 507 -
src/org/openstreetmap/josm/plugins/Plugin.java
r145 r149 1 1 package org.openstreetmap.josm.plugins; 2 3 import java.net.URL; 4 import java.net.URLClassLoader; 2 5 3 6 import org.openstreetmap.josm.Main; … … 5 8 6 9 /** 7 * All plugins must have at least one class implementing this interface. 10 * All plugins *must* have an standard constructor taking no arguments. 11 * This constructor is called at JOSM startup, after all Main-objects have been initialized. 12 * For all purposes of loading dynamic resources, the Plugin's class loader should be used 13 * (or else, the plugin jar will not be within the class path). 14 * 15 * All plugins should have at least one class subclassing this abstract base class. 8 16 * 9 * All plugins must have an default constructor (taking no arguments). This constructor 10 * is called at JOSM startup, after all Main-objects have been initialized. 17 * The actual implementation of this interface is optional, as all functions will be called 18 * via reflection. This is to be able to change this interface without the need of recompiling 19 * or even breaking the plugins. If your class does not provide a function here (or does 20 * provide a function with a mismatching signature), it will not be called. That simple. 11 21 * 12 * The pluginname is also the name of the directory to store the plugin's 13 * own stuff (located under the josm preferences directory) 22 * Or in other words: See this base class as an documentation of what functions are provided. 23 * Subclassing it and overriding some functions makes it easy for you to keep sync with the 24 * correct actual plugin architecture of JOSM. 25 * 26 * 27 * The pluginname provided to the constructor is also the name of the directory to 28 * store the plugin's own stuff (located under the josm preferences directory) 29 * 14 30 * @author Immanuel.Scholz 15 31 */ 16 32 public abstract class Plugin { 17 33 18 private finalString name;34 private String name; 19 35 20 public Plugin(String pluginName) { 21 this.name = pluginName; 36 public Plugin() { 37 URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs(); 38 String s = urls[urls.length-1].toString(); 39 int lastSlash = s.lastIndexOf('/'); 40 name = s.substring(lastSlash+1, s.length()-4); 41 } 42 43 /** 44 * @return The name of this plugin. This is the name of the .jar file. 45 */ 46 public final String getName() { 47 return name; 22 48 } 23 49 /** 50 * @return The directory for the plugin to store all kind of stuff. 51 */ 24 52 public final String getPluginDir() { 25 53 return Main.pref.getPreferencesDir()+"plugins/"+name+"/"; 26 54 } 27 55 56 57 28 58 /** 29 59 * Called after Main.mapFrame is initalized. (After the first data is loaded). 60 * You can use this callback to tweak the newFrame to your needs, as example install 61 * an alternative Painter. 30 62 */ 31 63 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {} 64 65 /** 66 * Called to retrieve a one-liner description of what this plugin does for tooltips. 67 * @return <code>null</code>, which means: "no description available". 68 */ 69 public String getDescription() {return null;} 70 32 71 } -
src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r113 r149 21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.plugins.PluginException; 24 import org.openstreetmap.josm.plugins.PluginProxy; 23 25 24 26 /** … … 35 37 JOptionPane.showMessageDialog(Main.parent, "You are out of memory. Strange things may happen.\nPlease restart JOSM and load smaller data sets."); 36 38 return; 39 } 40 41 if (e instanceof PluginException) { 42 PluginProxy plugin = ((PluginException)e).getPlugin(); 43 if (plugin != null && !plugin.misbehaving) { 44 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} throwed an exception: {1}\nIt may be outdated. Please contact the plugin's autor.\nThis message will not shown again until JOSM is restarted.", plugin.name, e.getMessage())); 45 plugin.misbehaving = true; 46 return; 47 } 37 48 } 38 49 -
src/org/openstreetmap/josm/tools/OpenBrowser.java
r69 r149 14 14 public static String displayUrl(String url) { 15 15 String os = System.getProperty("os.name"); 16 if (os == null) 17 return "unknown operating system"; 16 18 try { 17 19 if (os != null && os.startsWith("Windows")) 18 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); 19 else { 20 //... 21 } 20 windows(url); 21 else if (os.equals("Linux") || os.equals("Solaris") || os.equals("SunOS") || os.equals("AIX") || os.equals("FreeBSD")) 22 linux(url); 23 else if (os.equals("Mac OS") || os.equals("Mac OS X")) 24 mac(url); 25 else 26 return "unknown operating system"; 22 27 } catch (IOException e) { 23 28 return e.getMessage(); … … 25 30 return null; 26 31 } 32 33 private static void windows(String url) throws IOException { 34 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); 35 } 36 37 private static void linux(String url) throws IOException { 38 try { 39 Runtime.getRuntime().exec("gnome-open " + url); 40 } catch (IOException e) { 41 Runtime.getRuntime().exec("kfmclient openURL " + url); 42 } 43 } 44 45 private static void mac(String url) throws IOException { 46 Runtime.getRuntime().exec("open " + url); 47 } 27 48 } -
src/org/openstreetmap/josm/tools/UrlLabel.java
r104 r149 14 14 15 15 public UrlLabel(String url) { 16 this (url, url); 17 } 18 19 public UrlLabel(String url, String description) { 16 20 this.url = url; 17 21 setContentType("text/html"); 18 setText("<html><a href=\""+url+"\">"+ url+"</a></html>");22 setText("<html><a href=\""+url+"\">"+description+"</a></html>"); 19 23 setEditable(false); 20 24 setOpaque(false);
Note:
See TracChangeset
for help on using the changeset viewer.