Changeset 149 in josm for src/org/openstreetmap/josm/plugins


Ignore:
Timestamp:
2006-10-05T22:33:21+02:00 (18 years ago)
Author:
imi
Message:
  • added dynamic loading of plugins
  • removed mappaint (now seperate plugin)
  • fixed UrlLabel for Linux and Mac (untested)
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  
    11package org.openstreetmap.josm.plugins;
     2
     3import java.net.URL;
     4import java.net.URLClassLoader;
    25
    36import org.openstreetmap.josm.Main;
     
    58
    69/**
    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.
    816 *
    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.
    1121 *
    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 *
    1430 * @author Immanuel.Scholz
    1531 */
    1632public abstract class Plugin {
    1733
    18         private final String name;
     34        private String name;
    1935
    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;
    2248        }
    23 
     49        /**
     50         * @return The directory for the plugin to store all kind of stuff.
     51         */
    2452        public final String getPluginDir() {
    2553                return Main.pref.getPreferencesDir()+"plugins/"+name+"/";
    2654        }
    2755
     56       
     57
    2858        /**
    2959         * 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.
    3062         */
    3163        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
    3271}
Note: See TracChangeset for help on using the changeset viewer.