svn-gvsig-desktop / branches / v10 / extensions / extWCS / src / com / iver / cit / gvsig / gui / toolListeners / WCSZoomPixelCursorListener.java @ 20100
History | View | Annotate | Download (4.93 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.toolListeners; |
42 |
|
43 |
import java.awt.Cursor; |
44 |
import java.awt.Image; |
45 |
import java.awt.Point; |
46 |
import java.awt.Toolkit; |
47 |
import java.awt.geom.Point2D; |
48 |
import java.awt.geom.Rectangle2D; |
49 |
|
50 |
import javax.swing.ImageIcon; |
51 |
|
52 |
import org.apache.log4j.Logger; |
53 |
|
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.ViewPort; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
58 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
59 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
60 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
61 |
|
62 |
|
63 |
/**
|
64 |
* <p>Listener that executes a <i>zoom in</i> operation in the associated <code>MapControl</code>,
|
65 |
* having as center the point selected.</p>
|
66 |
*
|
67 |
* <p>Listens a single click of any mouse's button.</p>
|
68 |
*
|
69 |
* <p>The <i>zoom in</i> factor will depend on the maximum resolution of the <i>WCS</i> layers in
|
70 |
* the <code>MapControl</code>.</p>
|
71 |
*
|
72 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
73 |
*/
|
74 |
public class WCSZoomPixelCursorListener implements PointListener { |
75 |
/**
|
76 |
* Object used to log messages for this listener.
|
77 |
*/
|
78 |
private static Logger logger = Logger.getLogger(WCSZoomPixelCursorListener.class.getName()); |
79 |
|
80 |
/**
|
81 |
* The image to display when the cursor is active.
|
82 |
*/
|
83 |
private final Image img = new ImageIcon(MapControl.class.getResource("images/ZoomPixelCursor.gif")).getImage(); |
84 |
|
85 |
/**
|
86 |
* The cursor used to work with this tool listener.
|
87 |
*
|
88 |
* @see #getCursor()
|
89 |
*/
|
90 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor( img, new Point(16, 16), ""); |
91 |
|
92 |
/**
|
93 |
* Reference to the <code>MapControl</code> object that uses.
|
94 |
*/
|
95 |
private MapControl mapCtrl;
|
96 |
|
97 |
/**
|
98 |
* <p>Creates a new <code>WCSZoomPixelCursorListener</code> object.</p>
|
99 |
*
|
100 |
* @param mc the <code>MapControl</code> where be applied the changes
|
101 |
*/
|
102 |
public WCSZoomPixelCursorListener(MapControl mc) {
|
103 |
this.mapCtrl = mc;
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
109 |
*/
|
110 |
public void point(PointEvent event) throws BehaviorException { |
111 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
112 |
Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY()); |
113 |
ViewPort v = mapCtrl.getMapContext().getViewPort(); |
114 |
|
115 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
|
116 |
Rectangle2D ext = null; |
117 |
try{
|
118 |
ext = actives[0].getFullExtent();
|
119 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
120 |
e1.printStackTrace(); |
121 |
} |
122 |
|
123 |
if( ext != null ){ |
124 |
|
125 |
double w2 = v.getImageWidth()/2D; |
126 |
double h2 = v.getImageHeight()/2D; |
127 |
double wcOriginX = pReal.getX();
|
128 |
double wcOriginY = pReal.getY();
|
129 |
|
130 |
Point2D maxRes = ((FLyrWCS)actives[0]).getMaxResolution(); |
131 |
double wcDstMinX = wcOriginX-w2*maxRes.getX();
|
132 |
double wcDstMinY = wcOriginY-h2*maxRes.getY();
|
133 |
double wcDstWidth = w2*maxRes.getX()*2D; |
134 |
double wcDstHeight = h2*maxRes.getY()*2D; |
135 |
|
136 |
ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
137 |
mapCtrl.getMapContext().getViewPort().setExtent(ext); |
138 |
} |
139 |
|
140 |
} |
141 |
|
142 |
/*
|
143 |
* (non-Javadoc)
|
144 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
145 |
*/
|
146 |
public Cursor getCursor() { |
147 |
return cur;
|
148 |
} |
149 |
|
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
153 |
*/
|
154 |
public boolean cancelDrawing() { |
155 |
return false; |
156 |
} |
157 |
|
158 |
/*
|
159 |
* (non-Javadoc)
|
160 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
161 |
*/
|
162 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
163 |
// TODO Auto-generated method stub
|
164 |
|
165 |
} |
166 |
} |