Revision 3023 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/ZoomControlPanel.java
ZoomControlPanel.java | ||
---|---|---|
7 | 7 |
import java.awt.Graphics2D; |
8 | 8 |
import java.awt.GridBagConstraints; |
9 | 9 |
import java.awt.GridBagLayout; |
10 |
import java.awt.event.ActionEvent; |
|
11 |
import java.awt.event.ActionListener; |
|
10 | 12 |
import java.awt.geom.Point2D; |
11 | 13 |
import java.awt.geom.Rectangle2D; |
14 |
import java.awt.image.BufferStrategy; |
|
12 | 15 |
|
13 | 16 |
import javax.swing.ImageIcon; |
14 | 17 |
import javax.swing.JButton; |
... | ... | |
28 | 31 |
* @author Nacho Brodin (brodin_ign@gva.es) |
29 | 32 |
* |
30 | 33 |
*/ |
31 |
public class ZoomControlPanel extends JPanel{ |
|
34 |
public class ZoomControlPanel extends JPanel implements ActionListener{
|
|
32 | 35 |
|
33 | 36 |
|
34 | 37 |
private JPanel pImage = null; |
... | ... | |
130 | 133 |
bZoomMas = new JButton(); |
131 | 134 |
bZoomMas.setPreferredSize(new java.awt.Dimension(25,25)); |
132 | 135 |
bZoomMas.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/aumentar.png"))); |
136 |
bZoomMas.addActionListener(this); |
|
133 | 137 |
} |
134 | 138 |
return bZoomMas; |
135 | 139 |
} |
... | ... | |
144 | 148 |
bZoomMenos = new JButton(); |
145 | 149 |
bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25)); |
146 | 150 |
bZoomMenos.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/disminuir.png"))); |
151 |
bZoomMenos.addActionListener(this); |
|
147 | 152 |
} |
148 | 153 |
return bZoomMenos; |
149 | 154 |
} |
... | ... | |
171 | 176 |
*/ |
172 | 177 |
public void setVisible(boolean visible){ |
173 | 178 |
canvas.setVisible(visible); |
179 |
if(!visible) |
|
180 |
canvas.setSize(0,0); |
|
181 |
else |
|
182 |
canvas.setSize(sX, sY); |
|
174 | 183 |
canvas.repaint(); |
175 | 184 |
} |
176 | 185 |
|
... | ... | |
183 | 192 |
} |
184 | 193 |
|
185 | 194 |
/** |
195 |
* Manejo de los controles zoom m?s y zoom menos |
|
196 |
*/ |
|
197 |
public void actionPerformed(ActionEvent e) { |
|
198 |
if(e.getSource() == bZoomMas){ |
|
199 |
canvas.calcZoom(0.6); |
|
200 |
canvas.repaint(); |
|
201 |
} |
|
202 |
|
|
203 |
if(e.getSource() == bZoomMenos){ |
|
204 |
canvas.calcZoom(1.8); |
|
205 |
canvas.repaint(); |
|
206 |
} |
|
207 |
} |
|
208 |
/** |
|
186 | 209 |
* Control que representa la zona de dibujado de la ventana. Este se encarga de |
187 | 210 |
* repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase |
188 | 211 |
* @author Nacho Brodin (brodin_ign@gva.es) |
... | ... | |
194 | 217 |
private ViewPort viewPort = null; |
195 | 218 |
private ViewPort newViewPort = null; |
196 | 219 |
private Point2D centerPoint = null; |
197 |
private final int ZOOM = 12; |
|
220 |
private int zoom = 20; |
|
221 |
public BufferStrategy strategy; |
|
222 |
|
|
198 | 223 |
|
199 | 224 |
public CanvasZone( int anc,int alt) { |
200 | 225 |
ancho = anc; |
... | ... | |
202 | 227 |
|
203 | 228 |
this.setSize(ancho, alto); |
204 | 229 |
this.setBackground(Color.WHITE); |
230 |
//this.createBufferStrategy(2); |
|
231 |
//strategy = this.getBufferStrategy(); |
|
205 | 232 |
} |
206 | 233 |
|
207 | 234 |
/** |
... | ... | |
210 | 237 |
*/ |
211 | 238 |
public void setViewPort(ViewPort vp){ |
212 | 239 |
this.viewPort = vp; |
240 |
this.initViewPort(); |
|
213 | 241 |
} |
214 | 242 |
|
215 | 243 |
/** |
244 |
* Calcula el zoom dependiendo del factor de escala pasado por |
|
245 |
* par?metro. |
|
246 |
*/ |
|
247 |
public void calcZoom(double factor){ |
|
248 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
249 |
double nuevoX = centerPoint.getX() - |
|
250 |
((newViewPort.getExtent().getWidth() * factor) / 2.0); |
|
251 |
double nuevoY = centerPoint.getY() - |
|
252 |
((newViewPort.getExtent().getHeight() * factor) / 2.0); |
|
253 |
r.x = nuevoX; |
|
254 |
r.y = nuevoY; |
|
255 |
r.width = newViewPort.getExtent().getWidth() * factor; |
|
256 |
r.height = newViewPort.getExtent().getHeight() * factor; |
|
257 |
newViewPort.setExtent(r); |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
216 | 261 |
*Calculamos el viewPort para el zoom de la minimagen |
217 | 262 |
*/ |
218 |
public void calcViewPort(){
|
|
263 |
public void initViewPort(){
|
|
219 | 264 |
if(centerPoint != null){ |
220 | 265 |
newViewPort = this.viewPort.cloneViewPort(); |
221 | 266 |
|
222 | 267 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa |
223 |
double relacionPixelWcWidth = ((viewPort.getExtent().getMaxX() - viewPort.getExtent().getMinX()) / ZOOM)/this.getWidth();
|
|
224 |
double relacionPixelWcHeight = ((viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY()) / ZOOM)/this.getHeight();
|
|
268 |
double relacionPixelWcWidth = ((viewPort.getExtent().getMaxX() - viewPort.getExtent().getMinX()) / zoom)/this.getWidth();
|
|
269 |
double relacionPixelWcHeight = ((viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY()) / zoom)/this.getHeight();
|
|
225 | 270 |
|
226 | 271 |
double wcOriginX = centerPoint.getX() - ((viewPort.getImageWidth()*relacionPixelWcWidth)/2); |
227 | 272 |
double wcOriginY = centerPoint.getY() - ((viewPort.getImageHeight()*relacionPixelWcHeight)/2); |
... | ... | |
249 | 294 |
*/ |
250 | 295 |
public void paint( Graphics g ) { |
251 | 296 |
//Creamos el fondo |
297 |
//Graphics g = strategy.getDrawGraphics(); |
|
252 | 298 |
Graphics2D g2D = (Graphics2D) g; |
253 | 299 |
g.setColor( Color.WHITE ); |
254 | 300 |
g.fillRect( 0,0,ancho,alto ); |
255 |
try{ |
|
256 |
if(viewPort != null){ |
|
257 |
calcViewPort(); |
|
258 |
//Si no tenemos las capas las cargamos |
|
301 |
try{ |
|
302 |
if(newViewPort != null){ |
|
303 |
//Si no tenemos las capas las cargamos |
|
259 | 304 |
if(flayers == null){ |
260 | 305 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
261 | 306 |
flayers = theView.getMapControl().getMapContext().getLayers(); |
... | ... | |
270 | 315 |
}catch (DriverException e) { |
271 | 316 |
e.printStackTrace(); |
272 | 317 |
} |
318 |
//strategy.show(); |
|
273 | 319 |
} |
274 | 320 |
|
275 | 321 |
/** |
... | ... | |
277 | 323 |
* @param pto Punto central. |
278 | 324 |
*/ |
279 | 325 |
public void setCenterPoint(Point2D pto){ |
280 |
System.out.println("--->"+pto); |
|
281 | 326 |
this.centerPoint = pto; |
282 | 327 |
} |
283 | 328 |
|
284 | 329 |
|
285 |
} |
|
286 |
|
|
330 |
} |
|
287 | 331 |
|
288 | 332 |
} |
Also available in: Unified diff