Changes between Version 38 and Version 39 of DevelopersGuide/DevelopingPlugins
- Timestamp:
- 2010-01-12T19:31:16+01:00 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevelopersGuide/DevelopingPlugins
v38 v39 18 18 * If you need other OSM resources you can check out the complete osm - trunk: {{{svn co http://svn.openstreetmap.org/}}} 19 19 20 == The ''Plugin'' class == 21 After setting everything up, you need to create the plugin main class specified in the jar's manifest. The only prerequisite of this class is, that it must have a standard constructor taking no arguments. The constructor of the plugin class will be called during the JOSM startup if the plugin is registered. Here, you have full access to the object tree within JOSM. 20 == JOSM plugins == 22 21 23 It is recommended (but not required), that you subclass org.openstreetmap.josm.plugins.Plugin. This way you get some helper functions and always have the latest callback function signatures (see below) as hints in your baseclass to override them ;) 22 === A POJO as entry point === 24 23 25 The required minimum in naming is one individual part in the path structure of you plugin class names. The path of the base class is used to detect the source of exceptions. So when you base class is my.example.class.MyPlugin, then "my.example.class" is used to detect your plugin code. All important parts of your plugin should use that and also it should be unique for the plugin (i.e. add at least one part with the name of your plugin). 24 The entry point for a JOSM plugin, the '''plugin main class''' is a Plain Old Java Object (POJO) which provides a constructor with one parameter of type [source:/trunk/src/org/openstreetmap/josm/plugin/PluginInformation.java PluginInformation]. 25 {{{ 26 #!java 27 public class MyPlugin { 28 /** 29 * Will be invoked by JOSM to bootstrap the plugin 30 * 31 * @param info information about the plugin and its local installation 32 */ 33 public MyPlugin(PluginInformation info) { 34 } 26 35 27 == Callbacks == 36 /* ... */ 37 } 38 }}} 39 40 You don't have to derive the plugin main class from a common superclass but currently you are '''recommended''' to derive it from [source:/trunk/src/org/openstreetmap/josm/plugin/Plugin.java org.openstreetmap.josm.plugin.Plugin]. 41 42 {{{ 43 #!java 44 import org.openstreetmap.josm.plugin.Plugin; 45 import org.openstreetmap.josm.plugin.PluginInformation; 46 47 public class MyPlugin extends Plugin { 48 49 /** 50 * Will be invoked by JOSM to bootstrap the plugin 51 * 52 * @param info information about the plugin and its local installation 53 */ 54 public MyPlugin(PluginInformation info) extends Plugin { 55 super(info); 56 // init your plugin 57 } 58 } 59 }}} 60 61 For legacy reasons, JOSM currently also allows POJOs with a no-arg constructor as plugin main classes. This approach is '''deprecated''' and will be disabled in Q2/2010. New plugins should provide a constructor with one parameter of type [source:/trunk/src/org/openstreetmap/josm/plugin/PluginInformation.java PluginInformation]. 62 63 === Naming the plugin === 64 Each plugin has a unique name to identify it. The name is a short identifier like {{{wmsplugin}}} or {{{validator}}}. 65 * '''DONT''' use white space characters in the name. Call the plugin {{{BuildingUtility}}}, not {{{Jim's Building Utitlities}}} 66 * '''DONT''' use special characters in the plugin name, stick to alphanumeric characters. Call the plugin {{{routing4all}}} not {{{routing 4 all :-) !}}}. Note that the plugin name is used to '''create file and directory names''' on the computer where plugins are installed. If it included special characters like /, ., \, etc. these operations may fail. 67 68 You are recommended to use a Java package for the plugin main class and all other classes you need in the plugin, i.e. {{{org.foobar.josm.routing4all}}}. Stick to the well-established naming conventions used in the Java world (lower case package name, camel case class names, etc.). 69 70 71 == Callbacks == #Callbacks 28 72 Most of your plugin work will probably be tweaking the JOSM object tree at startup time, but there are a few callbacks that get automatically called on every plugin (whether you subclass Plugin or not, just the signature matters). 29 73