Changeset 149 in josm for src/org/openstreetmap/josm/plugins
- Timestamp:
- 2006-10-05T22:33:21+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm/plugins
- Files:
-
- 3 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.