svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / ZoomControlPanel.java @ 3102
History | View | Annotate | Download (20.9 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) { |
65 |
super();
|
66 |
this.rightControl = rightControl;
|
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 la capa
|
103 |
View theView = null; |
104 |
try{
|
105 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
106 |
}catch(ClassCastException exc){ |
107 |
return;
|
108 |
} |
109 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
110 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
111 |
if( lyr instanceof FLyrGeoRaster && |
112 |
lyr.getName().startsWith("*") &&
|
113 |
lyr.isActive()){ |
114 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
115 |
try{
|
116 |
lyrPoints = lyrGeoRaster.getFLyrPoints(); |
117 |
}catch(ClassCastException exc){ |
118 |
throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada"); |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
if(lyrGeoRaster == null || lyrPoints == null) |
124 |
throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada"); |
125 |
|
126 |
dialog = lyrGeoRaster.getGeoDialog(); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* This method initializes jPanel
|
131 |
*
|
132 |
* @return javax.swing.JPanel
|
133 |
*/
|
134 |
private JPanel getPImage() { |
135 |
if (pImage == null) { |
136 |
pImage = new JPanel(); |
137 |
BorderLayout borderLayout = new BorderLayout(); |
138 |
pImage.setLayout(borderLayout); |
139 |
pImage.setPreferredSize(new java.awt.Dimension(140,140)); |
140 |
pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
141 |
pImage.add(getCanvas(), BorderLayout.CENTER);
|
142 |
} |
143 |
return pImage;
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* This method initilizes canvas
|
148 |
* @return CanvasZone
|
149 |
*/
|
150 |
private CanvasZone getCanvas(){
|
151 |
if(canvas == null){ |
152 |
canvas = new CanvasZone(sX, sY, this); |
153 |
canvas.setVisible(false);
|
154 |
canvas.addMouseListener(canvas); |
155 |
canvas.addMouseMotionListener(canvas); |
156 |
} |
157 |
return canvas;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* This method initializes jPanel1
|
162 |
*
|
163 |
* @return javax.swing.JPanel
|
164 |
*/
|
165 |
private JPanel getPControls() { |
166 |
if (pControls == null) { |
167 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
168 |
gridBagConstraints3.gridx = 0;
|
169 |
gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0); |
170 |
gridBagConstraints3.gridy = 1;
|
171 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
172 |
gridBagConstraints2.gridx = 0;
|
173 |
gridBagConstraints2.gridy = 0;
|
174 |
pControls = new JPanel(); |
175 |
pControls.setLayout(new GridBagLayout()); |
176 |
pControls.setPreferredSize(new java.awt.Dimension(33,140)); |
177 |
pControls.add(getBZoomMas(), gridBagConstraints2); |
178 |
pControls.add(getBZoomMenos(), gridBagConstraints3); |
179 |
} |
180 |
return pControls;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* This method initializes jButton
|
185 |
*
|
186 |
* @return javax.swing.JButton
|
187 |
*/
|
188 |
private JButton getBZoomMas() { |
189 |
if (bZoomMas == null) { |
190 |
bZoomMas = new JButton(); |
191 |
bZoomMas.setPreferredSize(new java.awt.Dimension(25,25)); |
192 |
bZoomMas.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/aumentar.png"))); |
193 |
bZoomMas.addActionListener(this);
|
194 |
} |
195 |
return bZoomMas;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* This method initializes jButton
|
200 |
*
|
201 |
* @return javax.swing.JButton
|
202 |
*/
|
203 |
private JButton getBZoomMenos() { |
204 |
if (bZoomMenos == null) { |
205 |
bZoomMenos = new JButton(); |
206 |
bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25)); |
207 |
bZoomMenos.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/disminuir.png"))); |
208 |
bZoomMenos.addActionListener(this);
|
209 |
} |
210 |
return bZoomMenos;
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* @param viewPort The viewPort to set.
|
215 |
*/
|
216 |
public void setViewPort(ViewPort viewPort) { |
217 |
this.viewPort = viewPort;
|
218 |
getCanvas().setViewPort(this.viewPort);
|
219 |
} |
220 |
|
221 |
/**
|
222 |
*Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
|
223 |
*/
|
224 |
public void draw(){ |
225 |
if(!getDialog().isEnlarge())
|
226 |
getCanvas().loadBuffer(); |
227 |
getCanvas().repaint(); |
228 |
} |
229 |
|
230 |
/**
|
231 |
* Asigna al canvas la propiedad de visibilidad a verdadero o falso.
|
232 |
* @param visible true para mostrar el canvas y false para ocultarlo
|
233 |
*/
|
234 |
public void setVisible(boolean visible){ |
235 |
canvas.setVisible(visible); |
236 |
if(!visible)
|
237 |
canvas.setSize(0,0); |
238 |
else{
|
239 |
canvas.setSize(sX, sY); |
240 |
} |
241 |
canvas.repaint(); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* Asigna el punto sobre el que se centrar? el zoom de la minimagen
|
246 |
* @param pto
|
247 |
*/
|
248 |
public void setCenterPoint(Point2D pto){ |
249 |
getCanvas().setCenterPoint(pto); |
250 |
} |
251 |
|
252 |
/**
|
253 |
* Recupera el n?mero de punto que se est? tratando
|
254 |
* @param n
|
255 |
*/
|
256 |
public int getNumberPoint(){ |
257 |
try{
|
258 |
if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0) |
259 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
260 |
else
|
261 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
262 |
}catch(NullPointerException exc){ |
263 |
return -1; |
264 |
} |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Manejo de los controles zoom m?s y zoom menos
|
269 |
*/
|
270 |
public void actionPerformed(ActionEvent e) { |
271 |
if(e.getSource() == bZoomMas){
|
272 |
canvas.calcZoom(0.6);
|
273 |
canvas.repaint(); |
274 |
} |
275 |
|
276 |
if(e.getSource() == bZoomMenos){
|
277 |
canvas.calcZoom(1.8);
|
278 |
canvas.repaint(); |
279 |
} |
280 |
|
281 |
} |
282 |
|
283 |
|
284 |
/**
|
285 |
* @return Returns the rightControl.
|
286 |
*/
|
287 |
public boolean isRightControl() { |
288 |
return rightControl;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* @return Returns the lyrGeoRaster.
|
293 |
*/
|
294 |
public FLyrGeoRaster getLyrGeoRaster() {
|
295 |
return lyrGeoRaster;
|
296 |
} |
297 |
|
298 |
|
299 |
/**
|
300 |
* @return Returns the lyrPoints.
|
301 |
*/
|
302 |
public FLyrPoints getLyrPoints() {
|
303 |
try{
|
304 |
if(lyrPoints == null) |
305 |
this.loadLayer();
|
306 |
}catch(InstantiationException e){ |
307 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
308 |
PluginServices.getText(this, "error_capa_puntos")); |
309 |
} |
310 |
return lyrPoints;
|
311 |
} |
312 |
|
313 |
/**
|
314 |
* @return Returns the dialog.
|
315 |
*/
|
316 |
public GeoreferencingDialog getDialog() {
|
317 |
try{
|
318 |
if(dialog == null) |
319 |
this.loadLayer();
|
320 |
}catch(InstantiationException e){ |
321 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
322 |
PluginServices.getText(this, "error_capa_puntos")); |
323 |
} |
324 |
return dialog;
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Asigna el viewPort recalculado
|
329 |
* @param vp ViewPort
|
330 |
*/
|
331 |
public void setNewViewPort(ViewPort vp){ |
332 |
canvas.setNewViewPort(vp); |
333 |
} |
334 |
|
335 |
/**
|
336 |
*Limpia el canvas
|
337 |
*/
|
338 |
public void clear(){ |
339 |
canvas.setCleanCanvas(true);
|
340 |
canvas.repaint(); |
341 |
} |
342 |
|
343 |
/**
|
344 |
* Control que representa la zona de dibujado de la ventana. Este se encarga de
|
345 |
* repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
|
346 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
347 |
*/
|
348 |
class CanvasZone extends Canvas implements MouseListener, MouseMotionListener{ |
349 |
private ZoomControlPanel zoomControl = null; |
350 |
private int ancho; |
351 |
private int alto; |
352 |
private FLayers flayers = null; |
353 |
private ViewPort viewPort = null; |
354 |
private ViewPort newViewPort = null; |
355 |
private Point2D centerPoint = null; |
356 |
private int initZoom = 20; |
357 |
private boolean dragged = false; |
358 |
private Image dobleBuffer = null; |
359 |
private BufferedImage imgTmp = null; |
360 |
private Graphics dbGraphics = null; |
361 |
private boolean cleanCanvas = false; |
362 |
|
363 |
/**
|
364 |
* Puntos inicial y final para el desplazamiento del punto de control
|
365 |
*/
|
366 |
private Point2D ptoIni = null, ptoFin = null; |
367 |
private Point2D movDragged = null, initCrux = null; |
368 |
|
369 |
|
370 |
public CanvasZone( int anc,int alt, ZoomControlPanel zc) { |
371 |
zoomControl = zc; |
372 |
ancho = anc; |
373 |
alto = alt; |
374 |
|
375 |
this.setSize(ancho, alto);
|
376 |
this.setBackground(Color.WHITE); |
377 |
|
378 |
imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
379 |
dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
380 |
dbGraphics = dobleBuffer.getGraphics(); |
381 |
} |
382 |
|
383 |
/**
|
384 |
* Asigna el viewPort
|
385 |
* @param vp ViewPort
|
386 |
*/
|
387 |
public void setViewPort(ViewPort vp){ |
388 |
this.viewPort = vp;
|
389 |
this.initViewPort();
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* Asigna el viewPort recalculado
|
394 |
* @param vp ViewPort
|
395 |
*/
|
396 |
public void setNewViewPort(ViewPort vp){ |
397 |
this.newViewPort = vp;
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* Calcula el zoom dependiendo del factor de escala pasado por
|
402 |
* par?metro.
|
403 |
*/
|
404 |
public void calcZoom(double factor){ |
405 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
406 |
double nuevoX = centerPoint.getX() -
|
407 |
((newViewPort.getExtent().getWidth() * factor) / 2.0);
|
408 |
double nuevoY = centerPoint.getY() -
|
409 |
((newViewPort.getExtent().getHeight() * factor) / 2.0);
|
410 |
r.x = nuevoX; |
411 |
r.y = nuevoY; |
412 |
r.width = newViewPort.getExtent().getWidth() * factor; |
413 |
r.height = newViewPort.getExtent().getHeight() * factor; |
414 |
newViewPort.setExtent(r); |
415 |
newViewPort.setScale(); |
416 |
} |
417 |
|
418 |
|
419 |
/**
|
420 |
*Calculamos el viewPort para el zoom de la minimagen
|
421 |
*/
|
422 |
public void initViewPort(){ |
423 |
if(centerPoint != null){ |
424 |
newViewPort = this.viewPort.cloneViewPort();
|
425 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
426 |
double relacionPixelWcWidth = ((viewPort.getExtent().getMaxX() - viewPort.getExtent().getMinX()) / initZoom)/ancho;
|
427 |
double relacionPixelWcHeight = ((viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY()) / initZoom)/alto;
|
428 |
|
429 |
double wcOriginX = centerPoint.getX() - ((viewPort.getImageWidth()*relacionPixelWcWidth)/2); |
430 |
double wcOriginY = centerPoint.getY() - ((viewPort.getImageHeight()*relacionPixelWcHeight)/2); |
431 |
|
432 |
double wcDstMinX = wcOriginX;
|
433 |
double wcDstMinY = wcOriginY;
|
434 |
double wcDstMaxX = wcDstMinX + (viewPort.getImageWidth()*relacionPixelWcWidth);
|
435 |
double wcDstMaxY = wcDstMinY + (viewPort.getImageHeight()*relacionPixelWcHeight);
|
436 |
|
437 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
438 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
439 |
|
440 |
Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
441 |
|
442 |
newViewPort.setExtent(ext); |
443 |
newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));
|
444 |
newViewPort.setScale(); |
445 |
} |
446 |
} |
447 |
|
448 |
public void loadBuffer(){ |
449 |
Graphics2D gTmp = (Graphics2D)imgTmp.getGraphics(); |
450 |
if(!dragged){
|
451 |
dbGraphics.setColor( Color.WHITE );
|
452 |
dbGraphics.fillRect( 0,0,ancho,alto ); |
453 |
gTmp.setColor( Color.WHITE );
|
454 |
gTmp.fillRect( 0,0,ancho,alto ); |
455 |
|
456 |
try{
|
457 |
if(newViewPort != null){ |
458 |
if(zoomControl.getNumberPoint() != -1){//Salvamos el miniextent si hay puntos en la lista |
459 |
if(!zoomControl.isRightControl())
|
460 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
461 |
centerPoint, |
462 |
newViewPort, |
463 |
true);
|
464 |
else
|
465 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
466 |
centerPoint, |
467 |
newViewPort, |
468 |
false);
|
469 |
} |
470 |
//Si no tenemos las capas las cargamos
|
471 |
if(flayers == null){ |
472 |
View theView = null; |
473 |
try{
|
474 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
475 |
}catch(ClassCastException exc){ |
476 |
return;
|
477 |
} |
478 |
flayers = theView.getMapControl().getMapContext().getLayers(); |
479 |
} |
480 |
//dibujamos
|
481 |
if(zoomControl.getDialog().isEnlarge())
|
482 |
flayers.draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() { |
483 |
public boolean isCanceled() { |
484 |
return false; |
485 |
} |
486 |
},flayers.getFMap().getScaleView()); |
487 |
flayers.draw(null, gTmp, newViewPort,new Cancellable() { |
488 |
public boolean isCanceled() { |
489 |
return false; |
490 |
} |
491 |
},flayers.getFMap().getScaleView()); |
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 |
if(flayers == null) |
610 |
flayers = theView.getMapControl().getMapContext().getLayers(); |
611 |
for(int i=0;i<flayers.getLayersCount();i++){ |
612 |
FLayer lyr = flayers.getLayer(i); |
613 |
if(lyr instanceof FLyrPoints){ |
614 |
FLyrPoints lp = (FLyrPoints)lyr; |
615 |
|
616 |
if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen |
617 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(destX, destY);
|
618 |
|
619 |
if(pixelImg == null){ |
620 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
621 |
PluginServices.getText(this, "fuera_de_extent")); |
622 |
return;
|
623 |
} |
624 |
zoomControl.getLyrGeoRaster().updateData( nPoint, |
625 |
pixelImg, |
626 |
null,
|
627 |
zoomControl.getDialog(), |
628 |
null,
|
629 |
lp); |
630 |
|
631 |
//Actualizamos la otra miniimagen
|
632 |
//zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().getCanvas().calcStoreZoom();
|
633 |
//setCenterPoint(zoomControl.getLyrGeoRaster().img2World(pixelImg));
|
634 |
shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg)); |
635 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
636 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
637 |
}else{ //Control de actualizaci?n de coordenadas del mundo |
638 |
Point2D mapPoint = new Point2D.Double(); |
639 |
mapPoint.setLocation(destX, destY); |
640 |
zoomControl.getLyrGeoRaster().updateData( nPoint, |
641 |
null,
|
642 |
mapPoint, |
643 |
zoomControl.getDialog(), |
644 |
null,
|
645 |
lp); |
646 |
|
647 |
//Actualizamos la otra miniimagen
|
648 |
//zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().getCanvas().calcStoreZoom();
|
649 |
//setCenterPoint(mapPoint);
|
650 |
shiftExtent(mapPoint); |
651 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
652 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
653 |
} |
654 |
|
655 |
} |
656 |
} |
657 |
|
658 |
theView.getMapControl().getMapContext().invalidate(); |
659 |
repaint(); |
660 |
} |
661 |
|
662 |
/* (non-Javadoc)
|
663 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
664 |
*/
|
665 |
public void mouseDragged(MouseEvent ev) { |
666 |
this.movDragged = ev.getPoint();
|
667 |
repaint(); |
668 |
|
669 |
} |
670 |
|
671 |
/* (non-Javadoc)
|
672 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
673 |
*/
|
674 |
public void mouseMoved(MouseEvent arg0) { |
675 |
|
676 |
} |
677 |
|
678 |
/**
|
679 |
* @param cleanCanvas The cleanCanvas to set.
|
680 |
*/
|
681 |
public void setCleanCanvas(boolean cleanCanvas) { |
682 |
this.cleanCanvas = cleanCanvas;
|
683 |
} |
684 |
|
685 |
} |
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
} |