svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / toolListeners / WCSZoomPixelCursorListener.java @ 10626
History | View | Annotate | Download (4.28 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.hardcode.gdbms.driver.exceptions.ReadDriverException; |
55 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
56 |
import com.iver.cit.gvsig.fmap.MapControl; |
57 |
import com.iver.cit.gvsig.fmap.ViewPort; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
60 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
61 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
62 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
63 |
|
64 |
|
65 |
/**
|
66 |
*
|
67 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
68 |
*/
|
69 |
public class WCSZoomPixelCursorListener implements PointListener { |
70 |
private static Logger logger = Logger.getLogger(WCSZoomPixelCursorListener.class.getName()); |
71 |
private final Image img = new ImageIcon(MapControl.class.getResource( |
72 |
"images/ZoomPixelCursor.gif")).getImage();
|
73 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor( img, |
74 |
new Point(16, 16), ""); |
75 |
private MapControl mapCtrl;
|
76 |
|
77 |
/**
|
78 |
* Crea un nuevo AreaListenerImpl.
|
79 |
*
|
80 |
* @param mc DOCUMENT ME!
|
81 |
*/
|
82 |
public WCSZoomPixelCursorListener(MapControl mc) {
|
83 |
this.mapCtrl = mc;
|
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
88 |
*/
|
89 |
public void point(PointEvent event) throws BehaviorException { |
90 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
91 |
Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY()); |
92 |
ViewPort v = mapCtrl.getMapContext().getViewPort(); |
93 |
|
94 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
|
95 |
Rectangle2D ext = null; |
96 |
try {
|
97 |
ext = actives[0].getFullExtent();
|
98 |
} catch (ExpansionFileReadException e) {
|
99 |
throw new BehaviorException(e.getMessage()); |
100 |
} catch (ReadDriverException e) {
|
101 |
throw new BehaviorException(e.getMessage()); |
102 |
} |
103 |
|
104 |
|
105 |
if( ext != null ){ |
106 |
|
107 |
double w2 = v.getImageWidth()/2D; |
108 |
double h2 = v.getImageHeight()/2D; |
109 |
double wcOriginX = pReal.getX();
|
110 |
double wcOriginY = pReal.getY();
|
111 |
|
112 |
Point2D maxRes = ((FLyrWCS)actives[0]).getMaxResolution(); |
113 |
double wcDstMinX = wcOriginX-w2*maxRes.getX();
|
114 |
double wcDstMinY = wcOriginY-h2*maxRes.getY();
|
115 |
double wcDstWidth = w2*maxRes.getX()*2D; |
116 |
double wcDstHeight = h2*maxRes.getY()*2D; |
117 |
|
118 |
ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
119 |
mapCtrl.getMapContext().getViewPort().setExtent(ext); |
120 |
} |
121 |
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
126 |
*/
|
127 |
public Cursor getCursor() { |
128 |
return cur;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
133 |
*/
|
134 |
public boolean cancelDrawing() { |
135 |
return false; |
136 |
} |
137 |
|
138 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
139 |
// TODO Auto-generated method stub
|
140 |
|
141 |
} |
142 |
|
143 |
} |