Changeset 25110 in osm for applications/editors/josm/plugins/scripting/scripts
- Timestamp:
- 2011-01-22T16:39:26+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/scripting/scripts/AddHouseNumbers.groovy
r25107 r25110 1 /* 2 * This scripts sets a sequence of consecutive house numbers on the currently selected nodes. 3 * 4 */ 5 import java.awt.event.WindowAdapter; 1 6 2 /*3 * This scripts sets a sequence of house numbers on the currently selected nodes.4 *5 * The user can enter a start number and and an increment.6 */7 7 8 8 import java.awt.BorderLayout; … … 10 10 11 11 import java.awt.event.KeyEvent; 12 import java.awt.event.WindowAdapter; 13 import java.awt.event.WindowListener; 12 14 13 15 import javax.swing.KeyStroke; 14 16 15 17 import groovy.swing.SwingBuilder; 18 import groovy.util.ProxyGenerator; 19 16 20 import javax.swing.JOptionPane; 17 21 import org.openstreetmap.josm.Main; … … 35 39 import java.awt.GridBagLayout; 36 40 import javax.swing.JLabel; 41 import java.awt.event.FocusListener; 37 42 38 43 import javax.swing.Action; … … 43 48 import java.awt.event.ActionListener; 44 49 import java.awt.Dimension; 50 import java.awt.Dialog.ModalityType; 51 import java.awt.event.WindowEvent; 45 52 46 53 class AddHouseNumberDialog extends JDialog { … … 56 63 private JTextField tfStart; 57 64 private JTextField tfIncrement; 65 private def actApply; 58 66 59 67 public AddHouseNumberDialog(){ 60 super(Main.parent, true /* modal */)68 super(Main.parent,true) 61 69 build(); 62 70 } … … 95 103 SwingBuilder swing = new SwingBuilder() 96 104 return swing.panel(layout: new FlowLayout(FlowLayout.CENTER)) { 97 defactApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)})105 actApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)}) 98 106 def btnApply = button(action: actApply) 99 107 btnApply.setFocusable(true) … … 114 122 return 115 123 } 116 def cmds = getCurrentlySelectedNodes().collect { Node n -> 124 def nodes = Main?.map?.mapView?.editLayer?.data?.getSelectedNodes()?.asList() 125 if (nodes == null || nodes.isEmpty()) return 126 def cmds = nodes.collect { Node n -> 117 127 Node nn = new Node(n) 118 128 nn.put("addr:housenumber", start.toString()) … … 120 130 return new ChangeCommand(n, nn) 121 131 } 122 if (cmds.isEmpty()) return123 132 Main.main.undoRedo.add(new SequenceCommand("Setting house numbers", cmds)) 124 133 } … … 131 140 cp.add(buildInputPanel(), BorderLayout.CENTER) 132 141 cp.add(buildControlButtonPanel(), BorderLayout.SOUTH) 133 } 134 135 def getCurrentDataSet() { 136 def layer = Main?.map?.mapView?.activeLayer 137 if (layer == null) return null 138 if (! (layer instanceof OsmDataLayer)) return null 139 return layer.data 140 } 141 142 def getCurrentlySelectedNodes() { 143 def DataSet ds = getCurrentDataSet() 144 if (ds == null) return [] 145 return ds.getSelectedNodes().asList() 146 } 142 143 addWindowListener([windowActivated: {tfStart.requestFocusInWindow()}] as WindowAdapter) 144 getRootPane().registerKeyboardAction(actApply, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,KeyEvent.CTRL_MASK, false), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 145 } 147 146 148 147 @Override
Note:
See TracChangeset
for help on using the changeset viewer.