Changes between Version 9 and Version 10 of Help/Plugin/Scripting


Ignore:
Timestamp:
2012-07-08T12:55:27+02:00 (13 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Help/Plugin/Scripting

    v9 v10  
    1515* exporting to a custom file format not supported by JOSM
    1616
    17 You can use any scripting language which provides a JSR-223 compatible scripting engine, in particular:
    18 * [http://groovy.codehaus.org/ Groovy]
    19 * [http://www.jython.org/ Python]
    20 * [http://www.mozilla.org/rhino/ JavaScript]
    21 * [http://jruby.org/ Ruby]
     17The plugin includes a embedded scripting engine for Javascript based on Mozilla Rhino and a
     18[http://gubaer.github.com/josm-scripting-plugin/content/js-doc/index.html Javascript API] for the JOSM application objects.
    2219
    23 == Configuring a Scripting Engine ==
     20Alternatively, you can use any scripting language which provides a JSR-223 compatible scripting engine, in particular
     21[http://groovy.codehaus.org/ Groovy], [http://www.jython.org/ Python], or [http://jruby.org/ Ruby].
    2422
    25 The {{{scripting}}} plugin doesn't ship with a script engine. A standard Java 6 installation should already include a JavaScript engine (Rhino).
    26 If you want to use another scripting language, you have to configure the respective script engine first:
     23Please refer to the [http://gubaer.github.com/josm-scripting-plugin/content/index.html plugin documentation] on
     24[https://github.com/gubaer/josm-scripting-plugin GitHub] for more information.
    2725
    28 1. Select the menu item '''Scripting''' -> '''Configure ...'''
    29 2. Check whether your preferred scripting engine is already configured. If not,
    30      * download the jar file providing the scripting engine
    31      * add the path to this jar file to the list of scripting engine jars
    32 
    33 == Running a Script ==
    34 
    35 1. Select the menu item '''Scripting''' -> '''Run...'''
    36 2. Enter the path to the script
    37 3. Press '''Run'''
    38 
    39 
    40 == Writing a script ==
    41 The {{{scripting}}} plugin doesn't provide a development console for scripts (yet).
    42 
    43 Use your preferred editor or development environment to write the script in your
    44 preferred language.
    45 
    46 Here are three examples which display the number of layers in JOSM. If you want to write more complex scripts you will have to get familiar with the JOSM object model and in consequence with the JOSM code base, because there is neither an explicit scripting API nor any documentation outside of the JOSM code.
    47 
    48 === Groovy ===
    49 {{{
    50 /*
    51  * HelloWorld.groovy - displays the number of actually open layers
    52  */
    53 import javax.swing.JOptionPane;
    54 import org.openstreetmap.josm.Main;
    55 
    56 def numlayers = Main.main?.map?.mapView?.numLayers
    57 if (numlayers == null) numlayers = 0
    58 
    59 JOptionPane.showMessageDialog(Main.parent, "[Groovy] Hello World!\nYou have ${numlayers} layer(s).")
    60 }}}
    61 
    62 === JavaScript ===
    63 {{{
    64 /*
    65 * HelloWorld.js  -  displays the number of currently open layers
    66 */
    67 importClass(Packages.javax.swing.JOptionPane)
    68 importClass(Packages.org.openstreetmap.josm.Main)
    69 
    70 function getMapView() {
    71         if (Main.main == null) return null
    72         if (Main.main.map == null) return null
    73         return Main.main.map.mapView
    74 }
    75 
    76 var numlayers = 0
    77 var mv = getMapView()
    78 if (mv != null){
    79         numlayers = mv.getNumLayers()
    80 }
    81 JOptionPane.showMessageDialog(Main.parent, "[JavaScript] Hello World! You have " + numlayers + " layer(s).")
    82 }}}
    83 
    84 === Python ===
    85 {{{
    86 #!python
    87 #
    88 # HelloWorld.py  - displays the number of currently open layers
    89 #
    90 from javax.swing import JOptionPane
    91 from org.openstreetmap.josm import Main
    92 
    93 def getMapView():
    94     if Main.main and Main.main.map:
    95         return Main.main.map.mapView
    96     else:
    97         return None
    98 
    99 numlayers = 0
    100 mv = getMapView()
    101 if mv != None:
    102         numlayers = mv.getNumLayers()
    103        
    104 JOptionPane.showMessageDialog(Main.parent, "[Python] Hello World! You have %s layer(s)." % numlayers)
    105 }}}
     26== Example scripts in Python ==
    10627
    10728Here are some more examples:
     
    11940Back to [wiki:/Help Main Help]
    12041
    121 
    122