svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / ZoomControlPanel.java @ 4621
History | View | Annotate | Download (20 KB)
1 |
package com.iver.cit.gvsig.gui.Panels; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Canvas; |
5 |
import java.awt.Color; |
6 |
import java.awt.Component; |
7 |
import java.awt.Graphics; |
8 |
import java.awt.Graphics2D; |
9 |
import java.awt.GridBagConstraints; |
10 |
import java.awt.GridBagLayout; |
11 |
import java.awt.Image; |
12 |
import java.awt.event.ActionEvent; |
13 |
import java.awt.event.ActionListener; |
14 |
import java.awt.event.MouseEvent; |
15 |
import java.awt.event.MouseListener; |
16 |
import java.awt.event.MouseMotionListener; |
17 |
import java.awt.geom.Point2D; |
18 |
import java.awt.geom.Rectangle2D; |
19 |
import java.awt.image.BufferedImage; |
20 |
|
21 |
import javax.swing.ImageIcon; |
22 |
import javax.swing.JButton; |
23 |
import javax.swing.JOptionPane; |
24 |
import javax.swing.JPanel; |
25 |
|
26 |
import com.iver.andami.PluginServices; |
27 |
import com.iver.cit.gvsig.fmap.DriverException; |
28 |
import com.iver.cit.gvsig.fmap.ViewPort; |
29 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
32 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
33 |
import com.iver.cit.gvsig.gui.View; |
34 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
35 |
|
36 |
/**
|
37 |
* Panel que contiene los controles de zoom de la vista para
|
38 |
* afinar en la georreferenciaci?n.
|
39 |
*
|
40 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
41 |
*
|
42 |
*/
|
43 |
public class ZoomControlPanel extends JPanel implements ActionListener{ |
44 |
private JPanel pImage = null; |
45 |
private JPanel pControls = null; |
46 |
private JButton bZoomMas = null; |
47 |
private JButton bZoomMenos = null; |
48 |
|
49 |
private int sX = 140, sY = 140; |
50 |
private CanvasZone canvas = null; |
51 |
private ViewPort viewPort = null; |
52 |
|
53 |
public FLyrPoints lyrPoints = null; |
54 |
public FLyrGeoRaster lyrGeoRaster = null; |
55 |
public GeoreferencingDialog dialog = null; |
56 |
private boolean rightControl = false; |
57 |
|
58 |
|
59 |
|
60 |
/**
|
61 |
* This is the default constructor
|
62 |
*/
|
63 |
public ZoomControlPanel(boolean rightControl, GeoreferencingDialog dialog) { |
64 |
super();
|
65 |
this.rightControl = rightControl;
|
66 |
this.dialog = dialog;
|
67 |
initialize(rightControl); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* This method initializes this
|
72 |
*
|
73 |
* @return void
|
74 |
*/
|
75 |
private void initialize(boolean rightControl) { |
76 |
|
77 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
78 |
if(rightControl)
|
79 |
gridBagConstraints1.gridx = 1;
|
80 |
else
|
81 |
gridBagConstraints1.gridx = 0;
|
82 |
gridBagConstraints1.gridy = 0;
|
83 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
84 |
if(rightControl)
|
85 |
gridBagConstraints.gridx = 0;
|
86 |
else
|
87 |
gridBagConstraints.gridx = 1;
|
88 |
gridBagConstraints.gridy = 0;
|
89 |
this.setLayout(new GridBagLayout()); |
90 |
this.setPreferredSize(new java.awt.Dimension(175,142)); |
91 |
this.setSize(new java.awt.Dimension(175,142)); |
92 |
this.setLocation(new java.awt.Point(0,0)); |
93 |
this.add(getPImage(), gridBagConstraints);
|
94 |
this.add(getPControls(), gridBagConstraints1);
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Carga las capas de puntos y de raster georreferenciado
|
99 |
*
|
100 |
*/
|
101 |
public void loadLayer() throws InstantiationException{ |
102 |
//Cargamos las capas
|
103 |
this.lyrGeoRaster = dialog.getLyrGeoRaster();
|
104 |
this.lyrPoints = dialog.getLyrPoints();
|
105 |
|
106 |
if(lyrGeoRaster == null || lyrPoints == null) |
107 |
throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada"); |
108 |
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* This method initializes jPanel
|
113 |
*
|
114 |
* @return javax.swing.JPanel
|
115 |
*/
|
116 |
private JPanel getPImage() { |
117 |
if (pImage == null) { |
118 |
pImage = new JPanel(); |
119 |
BorderLayout borderLayout = new BorderLayout(); |
120 |
pImage.setLayout(borderLayout); |
121 |
pImage.setPreferredSize(new java.awt.Dimension(140,140)); |
122 |
pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
123 |
pImage.add(getCanvas(), BorderLayout.CENTER);
|
124 |
} |
125 |
return pImage;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initilizes canvas
|
130 |
* @return CanvasZone
|
131 |
*/
|
132 |
public CanvasZone getCanvas(){
|
133 |
if(canvas == null){ |
134 |
canvas = new CanvasZone(sX, sY, this); |
135 |
canvas.setVisible(false);
|
136 |
canvas.addMouseListener(canvas); |
137 |
canvas.addMouseMotionListener(canvas); |
138 |
} |
139 |
return canvas;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* This method initializes jPanel1
|
144 |
*
|
145 |
* @return javax.swing.JPanel
|
146 |
*/
|
147 |
private JPanel getPControls() { |
148 |
if (pControls == null) { |
149 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
150 |
gridBagConstraints3.gridx = 0;
|
151 |
gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0); |
152 |
gridBagConstraints3.gridy = 1;
|
153 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
154 |
gridBagConstraints2.gridx = 0;
|
155 |
gridBagConstraints2.gridy = 0;
|
156 |
pControls = new JPanel(); |
157 |
pControls.setLayout(new GridBagLayout()); |
158 |
pControls.setPreferredSize(new java.awt.Dimension(33,140)); |
159 |
pControls.add(getBZoomMas(), gridBagConstraints2); |
160 |
pControls.add(getBZoomMenos(), gridBagConstraints3); |
161 |
} |
162 |
return pControls;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* This method initializes jButton
|
167 |
*
|
168 |
* @return javax.swing.JButton
|
169 |
*/
|
170 |
private JButton getBZoomMas() { |
171 |
if (bZoomMas == null) { |
172 |
bZoomMas = new JButton(); |
173 |
bZoomMas.setPreferredSize(new java.awt.Dimension(25,25)); |
174 |
bZoomMas.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/aumentar.png"))); |
175 |
bZoomMas.addActionListener(this);
|
176 |
} |
177 |
return bZoomMas;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* This method initializes jButton
|
182 |
*
|
183 |
* @return javax.swing.JButton
|
184 |
*/
|
185 |
private JButton getBZoomMenos() { |
186 |
if (bZoomMenos == null) { |
187 |
bZoomMenos = new JButton(); |
188 |
bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25)); |
189 |
bZoomMenos.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/disminuir.png"))); |
190 |
bZoomMenos.addActionListener(this);
|
191 |
} |
192 |
return bZoomMenos;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* @param viewPort The viewPort to set.
|
197 |
*/
|
198 |
public void setViewPort(ViewPort viewPort) { |
199 |
this.viewPort = viewPort;
|
200 |
getCanvas().setViewPort(this.viewPort);
|
201 |
} |
202 |
|
203 |
/**
|
204 |
*Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
|
205 |
*/
|
206 |
public void draw(){ |
207 |
if(!getDialog().isEnlarge())
|
208 |
getCanvas().loadBuffer(); |
209 |
getCanvas().repaint(); |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Asigna al canvas la propiedad de visibilidad a verdadero o falso.
|
214 |
* @param visible true para mostrar el canvas y false para ocultarlo
|
215 |
*/
|
216 |
public void setVisible(boolean visible){ |
217 |
canvas.setVisible(visible); |
218 |
if(!visible)
|
219 |
canvas.setSize(0,0); |
220 |
else{
|
221 |
canvas.setSize(sX, sY); |
222 |
} |
223 |
canvas.repaint(); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* Asigna el punto sobre el que se centrar? el zoom de la minimagen
|
228 |
* @param pto
|
229 |
*/
|
230 |
public void setCenterPoint(Point2D pto){ |
231 |
getCanvas().setCenterPoint(pto); |
232 |
} |
233 |
|
234 |
/**
|
235 |
* Recupera el n?mero de punto que se est? tratando
|
236 |
* @param n
|
237 |
*/
|
238 |
public int getNumberPoint(){ |
239 |
try{
|
240 |
if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0) |
241 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
242 |
else
|
243 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
244 |
}catch(NullPointerException exc){ |
245 |
return -1; |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Manejo de los controles zoom m?s y zoom menos
|
251 |
*/
|
252 |
public void actionPerformed(ActionEvent e) { |
253 |
if(e.getSource() == bZoomMas){
|
254 |
canvas.calcZoom(0.6);
|
255 |
canvas.repaint(); |
256 |
} |
257 |
|
258 |
if(e.getSource() == bZoomMenos){
|
259 |
canvas.calcZoom(1.8);
|
260 |
canvas.repaint(); |
261 |
} |
262 |
|
263 |
} |
264 |
|
265 |
|
266 |
/**
|
267 |
* @return Returns the rightControl.
|
268 |
*/
|
269 |
public boolean isRightControl() { |
270 |
return rightControl;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* @return Returns the lyrGeoRaster.
|
275 |
*/
|
276 |
public FLyrGeoRaster getLyrGeoRaster() {
|
277 |
return lyrGeoRaster;
|
278 |
} |
279 |
|
280 |
|
281 |
/**
|
282 |
* @return Returns the lyrPoints.
|
283 |
*/
|
284 |
public FLyrPoints getLyrPoints() {
|
285 |
try{
|
286 |
if(lyrPoints == null) |
287 |
this.loadLayer();
|
288 |
}catch(InstantiationException e){ |
289 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
290 |
PluginServices.getText(this, "error_capa_puntos")); |
291 |
} |
292 |
return lyrPoints;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* @return Returns the dialog.
|
297 |
*/
|
298 |
public GeoreferencingDialog getDialog() {
|
299 |
try{
|
300 |
if(dialog == null) |
301 |
this.loadLayer();
|
302 |
}catch(InstantiationException e){ |
303 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
304 |
PluginServices.getText(this, "error_capa_puntos")); |
305 |
} |
306 |
return dialog;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Asigna el viewPort recalculado
|
311 |
* @param vp ViewPort
|
312 |
*/
|
313 |
public void setNewViewPort(ViewPort vp){ |
314 |
canvas.setNewViewPort(vp); |
315 |
} |
316 |
|
317 |
/**
|
318 |
*Limpia el canvas
|
319 |
*/
|
320 |
public void clear(){ |
321 |
canvas.setCleanCanvas(true);
|
322 |
canvas.repaint(); |
323 |
} |
324 |
|
325 |
/**
|
326 |
* Control que representa la zona de dibujado de la ventana. Este se encarga de
|
327 |
* repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
|
328 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
329 |
*/
|
330 |
public class CanvasZone extends Canvas implements MouseListener, MouseMotionListener{ |
331 |
private ZoomControlPanel zoomControl = null; |
332 |
private int ancho; |
333 |
private int alto; |
334 |
private FLayers flayers = null; |
335 |
private ViewPort viewPort = null; |
336 |
private ViewPort newViewPort = null; |
337 |
private Point2D centerPoint = null; |
338 |
private int initZoom = 20; |
339 |
private boolean dragged = false; |
340 |
private Image dobleBuffer = null; |
341 |
private BufferedImage imgTmp = null; |
342 |
private Graphics dbGraphics = null; |
343 |
private boolean cleanCanvas = false; |
344 |
|
345 |
/**
|
346 |
* Puntos inicial y final para el desplazamiento del punto de control
|
347 |
*/
|
348 |
private Point2D ptoIni = null, ptoFin = null; |
349 |
private Point2D movDragged = null, initCrux = null; |
350 |
|
351 |
|
352 |
public CanvasZone( int anc,int alt, ZoomControlPanel zc) { |
353 |
zoomControl = zc; |
354 |
ancho = anc; |
355 |
alto = alt; |
356 |
|
357 |
this.setSize(ancho, alto);
|
358 |
this.setBackground(Color.WHITE); |
359 |
|
360 |
imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
361 |
dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
362 |
dbGraphics = dobleBuffer.getGraphics(); |
363 |
} |
364 |
|
365 |
/**
|
366 |
* Asigna el viewPort
|
367 |
* @param vp ViewPort
|
368 |
*/
|
369 |
public void setViewPort(ViewPort vp){ |
370 |
this.viewPort = vp;
|
371 |
this.initViewPort(vp, this.centerPoint, null); |
372 |
} |
373 |
|
374 |
/**
|
375 |
* Asigna el viewPort recalculado
|
376 |
* @param vp ViewPort
|
377 |
*/
|
378 |
public void setNewViewPort(ViewPort vp){ |
379 |
this.newViewPort = vp;
|
380 |
} |
381 |
|
382 |
/**
|
383 |
* Calcula el zoom dependiendo del factor de escala pasado por
|
384 |
* par?metro.
|
385 |
*/
|
386 |
public void calcZoom(double factor){ |
387 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
388 |
double nuevoX = centerPoint.getX() -
|
389 |
((newViewPort.getExtent().getWidth() * factor) / 2.0);
|
390 |
double nuevoY = centerPoint.getY() -
|
391 |
((newViewPort.getExtent().getHeight() * factor) / 2.0);
|
392 |
r.x = nuevoX; |
393 |
r.y = nuevoY; |
394 |
r.width = newViewPort.getExtent().getWidth() * factor; |
395 |
r.height = newViewPort.getExtent().getHeight() * factor; |
396 |
newViewPort.setExtent(r); |
397 |
newViewPort.setScale(); |
398 |
} |
399 |
|
400 |
|
401 |
/**
|
402 |
*Calculamos el viewPort para el zoom de la minimagen
|
403 |
*/
|
404 |
public ViewPort initViewPort(ViewPort vp, Point2D center, ViewPort vpDest){ |
405 |
if(center != null){ |
406 |
|
407 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
408 |
double relacionPixelWcWidth = ((vp.getExtent().getMaxX() - vp.getExtent().getMinX()) / initZoom)/ancho;
|
409 |
double relacionPixelWcHeight = ((vp.getExtent().getMaxY() - vp.getExtent().getMinY()) / initZoom)/alto;
|
410 |
|
411 |
double wcOriginX = center.getX() - ((vp.getImageWidth()*relacionPixelWcWidth)/2); |
412 |
double wcOriginY = center.getY() - ((vp.getImageHeight()*relacionPixelWcHeight)/2); |
413 |
|
414 |
double wcDstMinX = wcOriginX;
|
415 |
double wcDstMinY = wcOriginY;
|
416 |
double wcDstMaxX = wcDstMinX + (vp.getImageWidth()*relacionPixelWcWidth);
|
417 |
double wcDstMaxY = wcDstMinY + (vp.getImageHeight()*relacionPixelWcHeight);
|
418 |
|
419 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
420 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
421 |
|
422 |
Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
423 |
|
424 |
if(vpDest == null){ |
425 |
newViewPort = vp.cloneViewPort(); |
426 |
newViewPort.setExtent(ext); |
427 |
newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));
|
428 |
newViewPort.setScale(); |
429 |
return newViewPort;
|
430 |
}else{
|
431 |
vpDest.setExtent(ext); |
432 |
vpDest.setScale(); |
433 |
return vpDest;
|
434 |
} |
435 |
|
436 |
} |
437 |
return null; |
438 |
} |
439 |
|
440 |
/**
|
441 |
* Dibuja sobre el graphics de la mini imagen la imagen
|
442 |
* definida en el newViewPort.
|
443 |
*/
|
444 |
public void loadBuffer(){ |
445 |
Graphics2D gTmp = (Graphics2D)imgTmp.getGraphics(); |
446 |
if(!dragged){
|
447 |
dbGraphics.setColor( Color.WHITE );
|
448 |
dbGraphics.fillRect( 0,0,ancho,alto ); |
449 |
gTmp.setColor( Color.WHITE );
|
450 |
gTmp.fillRect( 0,0,ancho,alto ); |
451 |
|
452 |
try{
|
453 |
if(newViewPort != null){ |
454 |
if(zoomControl.getNumberPoint() != -1){//Salvamos el miniextent si hay puntos en la lista |
455 |
if(!zoomControl.isRightControl())
|
456 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
457 |
centerPoint, |
458 |
newViewPort, |
459 |
true);
|
460 |
else
|
461 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
462 |
centerPoint, |
463 |
newViewPort, |
464 |
false);
|
465 |
} |
466 |
//Si no tenemos las capas las cargamos
|
467 |
if(flayers == null){ |
468 |
View theView = null; |
469 |
try{
|
470 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
471 |
}catch(ClassCastException exc){ |
472 |
return;
|
473 |
} |
474 |
flayers = theView.getMapControl().getMapContext().getLayers(); |
475 |
} |
476 |
|
477 |
//dibujamos
|
478 |
zoomControl.getLyrPoints().setDrawView(newViewPort); |
479 |
if(zoomControl.getDialog().isEnlarge()){
|
480 |
flayers.draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() { |
481 |
public boolean isCanceled() { |
482 |
return false; |
483 |
} |
484 |
},flayers.getFMap().getScaleView()); |
485 |
} |
486 |
flayers.draw(null, gTmp, newViewPort,new Cancellable() { |
487 |
public boolean isCanceled() { |
488 |
return false; |
489 |
} |
490 |
},flayers.getFMap().getScaleView()); |
491 |
|
492 |
} |
493 |
}catch (DriverException e) {
|
494 |
e.printStackTrace(); |
495 |
} |
496 |
}else{
|
497 |
double x, y;
|
498 |
if(movDragged != null){ |
499 |
x = (movDragged.getX() - ptoIni.getX()) + initCrux.getX(); |
500 |
y = (movDragged.getY() - ptoIni.getY()) + initCrux.getY(); |
501 |
}else{
|
502 |
x = ptoIni.getX() + initCrux.getX(); |
503 |
y = ptoIni.getY() + initCrux.getY(); |
504 |
} |
505 |
|
506 |
dbGraphics.drawImage(imgTmp, 0, 0, null); |
507 |
dbGraphics.setColor( Color.RED );
|
508 |
dbGraphics.drawLine((int)(x - 5), (int)y, (int)(x + 5), (int)y); |
509 |
dbGraphics.drawLine((int)x, (int)(y - 5), (int)x, (int)(y + 5)); |
510 |
} |
511 |
} |
512 |
|
513 |
|
514 |
public void update(Graphics g){ |
515 |
this.paint(g);
|
516 |
} |
517 |
|
518 |
/**
|
519 |
* Dibuja sobre el Graphics2D pasado el viewPort solicitado a
|
520 |
* la lista de capas.
|
521 |
* @param g
|
522 |
*/
|
523 |
public void paint( Graphics g ) { |
524 |
loadBuffer(); |
525 |
if(!cleanCanvas)
|
526 |
g.drawImage(dobleBuffer, 0, 0, null); |
527 |
else{
|
528 |
g.setColor( Color.WHITE );
|
529 |
g.fillRect( 0,0,ancho,alto ); |
530 |
cleanCanvas = false;
|
531 |
} |
532 |
} |
533 |
|
534 |
/**
|
535 |
* Asigna el punto donde se centrar? la vista de la minimagen
|
536 |
* @param pto Punto central.
|
537 |
*/
|
538 |
public void setCenterPoint(Point2D pto){ |
539 |
this.centerPoint = pto;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* Desplaza el extent al nuevo centro
|
544 |
* @param pto
|
545 |
*/
|
546 |
public void shiftExtent(Point2D pto){ |
547 |
this.setCenterPoint(pto);
|
548 |
this.calcZoom(1); |
549 |
} |
550 |
|
551 |
/* (non-Javadoc)
|
552 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
553 |
*/
|
554 |
public void mouseClicked(MouseEvent ev) { |
555 |
|
556 |
} |
557 |
|
558 |
/* (non-Javadoc)
|
559 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
560 |
*/
|
561 |
public void mouseEntered(MouseEvent arg0) { |
562 |
|
563 |
} |
564 |
|
565 |
/* (non-Javadoc)
|
566 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
567 |
*/
|
568 |
public void mouseExited(MouseEvent arg0) { |
569 |
|
570 |
} |
571 |
|
572 |
/**
|
573 |
* Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
|
574 |
*
|
575 |
*/
|
576 |
public void mousePressed(MouseEvent ev) { |
577 |
this.movDragged = ptoIni = ev.getPoint();
|
578 |
try{
|
579 |
zoomControl.loadLayer(); |
580 |
initCrux = new Point2D.Double(); |
581 |
initCrux.setLocation(this.getWidth() / 2, this.getHeight() / 2); |
582 |
this.dragged = true; |
583 |
repaint(); |
584 |
}catch(InstantiationException e){ |
585 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
586 |
PluginServices.getText(this, "error_capa_puntos")); |
587 |
} |
588 |
} |
589 |
|
590 |
/* (non-Javadoc)
|
591 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
592 |
*/
|
593 |
public void mouseReleased(MouseEvent ev) { |
594 |
View theView = null; |
595 |
try{
|
596 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
597 |
}catch(ClassCastException exc){ |
598 |
return;
|
599 |
} |
600 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
601 |
ptoFin = ev.getPoint(); |
602 |
this.dragged = false; |
603 |
|
604 |
double destX = newViewPort.getExtent().getMinX() + ((ptoFin.getX() * (centerPoint.getX() - newViewPort.getExtent().getMinX())) / ptoIni.getX());
|
605 |
double destY = newViewPort.getExtent().getMinY() + (((this.getHeight() - ptoFin.getY()) * (centerPoint.getY() - newViewPort.getExtent().getMinY())) / (this.getHeight() - ptoIni.getY())); |
606 |
|
607 |
int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
608 |
|
609 |
FLyrPoints lp = zoomControl.getLyrPoints();//(FLyrPoints)lyr;
|
610 |
|
611 |
if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen |
612 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(destX, destY);
|
613 |
|
614 |
if(pixelImg == null){ |
615 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
616 |
PluginServices.getText(this, "fuera_de_extent")); |
617 |
return;
|
618 |
} |
619 |
zoomControl.getLyrGeoRaster().updateData( nPoint, |
620 |
pixelImg, |
621 |
null,
|
622 |
zoomControl.getDialog(), |
623 |
null);
|
624 |
|
625 |
//Actualizamos la otra miniimagen
|
626 |
shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg)); |
627 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
628 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
629 |
}else{ //Control de actualizaci?n de coordenadas del mundo |
630 |
Point2D mapPoint = new Point2D.Double(); |
631 |
mapPoint.setLocation(destX, destY); |
632 |
zoomControl.getLyrGeoRaster().updateData( nPoint, |
633 |
null,
|
634 |
mapPoint, |
635 |
zoomControl.getDialog(), |
636 |
null);
|
637 |
|
638 |
//Actualizamos la otra miniimagen
|
639 |
shiftExtent(mapPoint); |
640 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
641 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
642 |
} |
643 |
repaint(); |
644 |
theView.getMapControl().getMapContext().invalidate(); |
645 |
} |
646 |
|
647 |
/* (non-Javadoc)
|
648 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
649 |
*/
|
650 |
public void mouseDragged(MouseEvent ev) { |
651 |
this.movDragged = ev.getPoint();
|
652 |
repaint(); |
653 |
|
654 |
} |
655 |
|
656 |
/* (non-Javadoc)
|
657 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
658 |
*/
|
659 |
public void mouseMoved(MouseEvent arg0) { |
660 |
|
661 |
} |
662 |
|
663 |
/**
|
664 |
* @param cleanCanvas The cleanCanvas to set.
|
665 |
*/
|
666 |
public void setCleanCanvas(boolean cleanCanvas) { |
667 |
this.cleanCanvas = cleanCanvas;
|
668 |
} |
669 |
|
670 |
} |
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
} |