source: osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java@ 12437

Last change on this file since 12437 was 12437, checked in by stoecker, 16 years ago

fixed text

File size: 2.5 KB
Line 
1package wmsplugin;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Cursor;
6import java.awt.event.MouseEvent;
7import java.awt.event.MouseListener;
8import java.awt.event.MouseMotionListener;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.gui.MapFrame;
12import org.openstreetmap.josm.actions.mapmode.MapMode;
13import org.openstreetmap.josm.data.coor.EastNorth;
14import org.openstreetmap.josm.tools.ImageProvider;
15import org.openstreetmap.josm.gui.layer.Layer;
16
17
18public class WMSAdjustAction extends MapMode implements
19 MouseListener, MouseMotionListener{
20
21 GeorefImage selectedImage;
22 boolean mouseDown;
23 EastNorth prevEastNorth;
24
25 public WMSAdjustAction(MapFrame mapFrame) {
26 super(tr("Adjust WMS"), "adjustwms",
27 tr("Adjust the position of the WMS layer"), mapFrame,
28 ImageProvider.getCursor("normal", "move"));
29 }
30
31 @Override public void enterMode() {
32 super.enterMode();
33 Main.map.mapView.addMouseListener(this);
34 Main.map.mapView.addMouseMotionListener(this);
35 }
36
37 @Override public void exitMode() {
38 super.exitMode();
39 Main.map.mapView.removeMouseListener(this);
40 Main.map.mapView.removeMouseMotionListener(this);
41 }
42
43 @Override public void mousePressed(MouseEvent e) {
44 if (e.getButton() != MouseEvent.BUTTON1)
45 return;
46
47 for(Layer layer:Main.map.mapView.getAllLayers()) {
48 if (layer.visible && layer instanceof WMSLayer) {
49 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
50 selectedImage = ((WMSLayer)layer).findImage(prevEastNorth);
51 if(selectedImage!=null){
52 Main.map.mapView.setCursor
53 (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
54 }
55 }
56 }
57 }
58
59 @Override public void mouseDragged(MouseEvent e) {
60 /*
61 if (e.getButton() != MouseEvent.BUTTON1)
62 return;
63 */
64
65 if(selectedImage!=null) {
66 EastNorth eastNorth=
67 Main.map.mapView.getEastNorth(e.getX(),e.getY());
68 if(selectedImage.contains(eastNorth)) {
69 selectedImage.displace(eastNorth.east()-prevEastNorth.east(),
70 eastNorth.north()-prevEastNorth.north());
71 prevEastNorth = eastNorth;
72 }
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 }
82
83 public void mouseEntered(MouseEvent e) {
84 }
85 public void mouseExited(MouseEvent e) {
86 }
87 public void mouseMoved(MouseEvent e) {
88 }
89
90 @Override public void mouseClicked(MouseEvent e) {
91 }
92}
Note: See TracBrowser for help on using the repository browser.