Changeset 1807 in josm
- Timestamp:
- 2009-07-19T00:06:29+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
r1415 r1807 17 17 import org.openstreetmap.josm.data.osm.Node; 18 18 import org.openstreetmap.josm.data.coor.LatLon; 19 import org.openstreetmap.josm.gui.layer.Layer; 20 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 19 21 import org.openstreetmap.josm.tools.GBC; 20 22 import org.openstreetmap.josm.tools.Shortcut; … … 24 26 * and when ok is pressed, a new node is created at the specified position. 25 27 */ 26 public final class AddNodeAction extends JosmAction {28 public final class AddNodeAction extends JosmAction implements LayerChangeListener { 27 29 28 30 public AddNodeAction() { 29 31 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."), 30 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT, 31 Shortcut.SHIFT_DEFAULT), true); 32 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT, 33 Shortcut.SHIFT_DEFAULT), true); 34 Layer.listeners.add(this); 35 refreshEnabled(); 36 } 37 38 protected void refreshEnabled() { 39 setEnabled(Main.map != null 40 && Main.map.mapView != null 41 && Main.map.mapView.getEditLayer() != null); 32 42 } 33 43 34 44 public void actionPerformed(ActionEvent e) { 45 // we abort if we are not in the context of an OsmDataLayer 46 // 47 if (!isEnabled()) 48 return; 49 35 50 JPanel p = new JPanel(new GridBagLayout()); 36 51 p.add(new JLabel("<html>"+ … … 56 71 try { 57 72 LatLon ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText())); 58 if (!ll.isOutSideWorld()) nnew = new Node(ll); 73 if (!ll.isOutSideWorld()) { 74 nnew = new Node(ll); 75 } 59 76 } catch (Exception ex) { } 60 77 } 61 78 62 79 /* Now execute the commands to add the dupicated contents of the paste buffer to the map */ 63 64 80 Main.main.undoRedo.add(new AddCommand(nnew)); 65 81 Main.ds.setSelected(nnew); 66 82 Main.map.mapView.repaint(); 67 83 } 84 85 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 86 refreshEnabled(); 87 } 88 89 public void layerAdded(Layer newLayer) { 90 refreshEnabled(); 91 92 } 93 94 public void layerRemoved(Layer oldLayer) { 95 refreshEnabled(); 96 } 68 97 }
Note:
See TracChangeset
for help on using the changeset viewer.