Changeset 25083 in osm


Ignore:
Timestamp:
2011-01-16T19:47:42+01:00 (14 years ago)
Author:
guggis
Message:

Updated sample scripts

Location:
applications/editors/josm/plugins/scripting/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/scripting/scripts/HelloWorld.groovy

    r25071 r25083  
     1/*
     2 * HelloWorld.groovy - displays the number of actually open layers
     3 */
    14import javax.swing.JOptionPane;
    25import org.openstreetmap.josm.Main;
    36
     7def numlayers = Main.main?.map?.mapView?.numLayers
     8if (numlayers == null) numlayers = 0
    49
    5 JOptionPane.showMessageDialog(Main.parent, "[Groovy] Hello World!")
     10JOptionPane.showMessageDialog(Main.parent, "[Groovy] Hello World!\nYou have ${numlayers} layer(s).")
  • applications/editors/josm/plugins/scripting/scripts/HelloWorld.js

    r25072 r25083  
    11/*
    2 * HelloWorld.js  -  sample JOSM script in JavaScript
     2* HelloWorld.js  -  displays the number of actually open layers
    33*/
    44importClass(Packages.javax.swing.JOptionPane)
    55importClass(Packages.org.openstreetmap.josm.Main)
    66
    7 JOptionPane.showMessageDialog(Main.parent, "[JavaScript] Hello World!")
     7function getMapView() {
     8        if (Main.main == null) return null
     9        if (Main.main.map == null) return null
     10        return Main.main.map.mapView
     11}
     12
     13var numlayers = 0
     14var mv = getMapView()
     15if (mv != null){
     16        numlayers = mv.getNumLayers()
     17}
     18JOptionPane.showMessageDialog(Main.parent, "[JavaScript] Hello World! You have " + numlayers + " layer(s).")
     19
  • applications/editors/josm/plugins/scripting/scripts/HelloWorld.py

    r25072 r25083  
    11#
    2 # HelloWorld.py  -  sample JOSM script in Python
     2# HelloWorld.py  - displays the number of actually open layers
    33#
    44from javax.swing import JOptionPane
    55from org.openstreetmap.josm import Main
    66
    7 JOptionPane.showMessageDialog(Main.parent, "[Python] Hello World!")
     7def getMapView():
     8        if Main.main == None:
     9                return None
     10        if Main.main.map == None:
     11                return None
     12        return Main.main.map.mapView
     13
     14
     15numlayers = 0
     16mv = getMapView()
     17if mv != None:
     18        numlayers = mv.getNumLayers()
     19       
     20JOptionPane.showMessageDialog(Main.parent, "[Python] Hello World! You have %s layer(s)." % numlayers)
Note: See TracChangeset for help on using the changeset viewer.