source: josm/trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java@ 2484

Last change on this file since 2484 was 2323, checked in by Gubaer, 15 years ago

Added explicit help topics
See also current list of help topics with links to source files and to help pages

File size: 3.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
6
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10
11import javax.swing.JLabel;
12import javax.swing.JOptionPane;
13import javax.swing.JPanel;
14import javax.swing.JTextField;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.command.AddCommand;
18import org.openstreetmap.josm.data.coor.LatLon;
19import org.openstreetmap.josm.data.osm.Node;
20import org.openstreetmap.josm.tools.GBC;
21import org.openstreetmap.josm.tools.Shortcut;
22
23/**
24 * This action displays a dialog where the user can enter a latitude and longitude,
25 * and when ok is pressed, a new node is created at the specified position.
26 */
27public final class AddNodeAction extends JosmAction {
28
29 public AddNodeAction() {
30 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."),
31 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
32 Shortcut.SHIFT_DEFAULT), true);
33 putValue("help", ht("/Action/AddNode"));
34 }
35
36 public void actionPerformed(ActionEvent e) {
37 // we abort if we are not in the context of an OsmDataLayer
38 //
39 if (!isEnabled())
40 return;
41
42 JPanel p = new JPanel(new GridBagLayout());
43 p.add(new JLabel("<html>"+
44 tr("Enter the coordinates for the new node.") +
45 "<br>" + tr("Use decimal degrees.") +
46 "<br>" + tr("Negative values denote Western/Southern hemisphere.")),
47 GBC.eol());
48
49 p.add(new JLabel(tr("Latitude")), GBC.std().insets(0,10,5,0));
50 final JTextField lat = new JTextField(12);
51 p.add(lat, GBC.eol().insets(0,10,0,0));
52 p.add(new JLabel(tr("Longitude")), GBC.std().insets(0,0,5,10));
53 final JTextField lon = new JTextField(12);
54 p.add(lon, GBC.eol().insets(0,0,0,10));
55
56 Node nnew = null;
57
58 while(nnew == null) {
59 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
60 pane.createDialog(Main.parent, tr("Add Node...")).setVisible(true);
61 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
62 return;
63 try {
64 LatLon ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText()));
65 if (!ll.isOutSideWorld()) {
66 nnew = new Node(ll);
67 }
68 } catch (Exception ex) { }
69 }
70
71 /* Now execute the commands to add the dupicated contents of the paste buffer to the map */
72 Main.main.undoRedo.add(new AddCommand(nnew));
73 getCurrentDataSet().setSelected(nnew);
74 Main.map.mapView.repaint();
75 }
76
77 @Override
78 protected void updateEnabledState() {
79 setEnabled(getEditLayer() != null);
80 }
81
82}
83
Note: See TracBrowser for help on using the repository browser.