1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.awt.BorderLayout;
|
---|
8 | import java.awt.GridBagLayout;
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.awt.event.FocusAdapter;
|
---|
11 | import java.awt.event.FocusEvent;
|
---|
12 | import java.awt.event.KeyEvent;
|
---|
13 | import java.util.ArrayList;
|
---|
14 | import java.util.Collection;
|
---|
15 | import java.util.HashMap;
|
---|
16 | import java.util.LinkedList;
|
---|
17 | import java.util.List;
|
---|
18 | import java.util.TreeMap;
|
---|
19 | import java.util.TreeSet;
|
---|
20 |
|
---|
21 | import javax.swing.JLabel;
|
---|
22 | import javax.swing.JOptionPane;
|
---|
23 | import javax.swing.JPanel;
|
---|
24 | import javax.swing.JTextField;
|
---|
25 |
|
---|
26 | import org.openstreetmap.josm.Main;
|
---|
27 | import org.openstreetmap.josm.command.AddCommand;
|
---|
28 | import org.openstreetmap.josm.command.Command;
|
---|
29 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
30 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
31 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
32 | import org.openstreetmap.josm.data.osm.Node;
|
---|
33 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
34 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
35 | import org.openstreetmap.josm.data.osm.Way;
|
---|
36 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
37 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
38 | import org.openstreetmap.josm.tools.AutoCompleteComboBox;
|
---|
39 | import org.openstreetmap.josm.tools.GBC;
|
---|
40 | import 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 | */
|
---|
46 | public 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 | }
|
---|