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

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

see #10858 - rename NoteDialog to NotesDialog

File size: 2.6 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.MouseEvent;
7
8import javax.swing.JOptionPane;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.coor.LatLon;
12import org.openstreetmap.josm.data.osm.NoteData;
13import org.openstreetmap.josm.gui.MapFrame;
14import org.openstreetmap.josm.gui.NoteInputDialog;
15import org.openstreetmap.josm.gui.Notification;
16import org.openstreetmap.josm.gui.dialogs.NotesDialog;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Map mode to add a new note. Listens for a mouse click and then
21 * prompts the user for text and adds a note to the note layer
22 */
23public class AddNoteAction extends MapMode {
24
25 private NoteData noteData;
26
27 /**
28 * Construct a new map mode.
29 * @param mapFrame Map frame to pass to the superconstructor
30 * @param data Note data container. Must not be null
31 */
32 public AddNoteAction(MapFrame mapFrame, NoteData data) {
33 super(tr("Add a new Note"), "addnote.png",
34 tr("Add note mode"),
35 mapFrame, ImageProvider.getCursor("crosshair", "create_note"));
36 if (data == null) {
37 throw new IllegalArgumentException("Note data must not be null");
38 }
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 }
52
53 @Override
54 public void exitMode() {
55 super.exitMode();
56 Main.map.mapView.removeMouseListener(this);
57 }
58
59 @Override
60 public void mouseClicked(MouseEvent e) {
61 Main.map.selectMapMode(Main.map.mapModeSelect);
62 LatLon latlon = Main.map.mapView.getLatLon(e.getPoint().x, e.getPoint().y);
63
64 NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Create new note"), tr("Create note"));
65 dialog.showNoteDialog(tr("Enter a detailed comment to create a note"), NotesDialog.ICON_NEW);
66
67 if (dialog.getValue() != 1) {
68 Main.debug("User aborted note creation");
69 return;
70 }
71 String input = dialog.getInputText();
72 if (input != null && !input.isEmpty()) {
73 noteData.createNote(latlon, input);
74 } else {
75 Notification notification = new Notification(tr("You must enter a comment to create a new note"));
76 notification.setIcon(JOptionPane.WARNING_MESSAGE);
77 notification.show();
78 }
79 }
80}
Note: See TracBrowser for help on using the repository browser.