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