svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / ZoomPixelCursorListener.java @ 10626
History | View | Annotate | Download (5.15 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.project.documents.view.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 |
import java.util.ArrayList; |
50 |
|
51 |
import javax.swing.ImageIcon; |
52 |
|
53 |
import org.apache.log4j.Logger; |
54 |
|
55 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
56 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
57 |
import com.iver.cit.gvsig.fmap.MapControl; |
58 |
import com.iver.cit.gvsig.fmap.ViewPort; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
61 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
62 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
63 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
64 |
|
65 |
|
66 |
/**
|
67 |
*
|
68 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
69 |
*/
|
70 |
public class ZoomPixelCursorListener implements PointListener { |
71 |
private static Logger logger = Logger.getLogger(ZoomPixelCursorListener.class.getName()); |
72 |
private final Image img = new ImageIcon(MapControl.class.getResource( |
73 |
"images/ZoomPixelCursor.gif")).getImage();
|
74 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor( img, |
75 |
new Point(16, 16), ""); |
76 |
private MapControl mapCtrl;
|
77 |
|
78 |
/**
|
79 |
* Crea un nuevo AreaListenerImpl.
|
80 |
*
|
81 |
* @param mc DOCUMENT ME!
|
82 |
*/
|
83 |
public ZoomPixelCursorListener(MapControl mc) {
|
84 |
this.mapCtrl = mc;
|
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
89 |
*/
|
90 |
public void point(PointEvent event) throws BehaviorException { |
91 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
92 |
Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY()); |
93 |
ViewPort v = mapCtrl.getMapContext().getViewPort(); |
94 |
|
95 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
|
96 |
Rectangle2D ext = null; |
97 |
try{
|
98 |
ext = actives[0].getFullExtent();
|
99 |
} catch (ReadDriverException e1) {
|
100 |
e1.printStackTrace(); |
101 |
} catch (ExpansionFileReadException e) {
|
102 |
e.printStackTrace(); |
103 |
} |
104 |
|
105 |
ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes(); |
106 |
int width = 0, height = 0; |
107 |
for (int i=0; i<attr.size(); i++) { |
108 |
Object[] a = (Object []) attr.get(i); |
109 |
if (a[0].toString().equals("Width")) |
110 |
width = ((Integer)a[1]).intValue(); |
111 |
if (a[0].toString().equals("Height")) |
112 |
height = ((Integer)a[1]).intValue(); |
113 |
} |
114 |
|
115 |
|
116 |
if( ext != null && |
117 |
width != 0 &&
|
118 |
height != 0){
|
119 |
|
120 |
double wcOriginCenterX = pReal.getX();
|
121 |
double wcOriginCenterY = pReal.getY();
|
122 |
|
123 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
124 |
double relacionPixelWcWidth = (ext.getMaxX() - ext.getMinX())/width;
|
125 |
double relacionPixelWcHeight = (ext.getMaxY() - ext.getMinY())/height;
|
126 |
double desplazamientoX = ext.getMinX();
|
127 |
double desplazamientoY = ext.getMinY();
|
128 |
|
129 |
double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2); |
130 |
double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2); |
131 |
|
132 |
double wcDstMinX = wcOriginX;
|
133 |
double wcDstMinY = wcOriginY;
|
134 |
double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
|
135 |
double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
|
136 |
|
137 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
138 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
139 |
|
140 |
ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
141 |
mapCtrl.getMapContext().getViewPort().setExtent(ext); |
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
147 |
*/
|
148 |
public Cursor getCursor() { |
149 |
return cur;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
154 |
*/
|
155 |
public boolean cancelDrawing() { |
156 |
return false; |
157 |
} |
158 |
|
159 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
160 |
// TODO Auto-generated method stub
|
161 |
|
162 |
} |
163 |
|
164 |
} |