source: osm/applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java

Last change on this file was 35368, checked in by donvip, 4 years ago

fix #josm18933 - define toolbar id

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.measurement;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Cursor;
7import java.awt.event.MouseEvent;
8
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.actions.mapmode.MapMode;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.gui.MainApplication;
14
15public class MeasurementMode extends MapMode {
16
17 private static final long serialVersionUID = 3853830673475744263L;
18
19 public MeasurementMode(String name, String desc) {
20 super(name, "measurement", desc, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
21 putValue("toolbar", "measurement");
22 }
23
24 @Override
25 public void enterMode() {
26 super.enterMode();
27 MainApplication.getMap().mapView.addMouseListener(this);
28 }
29
30 @Override
31 public void exitMode() {
32 super.exitMode();
33 MainApplication.getMap().mapView.removeMouseListener(this);
34 }
35
36 /**
37 * If user clicked with the left button, add a node at the current mouse
38 * position.
39 *
40 * If in nodesegment mode, add the node to the line segment by splitting the
41 * segment. The new created segment will be inserted in every way the segment
42 * was part of.
43 */
44 @Override
45 public void mouseClicked(MouseEvent e) {
46 if (e.getButton() == MouseEvent.BUTTON3) {
47 MeasurementPlugin.getCurrentLayer().removeLastPoint();
48 } else if (e.getButton() == MouseEvent.BUTTON1) {
49 Node coor = new Node(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()));
50 if (coor.isOutSideWorld()) {
51 JOptionPane.showMessageDialog(MainApplication.getMainFrame(),tr("Can not draw outside of the world."));
52 return;
53 }
54 MeasurementPlugin.getCurrentLayer().mouseClicked(e);
55 }
56 }
57}
Note: See TracBrowser for help on using the repository browser.