svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / panels / ZoomControlPanel.java @ 4831
History | View | Annotate | Download (26.4 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Component; |
6 |
import java.awt.Cursor; |
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.Point; |
13 |
import java.awt.Toolkit; |
14 |
import java.awt.event.ActionEvent; |
15 |
import java.awt.event.ActionListener; |
16 |
import java.awt.event.MouseEvent; |
17 |
import java.awt.event.MouseListener; |
18 |
import java.awt.event.MouseMotionListener; |
19 |
import java.awt.geom.Point2D; |
20 |
import java.awt.geom.Rectangle2D; |
21 |
import java.awt.image.BufferedImage; |
22 |
|
23 |
import javax.swing.ImageIcon; |
24 |
import javax.swing.JButton; |
25 |
import javax.swing.JOptionPane; |
26 |
import javax.swing.JPanel; |
27 |
|
28 |
import com.iver.andami.PluginServices; |
29 |
import com.iver.cit.gvsig.fmap.DriverException; |
30 |
import com.iver.cit.gvsig.fmap.MapControl; |
31 |
import com.iver.cit.gvsig.fmap.ViewPort; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
34 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
35 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
36 |
import com.iver.cit.gvsig.gui.View; |
37 |
import com.iver.cit.gvsig.gui.dialogs.GeoreferencingDialog; |
38 |
import com.iver.cit.gvsig.utils.MathUtils; |
39 |
|
40 |
/**
|
41 |
* Panel que contiene los controles de zoom de la vista para
|
42 |
* afinar en la georreferenciaci?n.
|
43 |
*
|
44 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
45 |
*
|
46 |
*/
|
47 |
public class ZoomControlPanel extends JPanel implements ActionListener{ |
48 |
|
49 |
//**********************Vars**********************************
|
50 |
private JPanel pImage = null; |
51 |
private JPanel pControls = null; |
52 |
private JButton bZoomMas = null; |
53 |
private JButton bZoomMenos = null; |
54 |
private int sX = 140, sY = 140; |
55 |
private CanvasZone canvas = null; |
56 |
private ViewPort viewPort = null; |
57 |
public FLyrPoints lyrPoints = null; |
58 |
public FLyrGeoRaster lyrGeoRaster = null; |
59 |
public GeoreferencingDialog dialog = null; |
60 |
private boolean rightControl = false; |
61 |
//**********************End Vars******************************
|
62 |
|
63 |
//**********************Methods*******************************
|
64 |
/**
|
65 |
* This is the default constructor
|
66 |
*/
|
67 |
public ZoomControlPanel(boolean rightControl, GeoreferencingDialog dialog) { |
68 |
super();
|
69 |
this.rightControl = rightControl;
|
70 |
this.dialog = dialog;
|
71 |
initialize(rightControl); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* This method initializes this
|
76 |
*
|
77 |
* @return void
|
78 |
*/
|
79 |
private void initialize(boolean rightControl) { |
80 |
|
81 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
82 |
if(rightControl)
|
83 |
gridBagConstraints1.gridx = 1;
|
84 |
else
|
85 |
gridBagConstraints1.gridx = 0;
|
86 |
gridBagConstraints1.gridy = 0;
|
87 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
88 |
if(rightControl)
|
89 |
gridBagConstraints.gridx = 0;
|
90 |
else
|
91 |
gridBagConstraints.gridx = 1;
|
92 |
gridBagConstraints.gridy = 0;
|
93 |
this.setLayout(new GridBagLayout()); |
94 |
this.setPreferredSize(new java.awt.Dimension(175,142)); |
95 |
this.setSize(new java.awt.Dimension(175,142)); |
96 |
this.setLocation(new java.awt.Point(0,0)); |
97 |
this.add(getPImage(), gridBagConstraints);
|
98 |
this.add(getPControls(), gridBagConstraints1);
|
99 |
//Desactivamos el control en la inicializaci?n
|
100 |
this.setEnabled(false); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Carga las capas de puntos y de raster georreferenciado
|
105 |
*
|
106 |
*/
|
107 |
public void loadLayer() throws InstantiationException{ |
108 |
//Cargamos las capas
|
109 |
this.lyrGeoRaster = dialog.getLyrGeoRaster();
|
110 |
this.lyrPoints = dialog.getLyrPoints();
|
111 |
|
112 |
if(lyrGeoRaster == null || lyrPoints == null) |
113 |
throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada"); |
114 |
|
115 |
} |
116 |
|
117 |
/**
|
118 |
*Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
|
119 |
*/
|
120 |
public void draw(){ |
121 |
if(!getDialog().isEnlarge())
|
122 |
getCanvas().loadBuffer(); |
123 |
getCanvas().repaint(); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Manejo de los controles zoom m?s y zoom menos
|
128 |
*/
|
129 |
public void actionPerformed(ActionEvent e) { |
130 |
if(e.getSource() == bZoomMas){
|
131 |
canvas.calcZoom(0.6);
|
132 |
canvas.repaint(); |
133 |
} |
134 |
|
135 |
if(e.getSource() == bZoomMenos){
|
136 |
canvas.calcZoom(1.8);
|
137 |
canvas.repaint(); |
138 |
} |
139 |
|
140 |
} |
141 |
|
142 |
/**
|
143 |
*Limpia el canvas
|
144 |
*/
|
145 |
public void clear(){ |
146 |
canvas.setCleanCanvas(true);
|
147 |
canvas.repaint(); |
148 |
} |
149 |
//**********************End Methods***************************
|
150 |
|
151 |
//**********************Setters & Getters*********************
|
152 |
/**
|
153 |
* @param viewPort The viewPort to set.
|
154 |
*/
|
155 |
public void setViewPort(ViewPort viewPort) { |
156 |
this.viewPort = viewPort;
|
157 |
getCanvas().setViewPort(this.viewPort);
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* This method initializes jPanel
|
162 |
*
|
163 |
* @return javax.swing.JPanel
|
164 |
*/
|
165 |
private JPanel getPImage() { |
166 |
if (pImage == null) { |
167 |
pImage = new JPanel(); |
168 |
BorderLayout borderLayout = new BorderLayout(); |
169 |
pImage.setLayout(borderLayout); |
170 |
pImage.setPreferredSize(new java.awt.Dimension(140,140)); |
171 |
pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
172 |
pImage.add(getCanvas(), BorderLayout.CENTER);
|
173 |
} |
174 |
return pImage;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* This method initilizes canvas
|
179 |
* @return CanvasZone
|
180 |
*/
|
181 |
public CanvasZone getCanvas(){
|
182 |
if(canvas == null){ |
183 |
canvas = new CanvasZone(sX, sY, this); |
184 |
canvas.setVisible(false);
|
185 |
canvas.addMouseListener(canvas); |
186 |
canvas.addMouseMotionListener(canvas); |
187 |
} |
188 |
return canvas;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* This method initializes jPanel1
|
193 |
*
|
194 |
* @return javax.swing.JPanel
|
195 |
*/
|
196 |
private JPanel getPControls() { |
197 |
if (pControls == null) { |
198 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
199 |
gridBagConstraints3.gridx = 0;
|
200 |
gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0); |
201 |
gridBagConstraints3.gridy = 1;
|
202 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
203 |
gridBagConstraints2.gridx = 0;
|
204 |
gridBagConstraints2.gridy = 0;
|
205 |
pControls = new JPanel(); |
206 |
pControls.setLayout(new GridBagLayout()); |
207 |
pControls.setPreferredSize(new java.awt.Dimension(33,140)); |
208 |
pControls.add(getBZoomMas(), gridBagConstraints2); |
209 |
pControls.add(getBZoomMenos(), gridBagConstraints3); |
210 |
} |
211 |
return pControls;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* This method initializes jButton
|
216 |
*
|
217 |
* @return javax.swing.JButton
|
218 |
*/
|
219 |
private JButton getBZoomMas() { |
220 |
if (bZoomMas == null) { |
221 |
bZoomMas = new JButton(); |
222 |
bZoomMas.setPreferredSize(new java.awt.Dimension(25,25)); |
223 |
bZoomMas.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/panels/images/aumentar.png"))); |
224 |
bZoomMas.addActionListener(this);
|
225 |
} |
226 |
return bZoomMas;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* This method initializes jButton
|
231 |
*
|
232 |
* @return javax.swing.JButton
|
233 |
*/
|
234 |
private JButton getBZoomMenos() { |
235 |
if (bZoomMenos == null) { |
236 |
bZoomMenos = new JButton(); |
237 |
bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25)); |
238 |
bZoomMenos.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/panels/images/disminuir.png"))); |
239 |
bZoomMenos.addActionListener(this);
|
240 |
} |
241 |
return bZoomMenos;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Obtiene true si se trata de un control con los botones de zoom
|
246 |
* a la derecha y false si los tiene a la izquierda.
|
247 |
* @return Returns the rightControl.
|
248 |
*/
|
249 |
public boolean isRightControl() { |
250 |
return rightControl;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Obtiene la capa de imagen georreferenciada.
|
255 |
* @return Returns the lyrGeoRaster.
|
256 |
*/
|
257 |
public FLyrGeoRaster getLyrGeoRaster() {
|
258 |
return lyrGeoRaster;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* Obtiene la capa de puntos.
|
263 |
* @return Returns the lyrPoints.
|
264 |
*/
|
265 |
public FLyrPoints getLyrPoints() {
|
266 |
try{
|
267 |
if(lyrPoints == null) |
268 |
this.loadLayer();
|
269 |
}catch(InstantiationException e){ |
270 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
271 |
PluginServices.getText(this, "error_capa_puntos")); |
272 |
} |
273 |
return lyrPoints;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* @return Returns the dialog.
|
278 |
*/
|
279 |
public GeoreferencingDialog getDialog() {
|
280 |
try{
|
281 |
if(dialog == null) |
282 |
this.loadLayer();
|
283 |
}catch(InstantiationException e){ |
284 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
285 |
PluginServices.getText(this, "error_capa_puntos")); |
286 |
} |
287 |
return dialog;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Asigna el viewPort recalculado
|
292 |
* @param vp ViewPort
|
293 |
*/
|
294 |
public void setNewViewPort(ViewPort vp){ |
295 |
canvas.setNewViewPort(vp); |
296 |
} |
297 |
|
298 |
/**
|
299 |
* Obtiene el viewPort recalculado
|
300 |
* @return vp ViewPort
|
301 |
*/
|
302 |
public ViewPort getNewViewPort(){
|
303 |
return canvas.getNewViewPort();
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Asigna al canvas la propiedad de visibilidad a verdadero o falso.
|
308 |
* @param visible true para mostrar el canvas y false para ocultarlo
|
309 |
*/
|
310 |
public void setVisible(boolean visible){ |
311 |
canvas.setVisible(visible); |
312 |
canvas.repaint(); |
313 |
} |
314 |
|
315 |
/**
|
316 |
* Asigna el punto sobre el que se centrar? el zoom de la minimagen
|
317 |
* @param pto
|
318 |
*/
|
319 |
public void setCenterPoint(Point2D pto){ |
320 |
getCanvas().setCenterPoint(pto); |
321 |
} |
322 |
|
323 |
/**
|
324 |
* Recupera el n?mero de punto que se est? tratando
|
325 |
* @param n
|
326 |
*/
|
327 |
public int getNumberPoint(){ |
328 |
try{
|
329 |
if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0) |
330 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
331 |
else
|
332 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
333 |
}catch(NullPointerException exc){ |
334 |
return -1; |
335 |
} |
336 |
} |
337 |
|
338 |
/**
|
339 |
* Activa o desactiva este panel y todos los que lo componen
|
340 |
* @param enabled variable booleana para la activaci?n y/o desactivaci?n
|
341 |
*/
|
342 |
public void setEnabled(boolean enabled){ |
343 |
this.getBZoomMas().setEnabled(enabled);
|
344 |
this.getBZoomMenos().setEnabled(enabled);
|
345 |
this.getCanvas().setEnableEvent(enabled);
|
346 |
} |
347 |
|
348 |
//**********************End Setters & Getters*****************
|
349 |
/**
|
350 |
* Control que representa la zona de dibujado de la ventana. Este se encarga de
|
351 |
* repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
|
352 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
353 |
*/
|
354 |
public class CanvasZone extends JPanel implements MouseListener, MouseMotionListener{ |
355 |
|
356 |
//**********************Params********************************
|
357 |
/**
|
358 |
* Zoom inicial de la miniimagen
|
359 |
*/
|
360 |
private int initZoom = 20; |
361 |
//**********************End Params****************************
|
362 |
|
363 |
//**********************Vars**********************************
|
364 |
private ZoomControlPanel zoomControl = null; |
365 |
private int ancho; |
366 |
private int alto; |
367 |
private FLayers flayers = null; |
368 |
private ViewPort newViewPort = null; |
369 |
private Point2D centerPoint = null; |
370 |
private Image dobleBuffer = null; |
371 |
private BufferedImage imgTmp = null; |
372 |
private Graphics dbGraphics = null; |
373 |
private boolean cleanCanvas = false; |
374 |
/**
|
375 |
* Cuando el control est? desactivado necesitamos controlar con esta variable que
|
376 |
* aunque se pinche sobre el canvas no se capture el evento
|
377 |
*/
|
378 |
private boolean enableEvent = true; |
379 |
/**
|
380 |
* Puntos inicial y final para el desplazamiento del punto de control
|
381 |
*/
|
382 |
private Point2D ptoIni = null, ptoFin = null; |
383 |
private Point2D movDragged = null, initCrux = null; |
384 |
private boolean dragged = false; |
385 |
private final Image redCursor = new ImageIcon(this.getClass().getResource( |
386 |
"images/icoRed.png")).getImage();
|
387 |
private final Image blueCursor = new ImageIcon(this.getClass().getResource( |
388 |
"images/icoBlue.png")).getImage();
|
389 |
//**********************End Vars******************************
|
390 |
|
391 |
//**********************Methods*******************************
|
392 |
/**
|
393 |
*
|
394 |
*/
|
395 |
public CanvasZone( int anc,int alt, ZoomControlPanel zc) { |
396 |
zoomControl = zc; |
397 |
ancho = anc; |
398 |
alto = alt; |
399 |
|
400 |
this.setSize(ancho, alto);
|
401 |
this.setBackground(Color.WHITE); |
402 |
|
403 |
imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
404 |
dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
405 |
dbGraphics = dobleBuffer.getGraphics(); |
406 |
} |
407 |
|
408 |
/**
|
409 |
* Calcula el zoom dependiendo del factor de escala pasado por
|
410 |
* par?metro.
|
411 |
*/
|
412 |
public void calcZoom(double factor){ |
413 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
414 |
double nuevoX = centerPoint.getX() -
|
415 |
((newViewPort.getExtent().getWidth() * factor) / 2.0);
|
416 |
double nuevoY = centerPoint.getY() -
|
417 |
((newViewPort.getExtent().getHeight() * factor) / 2.0);
|
418 |
r.x = nuevoX; |
419 |
r.y = nuevoY; |
420 |
r.width = newViewPort.getExtent().getWidth() * factor; |
421 |
r.height = newViewPort.getExtent().getHeight() * factor; |
422 |
newViewPort.setExtent(r); |
423 |
newViewPort.setScale(); |
424 |
} |
425 |
|
426 |
|
427 |
/**
|
428 |
*Calculamos el viewPort para el zoom de la minimagen
|
429 |
*/
|
430 |
public ViewPort initViewPort(ViewPort vp, Point2D center, ViewPort vpDest){ |
431 |
if(center != null){ |
432 |
|
433 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
434 |
double relacionPixelWcWidth = ((vp.getExtent().getMaxX() - vp.getExtent().getMinX()) / initZoom) / ancho;
|
435 |
double relacionPixelWcHeight = ((vp.getExtent().getMaxY() - vp.getExtent().getMinY()) / initZoom) / alto;
|
436 |
|
437 |
double wcOriginX = center.getX() - ((vp.getImageWidth() * relacionPixelWcWidth) / 2); |
438 |
double wcOriginY = center.getY() - ((vp.getImageHeight() * relacionPixelWcHeight) / 2); |
439 |
|
440 |
double wcDstMinX = wcOriginX;
|
441 |
double wcDstMinY = wcOriginY;
|
442 |
double wcDstMaxX = wcDstMinX + (vp.getImageWidth()*relacionPixelWcWidth);
|
443 |
double wcDstMaxY = wcDstMinY + (vp.getImageHeight()*relacionPixelWcHeight);
|
444 |
|
445 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
446 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
447 |
|
448 |
Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
449 |
|
450 |
if(vpDest == null){ |
451 |
newViewPort = vp.cloneViewPort(); |
452 |
newViewPort.setExtent(ext); |
453 |
newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));
|
454 |
newViewPort.setScale(); |
455 |
return newViewPort;
|
456 |
}else{
|
457 |
vpDest.setExtent(ext); |
458 |
vpDest.setScale(); |
459 |
return vpDest;
|
460 |
} |
461 |
|
462 |
} |
463 |
return null; |
464 |
} |
465 |
|
466 |
/**
|
467 |
* Dibuja sobre el graphics de la mini imagen la imagen
|
468 |
* definida en el newViewPort.
|
469 |
*/
|
470 |
public void loadBuffer(){ |
471 |
Graphics2D gTmp = (Graphics2D)imgTmp.getGraphics(); |
472 |
|
473 |
|
474 |
dbGraphics.setColor( Color.WHITE );
|
475 |
dbGraphics.fillRect( 0,0,ancho,alto ); |
476 |
gTmp.setColor( Color.WHITE );
|
477 |
gTmp.fillRect( 0,0,ancho,alto ); |
478 |
|
479 |
try{
|
480 |
if(newViewPort != null){ |
481 |
if(zoomControl.getNumberPoint() != -1){//Salvamos el miniextent si hay puntos en la lista |
482 |
if(!zoomControl.isRightControl())
|
483 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
484 |
centerPoint, |
485 |
newViewPort, |
486 |
true);
|
487 |
else
|
488 |
zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), |
489 |
centerPoint, |
490 |
newViewPort, |
491 |
false);
|
492 |
} |
493 |
//Si no tenemos las capas las cargamos
|
494 |
if(flayers == null){ |
495 |
View theView = null; |
496 |
try{
|
497 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
498 |
}catch(ClassCastException exc){ |
499 |
return;
|
500 |
} |
501 |
flayers = theView.getMapControl().getMapContext().getLayers(); |
502 |
} |
503 |
|
504 |
/*Dibujamos sobre las miniimagenes
|
505 |
Forzamos un draw de las capas para dibujar la vista sobre el control de las miniimagenes.
|
506 |
Como la capa gr?fica est? en FMap esta no aparece en el dibujado de FLayers por los que
|
507 |
forzaremos el pintado tambi?n de la capa de puntos sobre nuestro control*/
|
508 |
|
509 |
if(zoomControl.getDialog().isEnlarge()){
|
510 |
if(zoomControl.getNumberPoint() != -1){ |
511 |
flayers.draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() { |
512 |
public boolean isCanceled() { |
513 |
return false; |
514 |
} |
515 |
},flayers.getFMap().getScaleView()); |
516 |
zoomControl.getLyrPoints().draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() { |
517 |
public boolean isCanceled() { |
518 |
return false; |
519 |
} |
520 |
},flayers.getFMap().getScaleView()); |
521 |
} |
522 |
} |
523 |
|
524 |
flayers.draw(null, gTmp, newViewPort,new Cancellable() { |
525 |
public boolean isCanceled() { |
526 |
return false; |
527 |
} |
528 |
},flayers.getFMap().getScaleView()); |
529 |
zoomControl.getLyrPoints().draw(null, gTmp, newViewPort,new Cancellable() { |
530 |
public boolean isCanceled() { |
531 |
return false; |
532 |
} |
533 |
},flayers.getFMap().getScaleView()); |
534 |
|
535 |
} |
536 |
}catch (DriverException e) {
|
537 |
e.printStackTrace(); |
538 |
} |
539 |
} |
540 |
|
541 |
/**
|
542 |
*
|
543 |
*/
|
544 |
public void update(Graphics g){ |
545 |
this.paint(g);
|
546 |
} |
547 |
|
548 |
/**
|
549 |
* Dibuja sobre el Graphics2D pasado el viewPort solicitado a
|
550 |
* la lista de capas.
|
551 |
* @param g
|
552 |
*/
|
553 |
public void paint( Graphics g ) { |
554 |
if(!cleanCanvas){
|
555 |
loadBuffer(); |
556 |
g.drawImage(dobleBuffer, 0, 0, null); |
557 |
AdjustGeorefPanel p = zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel(); |
558 |
try{
|
559 |
if(!this.zoomControl.isRightControl()) |
560 |
p.setLZoomLeft("1:"+((int)newViewPort.getScale())); |
561 |
else
|
562 |
p.setLZoomRight("1:"+((int)newViewPort.getScale())); |
563 |
}catch(NullPointerException exc){ |
564 |
//No ponemos la escala
|
565 |
} |
566 |
}else{
|
567 |
g.setColor( Color.WHITE );
|
568 |
g.fillRect( 0,0,ancho,alto ); |
569 |
cleanCanvas = false;
|
570 |
} |
571 |
} |
572 |
|
573 |
/**
|
574 |
* Desplaza el extent al nuevo centro
|
575 |
* @param pto
|
576 |
*/
|
577 |
public void shiftExtent(Point2D pto){ |
578 |
this.setCenterPoint(pto);
|
579 |
this.calcZoom(1); |
580 |
} |
581 |
|
582 |
/* (non-Javadoc)
|
583 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
584 |
*/
|
585 |
public void mouseClicked(MouseEvent ev) { |
586 |
|
587 |
} |
588 |
|
589 |
/**
|
590 |
* Cuando el rat?n entra dentro del control fijamos el valor de las coordenadas
|
591 |
* que tiene el punto seleccionado. De esta forma cuando salga del control podr?
|
592 |
* volver a restaurarlo en caso de que no haya sido cambiado.
|
593 |
*/
|
594 |
public void mouseEntered(MouseEvent arg0) { |
595 |
if(isEnableEvent()){
|
596 |
if(!zoomControl.rightControl)
|
597 |
zoomControl.getDialog().getPointManager().setCurrentWC(); |
598 |
else
|
599 |
zoomControl.getDialog().getPointManager().setCurrentPixelCoord(); |
600 |
} |
601 |
} |
602 |
|
603 |
/**
|
604 |
* Al sacar el rat?n de la zona de dibujado de la miniimagen restauramos los valores
|
605 |
* de los JTextField.
|
606 |
*
|
607 |
* Se actualizaran los correspondientes a las coordenadas del mundo real
|
608 |
* en el caso de que el control tenga botones a la izquierda.
|
609 |
*
|
610 |
* Se actualizaran los correspondientes a las coordenadas en pixels cuando se trata del control con
|
611 |
* botones a la derecha.
|
612 |
*/
|
613 |
public void mouseExited(MouseEvent arg0) { |
614 |
if(isEnableEvent()){
|
615 |
if(!zoomControl.rightControl)
|
616 |
zoomControl.getDialog().getPointManager().replaceWC(); |
617 |
else
|
618 |
zoomControl.getDialog().getPointManager().replacePixelCoord(); |
619 |
} |
620 |
} |
621 |
|
622 |
/**
|
623 |
* Controla la actualizaci?n del valor de un punto en los JTextDialog. Cuando se mueve sobre
|
624 |
* el panel con controles a la izquierda actualizamos las coordenadas del mapa. Cuando se mueve sobre
|
625 |
* el panel con controles a la derecha actualizamos las coordenadas de la imagen.
|
626 |
*/
|
627 |
public void mouseMoved(MouseEvent arg0) { |
628 |
if( isEnableEvent() &&
|
629 |
zoomControl.getLyrPoints() != null &&
|
630 |
zoomControl.getLyrPoints().getCountPoints() > 0){
|
631 |
double newWCPointX = this.newViewPort.getExtent().getMinX() + ((arg0.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth()); |
632 |
int ptoSelectY = (int)(this.getHeight() - arg0.getY()); |
633 |
double newWCPointY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight()); |
634 |
if(!zoomControl.rightControl){
|
635 |
zoomControl.getDialog().getPointManager().setTempWC(newWCPointX, newWCPointY); |
636 |
}else{
|
637 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
|
638 |
if(pixelImg != null) |
639 |
zoomControl.getDialog().getPointManager().setTempPixelCoord(pixelImg.getX(), pixelImg.getY()); |
640 |
else
|
641 |
//Si pixelImg es null es que nos hemos salido de la imagen por lo que reponemos los valores originales hasta que vuelva a entrar.
|
642 |
zoomControl.getDialog().getPointManager().replacePixelCoord(); |
643 |
|
644 |
} |
645 |
} |
646 |
} |
647 |
|
648 |
/**
|
649 |
* Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
|
650 |
*
|
651 |
*/
|
652 |
public void mousePressed(MouseEvent ev) { |
653 |
int cte = 10; |
654 |
if( (ev.getX() > ((getWidth() >> 1) - cte)) && (ev.getX() < ((getWidth() >> 1) + cte)) && |
655 |
(ev.getY() > ((getHeight() >> 1) - cte)) && (ev.getY() < ((getHeight() >> 1) + cte))){ |
656 |
this.dragged = true; |
657 |
this.movDragged = ptoIni = ev.getPoint();
|
658 |
try{
|
659 |
if(zoomControl.isRightControl())
|
660 |
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(redCursor, new Point(16, 16), "")); |
661 |
else
|
662 |
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(blueCursor, new Point(16, 16), "")); |
663 |
|
664 |
zoomControl.loadLayer(); |
665 |
initCrux = new Point2D.Double(); |
666 |
initCrux.setLocation(this.getWidth() / 2, this.getHeight() / 2); |
667 |
repaint(); |
668 |
}catch(InstantiationException e){ |
669 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
670 |
PluginServices.getText(this, "error_capa_puntos")); |
671 |
} |
672 |
} |
673 |
} |
674 |
|
675 |
/* (non-Javadoc)
|
676 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
677 |
*/
|
678 |
public void mouseReleased(MouseEvent ev) { |
679 |
if(!dragged)
|
680 |
return;
|
681 |
dragged = false;
|
682 |
View theView = null; |
683 |
try{
|
684 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
685 |
}catch(ClassCastException exc){ |
686 |
return;
|
687 |
} |
688 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
689 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
690 |
|
691 |
ptoFin = ev.getPoint(); |
692 |
|
693 |
/*double destX = this.newViewPort.getExtent().getMinX() + ((ev.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth());
|
694 |
int ptoSelectY = (int)(this.getHeight() - ev.getY());
|
695 |
double destY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight());
|
696 |
*/
|
697 |
Point2D point = newViewPort.toMapPoint(ev.getX(), ev.getY());
|
698 |
int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
699 |
|
700 |
FLyrPoints lp = zoomControl.getLyrPoints();//(FLyrPoints)lyr;
|
701 |
|
702 |
if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen |
703 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(point);
|
704 |
//Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
|
705 |
|
706 |
if(pixelImg == null){ |
707 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
708 |
PluginServices.getText(this, "fuera_de_extent")); |
709 |
return;
|
710 |
} |
711 |
zoomControl.getDialog().getPointManager().updateData( nPoint, |
712 |
pixelImg, |
713 |
null,
|
714 |
zoomControl.getDialog(), |
715 |
null);
|
716 |
|
717 |
//Actualizamos la otra miniimagen
|
718 |
shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg)); |
719 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
720 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
721 |
zoomControl.getDialog().getPointManager().setCurrentPixelCoord(); |
722 |
}else{ //Control de actualizaci?n de coordenadas del mundo |
723 |
Point2D mapPoint = new Point2D.Double(); |
724 |
mapPoint.setLocation(point); |
725 |
//Point2D mapPoint = new Point2D.Double();
|
726 |
//mapPoint.setLocation(newWCPointX, newWCPointY);
|
727 |
zoomControl.getDialog().getPointManager().updateData( nPoint, |
728 |
null,
|
729 |
mapPoint, |
730 |
zoomControl.getDialog(), |
731 |
null);
|
732 |
|
733 |
//Actualizamos la otra miniimagen
|
734 |
shiftExtent(mapPoint); |
735 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
736 |
zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
737 |
zoomControl.getDialog().getPointManager().setCurrentWC(); |
738 |
} |
739 |
repaint(); |
740 |
theView.getMapControl().getMapContext().invalidate(); |
741 |
} |
742 |
|
743 |
/* (non-Javadoc)
|
744 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
745 |
*/
|
746 |
public void mouseDragged(MouseEvent ev) { |
747 |
this.mouseMoved(ev);
|
748 |
} |
749 |
//**********************End Methods***************************
|
750 |
|
751 |
//**********************Setters & Getters*********************
|
752 |
/**
|
753 |
* @param cleanCanvas The cleanCanvas to set.
|
754 |
*/
|
755 |
public void setCleanCanvas(boolean cleanCanvas) { |
756 |
this.cleanCanvas = cleanCanvas;
|
757 |
} |
758 |
|
759 |
/**
|
760 |
* Asigna el punto donde se centrar? la vista de la minimagen
|
761 |
* @param pto Punto central.
|
762 |
*/
|
763 |
public void setCenterPoint(Point2D pto){ |
764 |
this.centerPoint = pto;
|
765 |
} |
766 |
|
767 |
/**
|
768 |
* Asigna el viewPort
|
769 |
* @param vp ViewPort
|
770 |
*/
|
771 |
public void setViewPort(ViewPort vp){ |
772 |
this.initViewPort(vp, this.centerPoint, null); |
773 |
} |
774 |
|
775 |
/**
|
776 |
* Asigna el viewPort recalculado
|
777 |
* @param vp ViewPort
|
778 |
*/
|
779 |
public void setNewViewPort(ViewPort vp){ |
780 |
this.newViewPort = vp;
|
781 |
} |
782 |
|
783 |
/**
|
784 |
* Obtiene el viewPort recalculado
|
785 |
* @return vp ViewPort
|
786 |
*/
|
787 |
public ViewPort getNewViewPort(){
|
788 |
return this.newViewPort; |
789 |
} |
790 |
|
791 |
/**
|
792 |
* Obtiene el valor del desactivador de eventos sobre el canvas.
|
793 |
* @return
|
794 |
*/
|
795 |
public boolean isEnableEvent() { |
796 |
return enableEvent;
|
797 |
} |
798 |
|
799 |
/**
|
800 |
* Asigna el desactivador de eventos sobre el canvas
|
801 |
* @param enableEvent
|
802 |
*/
|
803 |
public void setEnableEvent(boolean enableEvent) { |
804 |
this.enableEvent = enableEvent;
|
805 |
} |
806 |
//**********************End Setters & Getters*****************
|
807 |
|
808 |
} |
809 |
} |