Changeset 25107 in osm for applications/editors/josm/plugins/scripting/scripts/AddHouseNumbers.groovy
- Timestamp:
- 2011-01-22T12:18:25+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/scripting/scripts/AddHouseNumbers.groovy
r25019 r25107 1 1 2 /* 2 3 * This scripts sets a sequence of house numbers on the currently selected nodes. … … 6 7 7 8 import java.awt.BorderLayout; 9 import javax.swing.JComponent; 10 11 import java.awt.event.KeyEvent; 12 13 import javax.swing.KeyStroke; 8 14 9 15 import groovy.swing.SwingBuilder; … … 30 36 import javax.swing.JLabel; 31 37 38 import javax.swing.Action; 32 39 import javax.swing.BorderFactory; 33 40 import javax.swing.JTextField; … … 38 45 39 46 class AddHouseNumberDialog extends JDialog { 47 48 static private AddHouseNumberDialog instance; 49 static def AddHouseNumberDialog getInstance() { 50 if (instance == null){ 51 instance = new AddHouseNumberDialog() 52 } 53 return instance 54 } 40 55 41 56 private JTextField tfStart; … … 52 67 <html> 53 68 Enter the <strong>first house number</strong> to be applied to the currently selected nodes 54 and the amount by which the house number is<strong>incremented</strong>.69 and the <strong>increment</strong> between consecutive house numbers. 55 70 </html> 56 71 """ … … 61 76 SwingBuilder swing = new SwingBuilder() 62 77 return swing.panel(){ 78 emptyBorder([5,5,5,5],parent:true) 63 79 gridBagLayout() 64 80 label(text: "Start:", … … 67 83 ) 68 84 tfStart = textField(constraints: gbc(gridx:1,gridy:0,weightx:1.0, weighty:0.0, fill: GridBagConstraints.HORIZONTAL, insets:[2,2,2,2])) 85 SelectAllOnFocusGainedDecorator.decorate(tfStart) 69 86 label(text: "Increment:", horizontalAlignment: JLabel.LEFT, constraints: gbc(gridx:0,gridy:1,weightx:0.0, weighty:0.0, anchor: GridBagConstraints.WEST, insets:[2,2,2,2])) 70 87 tfIncrement = textField(constraints: gbc(gridx:1,gridy:1,weightx:1.0, weighty:0.0, fill: GridBagConstraints.HORIZONTAL, anchor: GridBagConstraints.WEST, insets:[2,2,2,2])) 88 SelectAllOnFocusGainedDecorator.decorate(tfIncrement) 71 89 panel(constraints: gbc(gridx:0,gridy:2,weightx:1.0, weighty:1.0, gridwidth:2, fill: GridBagConstraints.BOTH, insets:[2,2,2,2])) 90 tfIncrement.text = "2" 72 91 } 73 92 } … … 76 95 SwingBuilder swing = new SwingBuilder() 77 96 return swing.panel(layout: new FlowLayout(FlowLayout.CENTER)) { 97 def actApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)}) 98 def btnApply = button(action: actApply) 99 btnApply.setFocusable(true) 100 btnApply.registerKeyboardAction(actApply, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0, false), JComponent.WHEN_FOCUSED) 101 78 102 button(text: "Cancel", icon: ImageProvider.get("cancel"), actionPerformed: {setVisible(false)}) 79 button(text: "Apply", icon: ImageProvider.get("ok"), actionPerformed: {80 apply()81 setVisible(false)82 })83 103 } 84 104 } 85 105 86 106 def apply() { 87 107 def start 108 def incr 88 109 try { 89 110 start = tfStart.text.trim().toInteger() 111 incr = tfIncrement.text.trim().toInteger() 90 112 } catch(NumberFormatException e){ 91 113 e.printStackTrace() 92 114 return 93 115 } 94 def incr 95 try { 96 incr = tfIncrement.text.trim().toInteger() 97 } catch(NumberFormatException e){ 98 e.printStackTrace() 99 return 100 } 101 def nodes = getCurrentlySelectedNodes() 102 def cmds = [] 103 nodes.each {Node n -> 116 def cmds = getCurrentlySelectedNodes().collect { Node n -> 104 117 Node nn = new Node(n) 105 118 nn.put("addr:housenumber", start.toString()) 106 119 start += incr 107 cmds <<new ChangeCommand(n, nn)120 return new ChangeCommand(n, nn) 108 121 } 109 122 if (cmds.isEmpty()) return … … 112 125 113 126 def build() { 114 setTitle("Set house numbers")127 title = "Set house numbers" 115 128 def cp = getContentPane() 116 129 cp.setLayout(new BorderLayout()) … … 121 134 122 135 def getCurrentDataSet() { 123 def layer = Main?.map?.mapView?. getActiveLayer()136 def layer = Main?.map?.mapView?.activeLayer 124 137 if (layer == null) return null 125 138 if (! (layer instanceof OsmDataLayer)) return null … … 142 155 } 143 156 144 def dialog = newAddHouseNumberDialog()145 dialog.setVisible(true) 157 AddHouseNumberDialog.instance.setVisible(true) 158
Note:
See TracChangeset
for help on using the changeset viewer.