| 1 | package ext_tools;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.awt.event.KeyEvent;
|
|---|
| 7 | import java.awt.event.MouseEvent;
|
|---|
| 8 |
|
|---|
| 9 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
|---|
| 10 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 11 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 12 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 14 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 15 |
|
|---|
| 16 | // TODO: Merge with ExtTool class?
|
|---|
| 17 | class ExtToolAction extends MapMode {
|
|---|
| 18 |
|
|---|
| 19 | protected MapMode oldMapMode;
|
|---|
| 20 | protected ExtTool tool;
|
|---|
| 21 |
|
|---|
| 22 | public ExtToolAction(ExtTool tool) {
|
|---|
| 23 | super(tr(tool.name), "empty", tool.description,
|
|---|
| 24 | Shortcut.registerShortcut(tr("exttool:{0}", tool.name), tr("External Tool: {0}", tool.name),
|
|---|
| 25 | KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
|
|---|
| 26 | ImageProvider.getCursor("crosshair", null));
|
|---|
| 27 | this.tool = tool;
|
|---|
| 28 | setEnabled(true);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | @Override
|
|---|
| 32 | public void actionPerformed(ActionEvent e) {
|
|---|
| 33 | if (!MainApplication.isDisplayingMapView())
|
|---|
| 34 | return;
|
|---|
| 35 | oldMapMode = MainApplication.getMap().mapMode;
|
|---|
| 36 | super.actionPerformed(e);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | @Override
|
|---|
| 40 | public void enterMode() {
|
|---|
| 41 | super.enterMode();
|
|---|
| 42 | MainApplication.getMap().mapView.addMouseListener(this);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | @Override
|
|---|
| 46 | public void exitMode() {
|
|---|
| 47 | super.exitMode();
|
|---|
| 48 | MainApplication.getMap().mapView.removeMouseListener(this);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | @Override
|
|---|
| 52 | public void mouseClicked(MouseEvent e) {
|
|---|
| 53 | if (!MainApplication.isDisplayingMapView()) {
|
|---|
| 54 | return;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | tool.runTool(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()));
|
|---|
| 58 | MainApplication.getMap().selectMapMode(oldMapMode);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | @Override
|
|---|
| 62 | public boolean layerIsSupported(Layer l) {
|
|---|
| 63 | return l instanceof OsmDataLayer;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|