source: josm/trunk/src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java@ 12620

Last change on this file since 12620 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.mapmode;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.KeyEvent;
7import java.awt.event.MouseEvent;
8
9import javax.swing.JOptionPane;
10import javax.swing.SwingUtilities;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.osm.NoteData;
15import org.openstreetmap.josm.gui.NoteInputDialog;
16import org.openstreetmap.josm.gui.Notification;
17import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
18import org.openstreetmap.josm.tools.CheckParameterUtil;
19import org.openstreetmap.josm.tools.ImageProvider;
20import org.openstreetmap.josm.tools.Logging;
21
22/**
23 * Map mode to add a new note. Listens for a mouse click and then
24 * prompts the user for text and adds a note to the note layer
25 */
26public class AddNoteAction extends MapMode implements KeyPressReleaseListener {
27
28 private final transient NoteData noteData;
29
30 /**
31 * Construct a new map mode.
32 * @param data Note data container. Must not be null
33 * @since 11713
34 */
35 public AddNoteAction(NoteData data) {
36 super(tr("Add a new Note"), "addnote", tr("Add note mode"),
37 ImageProvider.getCursor("crosshair", "create_note"));
38 CheckParameterUtil.ensureParameterNotNull(data, "data");
39 noteData = data;
40 }
41
42 @Override
43 public String getModeHelpText() {
44 return tr("Click the location where you wish to create a new note");
45 }
46
47 @Override
48 public void enterMode() {
49 super.enterMode();
50 Main.map.mapView.addMouseListener(this);
51 Main.map.keyDetector.addKeyListener(this);
52 }
53
54 @Override
55 public void exitMode() {
56 super.exitMode();
57 Main.map.mapView.removeMouseListener(this);
58 Main.map.keyDetector.removeKeyListener(this);
59 }
60
61 @Override
62 public void mouseClicked(MouseEvent e) {
63 if (!SwingUtilities.isLeftMouseButton(e)) {
64 // allow to pan without distraction
65 return;
66 }
67 Main.map.selectMapMode(Main.map.mapModeSelect);
68
69 NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Create new note"), tr("Create note"));
70 dialog.showNoteDialog(tr("Enter a detailed comment to create a note"), ImageProvider.get("dialogs/notes", "note_new"));
71
72 if (dialog.getValue() != 1) {
73 Logging.debug("User aborted note creation");
74 return;
75 }
76 String input = dialog.getInputText();
77 if (input != null && !input.isEmpty()) {
78 LatLon latlon = Main.map.mapView.getLatLon(e.getPoint().x, e.getPoint().y);
79 noteData.createNote(latlon, input);
80 } else {
81 new Notification(tr("You must enter a comment to create a new note")).setIcon(JOptionPane.WARNING_MESSAGE).show();
82 }
83 }
84
85 @Override
86 public void doKeyPressed(KeyEvent e) {
87 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
88 Main.map.selectMapMode(Main.map.mapModeSelect);
89 }
90 }
91
92 @Override
93 public void doKeyReleased(KeyEvent e) {
94 // Do nothing
95 }
96}
Note: See TracBrowser for help on using the repository browser.