| 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 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 | for(Layer layer:Main.map.mapView.getAllLayers()) {
|
|---|
| 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 |
|
|---|
| 61 | @Override public void mouseDragged(MouseEvent e) {
|
|---|
| 62 | /*
|
|---|
| 63 | if (e.getButton() != MouseEvent.BUTTON1)
|
|---|
| 64 | return;
|
|---|
| 65 | */
|
|---|
| 66 |
|
|---|
| 67 | if(selectedImage!=null) {
|
|---|
| 68 | EastNorth eastNorth=
|
|---|
| 69 | Main.map.mapView.getEastNorth(e.getX(),e.getY());
|
|---|
| 70 | selectedLayer.displace(eastNorth.east()-prevEastNorth.east(),
|
|---|
| 71 | eastNorth.north()-prevEastNorth.north());
|
|---|
| 72 | prevEastNorth = eastNorth;
|
|---|
| 73 | Main.map.mapView.repaint();
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | @Override public void mouseReleased(MouseEvent e) {
|
|---|
| 78 | Main.map.mapView.repaint();
|
|---|
| 79 | Main.map.mapView.setCursor(Cursor.getDefaultCursor());
|
|---|
| 80 | selectedImage = null;
|
|---|
| 81 | prevEastNorth = null;
|
|---|
| 82 | selectedLayer = null;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | public void mouseEntered(MouseEvent e) {
|
|---|
| 86 | }
|
|---|
| 87 | public void mouseExited(MouseEvent e) {
|
|---|
| 88 | }
|
|---|
| 89 | public void mouseMoved(MouseEvent e) {
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | @Override public void mouseClicked(MouseEvent e) {
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|