Ignore:
Timestamp:
2011-01-22T16:39:26+01:00 (14 years ago)
Author:
guggis
Message:

Fixed help context

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 */
     5import java.awt.event.WindowAdapter;
    16
    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  */
    77
    88import java.awt.BorderLayout;
     
    1010
    1111import java.awt.event.KeyEvent;
     12import java.awt.event.WindowAdapter;
     13import java.awt.event.WindowListener;
    1214
    1315import javax.swing.KeyStroke;
    1416
    1517import groovy.swing.SwingBuilder;
     18import groovy.util.ProxyGenerator;
     19
    1620import javax.swing.JOptionPane;
    1721import org.openstreetmap.josm.Main;
     
    3539import java.awt.GridBagLayout;
    3640import javax.swing.JLabel;
     41import java.awt.event.FocusListener;
    3742
    3843import javax.swing.Action;
     
    4348import java.awt.event.ActionListener;
    4449import java.awt.Dimension;
     50import java.awt.Dialog.ModalityType;
     51import java.awt.event.WindowEvent;
    4552
    4653class AddHouseNumberDialog extends JDialog {
     
    5663        private JTextField tfStart;
    5764        private JTextField tfIncrement;
     65        private def actApply;
    5866       
    5967        public AddHouseNumberDialog(){
    60                 super(Main.parent, true /* modal */)
     68                super(Main.parent,true)
    6169                build();
    6270        }
     
    95103                SwingBuilder swing = new SwingBuilder()
    96104                return swing.panel(layout: new FlowLayout(FlowLayout.CENTER)) {
    97                     def actApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)})
     105                    actApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)})
    98106                        def btnApply = button(action: actApply)
    99107                        btnApply.setFocusable(true)
     
    114122                        return
    115123                }
    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 ->
    117127                        Node nn = new Node(n)
    118128                        nn.put("addr:housenumber", start.toString())
     
    120130                        return new ChangeCommand(n, nn)                 
    121131                }
    122                 if (cmds.isEmpty()) return
    123132                Main.main.undoRedo.add(new SequenceCommand("Setting house numbers", cmds))
    124133        }
     
    131140                cp.add(buildInputPanel(), BorderLayout.CENTER)
    132141                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        }               
    147146
    148147        @Override
Note: See TracChangeset for help on using the changeset viewer.