1 | package wmsplugin;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.Cursor;
|
---|
6 | import java.awt.event.MouseEvent;
|
---|
7 | import java.awt.event.MouseListener;
|
---|
8 | import java.awt.event.MouseMotionListener;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
12 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
13 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
16 |
|
---|
17 |
|
---|
18 | public class WMSAdjustAction extends MapMode implements
|
---|
19 | MouseListener, MouseMotionListener{
|
---|
20 |
|
---|
21 | GeorefImage selectedImage;
|
---|
22 | WMSLayer selectedLayer;
|
---|
23 | boolean mouseDown;
|
---|
24 | EastNorth prevEastNorth;
|
---|
25 |
|
---|
26 | public WMSAdjustAction(MapFrame mapFrame) {
|
---|
27 | super(tr("Adjust WMS"), "adjustwms",
|
---|
28 | tr("Adjust the position of the selected WMS layer"), mapFrame,
|
---|
29 | ImageProvider.getCursor("normal", "move"));
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override public void enterMode() {
|
---|
33 | super.enterMode();
|
---|
34 | Main.map.mapView.addMouseListener(this);
|
---|
35 | Main.map.mapView.addMouseMotionListener(this);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override public void exitMode() {
|
---|
39 | super.exitMode();
|
---|
40 | Main.map.mapView.removeMouseListener(this);
|
---|
41 | Main.map.mapView.removeMouseMotionListener(this);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override public void mousePressed(MouseEvent e) {
|
---|
45 | if (e.getButton() != MouseEvent.BUTTON1)
|
---|
46 | return;
|
---|
47 |
|
---|
48 | Layer layer=Main.map.mapView.getActiveLayer();
|
---|
49 | if (layer.visible && layer instanceof WMSLayer) {
|
---|
50 | prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
|
---|
51 | selectedLayer = ((WMSLayer)layer);
|
---|
52 | selectedImage = selectedLayer.findImage(prevEastNorth);
|
---|
53 | if(selectedImage!=null) {
|
---|
54 | Main.map.mapView.setCursor
|
---|
55 | (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override public void mouseDragged(MouseEvent e) {
|
---|
61 | if(selectedImage!=null) {
|
---|
62 | EastNorth eastNorth=
|
---|
63 | Main.map.mapView.getEastNorth(e.getX(),e.getY());
|
---|
64 | selectedLayer.displace(
|
---|
65 | eastNorth.east()-prevEastNorth.east(),
|
---|
66 | eastNorth.north()-prevEastNorth.north()
|
---|
67 | );
|
---|
68 | prevEastNorth = eastNorth;
|
---|
69 | Main.map.mapView.repaint();
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override public void mouseReleased(MouseEvent e) {
|
---|
74 | Main.map.mapView.repaint();
|
---|
75 | Main.map.mapView.setCursor(Cursor.getDefaultCursor());
|
---|
76 | selectedImage = null;
|
---|
77 | prevEastNorth = null;
|
---|
78 | selectedLayer = null;
|
---|
79 | }
|
---|
80 |
|
---|
81 | public void mouseEntered(MouseEvent e) {
|
---|
82 | }
|
---|
83 | public void mouseExited(MouseEvent e) {
|
---|
84 | }
|
---|
85 | public void mouseMoved(MouseEvent e) {
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override public void mouseClicked(MouseEvent e) {
|
---|
89 | }
|
---|
90 |
|
---|
91 | // This only makes the buttons look disabled, but since no keyboard shortcut is
|
---|
92 | // provided there aren't any other means to activate this tool
|
---|
93 | @Override public boolean layerIsSupported(Layer l) {
|
---|
94 | return (l instanceof WMSLayer) && l.visible;
|
---|
95 | }
|
---|
96 | }
|
---|