root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / MapOverviewChangeZoomListener.java @ 7738
History | View | Annotate | Download (3.77 KB)
1 | 5233 | jmvivo | /**
|
---|---|---|---|
2 | *
|
||
3 | */
|
||
4 | package com.iver.cit.gvsig.gui.toolListeners; |
||
5 | |||
6 | import java.awt.Cursor; |
||
7 | import java.awt.Image; |
||
8 | import java.awt.Point; |
||
9 | import java.awt.Toolkit; |
||
10 | import java.awt.event.InputEvent; |
||
11 | 6274 | jmvivo | import java.awt.event.MouseEvent; |
12 | 5233 | jmvivo | import java.awt.geom.Rectangle2D; |
13 | |||
14 | import javax.swing.ImageIcon; |
||
15 | |||
16 | import com.iver.cit.gvsig.fmap.MapControl; |
||
17 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
18 | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
||
19 | import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
||
20 | import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
||
21 | import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
||
22 | 7738 | jaume | import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
23 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.MapOverview; |
24 | 5233 | jmvivo | |
25 | /**
|
||
26 | * @author jmvivo
|
||
27 | *
|
||
28 | */
|
||
29 | |||
30 | |||
31 | |||
32 | public class MapOverviewChangeZoomListener implements RectangleListener, PanListener { |
||
33 | private final Image izoomin = new ImageIcon(MapControl.class.getResource( |
||
34 | "images/ZoomInCursor.gif")).getImage();
|
||
35 | private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin,new Point(16, 16), ""); |
||
36 | protected MapControl mapControl;
|
||
37 | |||
38 | /**
|
||
39 | * Crea un nuevo MapOverviewChangeZoomListener.
|
||
40 | *
|
||
41 | * @param mapControl Control de mapa asociado
|
||
42 | */
|
||
43 | public MapOverviewChangeZoomListener(MapControl mapControl) {
|
||
44 | this.mapControl=mapControl;
|
||
45 | } |
||
46 | |||
47 | /**
|
||
48 | * Cambia el zoom. Es llamado cuando finaliza de
|
||
49 | * pintar el recuadro
|
||
50 | *
|
||
51 | *
|
||
52 | *
|
||
53 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
||
54 | */
|
||
55 | public void rectangle(RectangleEvent event) throws BehaviorException { |
||
56 | |||
57 | 6274 | jmvivo | if (!checkModifiers(event.getEvent())){
|
58 | 5233 | jmvivo | return;
|
59 | } |
||
60 | MapOverview mov=(MapOverview) this.mapControl;
|
||
61 | ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
||
62 | ViewPort vp = mov.getViewPort(); |
||
63 | |||
64 | if (vp.getExtent() != null && vpView.getExtent() != null) { |
||
65 | |||
66 | // Recuperamos las coordenadas del evento en px
|
||
67 | Rectangle2D pxRectangle = event.getPixelCoordRect();
|
||
68 | // Recuperamos las coordenadas del evento en coordenadas de la vista de localizador
|
||
69 | Rectangle2D realRectangle = event.getWorldCoordRect();
|
||
70 | |||
71 | if ((pxRectangle.getWidth() < 3) && (pxRectangle.getHeight() < 3)) |
||
72 | { |
||
73 | // rectangulo < 3 px no hacemos nada
|
||
74 | return;
|
||
75 | |||
76 | } else {
|
||
77 | // Cambiamos la extension de la vista asociada al localizador
|
||
78 | vpView.setExtent(realRectangle); |
||
79 | } |
||
80 | |||
81 | } |
||
82 | |||
83 | |||
84 | } |
||
85 | |||
86 | /**
|
||
87 | * (non-Javadoc)
|
||
88 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
89 | **/
|
||
90 | public Cursor getCursor() { |
||
91 | return this.cur; |
||
92 | } |
||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
96 | */
|
||
97 | public boolean cancelDrawing() { |
||
98 | return true; //??? |
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Es llamado mientras se hace del 'Dragg' del
|
||
103 | * raton. Pinta el recuadro de la forma.
|
||
104 | **/
|
||
105 | public void move(MoveEvent event) throws BehaviorException { |
||
106 | |||
107 | |||
108 | 6274 | jmvivo | if (!checkModifiers(event.getEvent())){
|
109 | 5233 | jmvivo | return;
|
110 | } |
||
111 | 6274 | jmvivo | System.out.println("mapOvervierChangeZoom"); |
112 | 5233 | jmvivo | MapOverview mov=(MapOverview) this.mapControl;
|
113 | ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
||
114 | ViewPort vp = mov.getViewPort(); |
||
115 | |||
116 | if (vp.getExtent() != null && vpView.getExtent() != null) { |
||
117 | |||
118 | // Creamos un recuadro con las coordenadas del raton
|
||
119 | // traducidas a la del mapa
|
||
120 | Rectangle2D realRectangle = new Rectangle2D.Double(); |
||
121 | realRectangle.setFrameFromDiagonal(vp.toMapPoint(event.getFrom()),vp.toMapPoint(event.getTo())); |
||
122 | |||
123 | // Establecemos la forma
|
||
124 | mov.refreshOverView(realRectangle); |
||
125 | } |
||
126 | |||
127 | |||
128 | |||
129 | } |
||
130 | |||
131 | /**
|
||
132 | * Comprueba que el estado de los botones
|
||
133 | * sea el deseado para esta herramienta.
|
||
134 | **/
|
||
135 | 6274 | jmvivo | private boolean checkModifiers(MouseEvent event) { |
136 | int modifiers = event.getModifiers();
|
||
137 | int keyPressedMask = InputEvent.BUTTON1_MASK; |
||
138 | return ((modifiers & keyPressedMask) == keyPressedMask);
|
||
139 | 5233 | jmvivo | } |
140 | |||
141 | } |