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

Last change on this file since 1180 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

File size: 3.4 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.tools.I18n.trn;
6
7import java.awt.BorderLayout;
8import java.awt.GridBagLayout;
9import java.awt.event.ActionEvent;
10import java.awt.event.FocusAdapter;
11import java.awt.event.FocusEvent;
12import java.awt.event.KeyEvent;
13import java.util.ArrayList;
14import java.util.Collection;
15import java.util.HashMap;
16import java.util.LinkedList;
17import java.util.List;
18import java.util.TreeMap;
19import java.util.TreeSet;
20
21import javax.swing.JLabel;
22import javax.swing.JOptionPane;
23import javax.swing.JPanel;
24import javax.swing.JTextField;
25
26import org.openstreetmap.josm.Main;
27import org.openstreetmap.josm.command.AddCommand;
28import org.openstreetmap.josm.command.Command;
29import org.openstreetmap.josm.command.SequenceCommand;
30import org.openstreetmap.josm.data.osm.DataSet;
31import org.openstreetmap.josm.data.osm.Relation;
32import org.openstreetmap.josm.data.osm.Node;
33import org.openstreetmap.josm.data.osm.OsmPrimitive;
34import org.openstreetmap.josm.data.osm.RelationMember;
35import org.openstreetmap.josm.data.osm.Way;
36import org.openstreetmap.josm.data.coor.EastNorth;
37import org.openstreetmap.josm.data.coor.LatLon;
38import org.openstreetmap.josm.tools.AutoCompleteComboBox;
39import org.openstreetmap.josm.tools.GBC;
40import org.openstreetmap.josm.tools.Shortcut;
41
42/**
43 * This action displays a dialog where the user can enter a latitude and longitude,
44 * and when ok is pressed, a new node is created at the specified position.
45 */
46public final class AddNodeAction extends JosmAction {
47
48 public AddNodeAction() {
49 super(tr("Add Node"), "addnode", tr("Add a node by entering latitude and longitude."),
50 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
51 Shortcut.SHIFT_DEFAULT), true);
52 }
53
54 public void actionPerformed(ActionEvent e) {
55 JPanel p = new JPanel(new GridBagLayout());
56 p.add(new JLabel("<html>"+
57 tr("Enter the coordinates for the new node.") +
58 "<br>" + tr("Use decimal degrees.") +
59 "<br>" + tr("Negative values denote Western/Southern hemisphere.")),
60 GBC.eol());
61
62 p.add(new JLabel(tr("Latitude")), GBC.std().insets(0,10,5,0));
63 final JTextField lat = new JTextField(12);
64 p.add(lat, GBC.eol().insets(0,10,0,0));
65 p.add(new JLabel(tr("Longitude")), GBC.std().insets(0,0,5,10));
66 final JTextField lon = new JTextField(12);
67 p.add(lon, GBC.eol().insets(0,0,0,10));
68
69 Node nnew = null;
70
71 while(nnew == null) {
72 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
73 pane.createDialog(Main.parent, tr("Add Node")).setVisible(true);
74 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
75 return;
76 try {
77 LatLon ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText()));
78 if (!ll.isOutSideWorld()) nnew = new Node(ll);
79 } catch (Exception ex) { }
80 }
81
82 /* Now execute the commands to add the dupicated contents of the paste buffer to the map */
83
84 Main.main.undoRedo.add(new AddCommand(nnew));
85 Main.ds.setSelected(nnew);
86 Main.map.mapView.repaint();
87 }
88}
Note: See TracBrowser for help on using the repository browser.