svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / panels / ZoomControlPanel.java @ 10626
History | View | Annotate | Download (31.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.georeferencing.gui.panels; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Color; |
23 |
import java.awt.Component; |
24 |
import java.awt.Cursor; |
25 |
import java.awt.Graphics; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Image; |
30 |
import java.awt.Point; |
31 |
import java.awt.Toolkit; |
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
import java.awt.event.MouseEvent; |
35 |
import java.awt.event.MouseListener; |
36 |
import java.awt.event.MouseMotionListener; |
37 |
import java.awt.geom.Point2D; |
38 |
import java.awt.geom.Rectangle2D; |
39 |
import java.awt.image.BufferedImage; |
40 |
import java.io.IOException; |
41 |
|
42 |
import javax.swing.ImageIcon; |
43 |
import javax.swing.JButton; |
44 |
import javax.swing.JOptionPane; |
45 |
import javax.swing.JPanel; |
46 |
|
47 |
import org.cresques.px.Extent; |
48 |
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog; |
49 |
import org.gvsig.georeferencing.utils.GeoUtils; |
50 |
|
51 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.cit.gvsig.fmap.ViewPort; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
58 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
59 |
import com.iver.utiles.swing.threads.Cancellable; |
60 |
|
61 |
/**
|
62 |
* Panel que contiene los controles de zoom de la vista para
|
63 |
* afinar en la georreferenciaci?n.
|
64 |
*
|
65 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
66 |
*
|
67 |
*/
|
68 |
public class ZoomControlPanel extends JPanel implements ActionListener{ |
69 |
|
70 |
//**********************Vars**********************************
|
71 |
public static final int WIDTH_MINIMG = 140; |
72 |
public static final int HEIGHT_MINIMG = 140; |
73 |
private JPanel pImage = null; |
74 |
private JPanel pControls = null; |
75 |
private JButton bZoomMas = null; |
76 |
private JButton bZoomMenos = null; |
77 |
private CanvasZone canvas = null; |
78 |
private ViewPort viewPort = null; |
79 |
public FLyrPoints lyrPoints = null; |
80 |
public FLyrGeoRaster lyrGeoRaster = null; |
81 |
public GeoreferencingDialog dialog = null; |
82 |
private boolean rightControl = false; |
83 |
/**
|
84 |
* Estado de los botones cuando se ejecuta disableAllControls
|
85 |
*/
|
86 |
private boolean[] buttonsState = new boolean[2]; |
87 |
/**
|
88 |
* DisableAllControls ha sido ejecutada si est? a true esta variabled
|
89 |
*/
|
90 |
private boolean disableAllControls = false; |
91 |
/**
|
92 |
* Factor multiplicador cuando hacemos zoom mas
|
93 |
*/
|
94 |
private double zoomMas = 0.6; |
95 |
/**
|
96 |
* Factor multiplicador cuando hacemos zoom menos
|
97 |
*/
|
98 |
private double zoomMenos = 1.8; |
99 |
//**********************End Vars******************************
|
100 |
|
101 |
//**********************Methods*******************************
|
102 |
/**
|
103 |
* This is the default constructor
|
104 |
*/
|
105 |
public ZoomControlPanel(boolean rightControl, GeoreferencingDialog dialog) { |
106 |
super();
|
107 |
this.rightControl = rightControl;
|
108 |
this.dialog = dialog;
|
109 |
initialize(rightControl); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* This method initializes this
|
114 |
*
|
115 |
* @return void
|
116 |
*/
|
117 |
private void initialize(boolean rightControl) { |
118 |
|
119 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
120 |
if(rightControl)
|
121 |
gridBagConstraints1.gridx = 1;
|
122 |
else
|
123 |
gridBagConstraints1.gridx = 0;
|
124 |
gridBagConstraints1.gridy = 0;
|
125 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
126 |
if(rightControl)
|
127 |
gridBagConstraints.gridx = 0;
|
128 |
else
|
129 |
gridBagConstraints.gridx = 1;
|
130 |
gridBagConstraints.gridy = 0;
|
131 |
this.setLayout(new GridBagLayout()); |
132 |
this.setPreferredSize(new java.awt.Dimension(175,142)); |
133 |
this.setSize(new java.awt.Dimension(175,142)); |
134 |
this.setLocation(new java.awt.Point(0,0)); |
135 |
this.add(getPImage(), gridBagConstraints);
|
136 |
this.add(getPControls(), gridBagConstraints1);
|
137 |
//Desactivamos el control en la inicializaci?n
|
138 |
this.setEnabled(false); |
139 |
} |
140 |
|
141 |
/**
|
142 |
* Carga las capas de puntos y de raster georreferenciado
|
143 |
*
|
144 |
*/
|
145 |
public void loadLayer() throws InstantiationException{ |
146 |
//Cargamos las capas
|
147 |
this.lyrGeoRaster = dialog.getLyrGeoRaster();
|
148 |
this.lyrPoints = dialog.getLyrPoints();
|
149 |
|
150 |
if(lyrGeoRaster == null || lyrPoints == null) |
151 |
throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada"); |
152 |
|
153 |
} |
154 |
|
155 |
/**
|
156 |
*Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
|
157 |
*/
|
158 |
public void draw(){ |
159 |
if(!getDialog().isEnlarge())
|
160 |
getCanvas().loadBuffer(); |
161 |
canvas.draw = true;
|
162 |
getCanvas().repaint(); |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Manejo de los controles zoom m?s y zoom menos
|
167 |
*/
|
168 |
public void actionPerformed(ActionEvent e) { |
169 |
double zoom = zoomMas;
|
170 |
|
171 |
if(e.getSource() == bZoomMas)
|
172 |
canvas.calcZoom(zoomMas); |
173 |
|
174 |
if(e.getSource() == bZoomMenos){
|
175 |
canvas.calcZoom(zoomMenos); |
176 |
zoom = zoomMenos; |
177 |
} |
178 |
|
179 |
canvas.draw = true;
|
180 |
canvas.repaint(); |
181 |
if(isRightControl())
|
182 |
lyrPoints.getPoint(dialog.getSelectedPoint()).zoomLeft *= zoom; |
183 |
else
|
184 |
lyrPoints.getPoint(dialog.getSelectedPoint()).zoomRight *= zoom; |
185 |
|
186 |
} |
187 |
|
188 |
/**
|
189 |
*Limpia el canvas
|
190 |
*/
|
191 |
public void clear(){ |
192 |
canvas.setCleanCanvas(true);
|
193 |
canvas.repaint(); |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Esta funci?n deshabilita todos los controles y guarda sus valores
|
198 |
* de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
|
199 |
* se vuelvan a quedar como estaba
|
200 |
*/
|
201 |
public void disableAllControls(){ |
202 |
if(!disableAllControls){
|
203 |
disableAllControls = true;
|
204 |
|
205 |
//Salvamos los estados
|
206 |
buttonsState[0] = getBZoomMas().isEnabled();
|
207 |
buttonsState[1] = getBZoomMenos().isEnabled();
|
208 |
|
209 |
//Desactivamos controles
|
210 |
getBZoomMas().setEnabled(false);
|
211 |
getBZoomMenos().setEnabled(false);
|
212 |
} |
213 |
} |
214 |
|
215 |
/**
|
216 |
* Esta funci?n deja los controles como estaban al ejecutar la funci?n
|
217 |
* disableAllControls
|
218 |
*/
|
219 |
public void restoreControlsValue(){ |
220 |
if(disableAllControls){
|
221 |
disableAllControls = false;
|
222 |
getBZoomMas().setEnabled(buttonsState[0]);
|
223 |
getBZoomMenos().setEnabled(buttonsState[1]);
|
224 |
} |
225 |
} |
226 |
//**********************End Methods***************************
|
227 |
|
228 |
//**********************Setters & Getters*********************
|
229 |
/**
|
230 |
* @param viewPort The viewPort to set.
|
231 |
*/
|
232 |
public void setViewPort(ViewPort viewPort, double zoom) { |
233 |
this.viewPort = viewPort;
|
234 |
getCanvas().setViewPort(this.viewPort, zoom);
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* This method initializes jPanel
|
239 |
*
|
240 |
* @return javax.swing.JPanel
|
241 |
*/
|
242 |
private JPanel getPImage() { |
243 |
if (pImage == null) { |
244 |
pImage = new JPanel(); |
245 |
BorderLayout borderLayout = new BorderLayout(); |
246 |
pImage.setLayout(borderLayout); |
247 |
pImage.setPreferredSize(new java.awt.Dimension(140,140)); |
248 |
pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
249 |
pImage.add(getCanvas(), BorderLayout.CENTER);
|
250 |
} |
251 |
return pImage;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* This method initilizes canvas
|
256 |
* @return CanvasZone
|
257 |
*/
|
258 |
public CanvasZone getCanvas(){
|
259 |
if(canvas == null){ |
260 |
canvas = new CanvasZone(ZoomControlPanel.WIDTH_MINIMG, ZoomControlPanel.HEIGHT_MINIMG, this); |
261 |
canvas.setVisible(false);
|
262 |
canvas.addMouseListener(canvas); |
263 |
canvas.addMouseMotionListener(canvas); |
264 |
} |
265 |
return canvas;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* This method initializes jPanel1
|
270 |
*
|
271 |
* @return javax.swing.JPanel
|
272 |
*/
|
273 |
private JPanel getPControls() { |
274 |
if (pControls == null) { |
275 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
276 |
gridBagConstraints3.gridx = 0;
|
277 |
gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0); |
278 |
gridBagConstraints3.gridy = 1;
|
279 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
280 |
gridBagConstraints2.gridx = 0;
|
281 |
gridBagConstraints2.gridy = 0;
|
282 |
pControls = new JPanel(); |
283 |
pControls.setLayout(new GridBagLayout()); |
284 |
pControls.setPreferredSize(new java.awt.Dimension(33,140)); |
285 |
pControls.add(getBZoomMas(), gridBagConstraints2); |
286 |
pControls.add(getBZoomMenos(), gridBagConstraints3); |
287 |
} |
288 |
return pControls;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* This method initializes jButton
|
293 |
*
|
294 |
* @return javax.swing.JButton
|
295 |
*/
|
296 |
public JButton getBZoomMas() { |
297 |
if (bZoomMas == null) { |
298 |
bZoomMas = new JButton(); |
299 |
bZoomMas.setPreferredSize(new java.awt.Dimension(25,25)); |
300 |
try{
|
301 |
bZoomMas.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/aumentar.png"))); |
302 |
}catch(NullPointerException e){ |
303 |
//Sin icono
|
304 |
} |
305 |
bZoomMas.addActionListener(this);
|
306 |
} |
307 |
return bZoomMas;
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* This method initializes jButton
|
312 |
*
|
313 |
* @return javax.swing.JButton
|
314 |
*/
|
315 |
public JButton getBZoomMenos() { |
316 |
if (bZoomMenos == null) { |
317 |
bZoomMenos = new JButton(); |
318 |
bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25)); |
319 |
try{
|
320 |
bZoomMenos.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/disminuir.png"))); |
321 |
}catch(NullPointerException e){ |
322 |
//Sin icono
|
323 |
} |
324 |
bZoomMenos.addActionListener(this);
|
325 |
} |
326 |
return bZoomMenos;
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* Obtiene true si se trata de un control con los botones de zoom
|
331 |
* a la derecha y false si los tiene a la izquierda.
|
332 |
* @return Returns the rightControl.
|
333 |
*/
|
334 |
public boolean isRightControl() { |
335 |
return rightControl;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* Obtiene la capa de imagen georreferenciada.
|
340 |
* @return Returns the lyrGeoRaster.
|
341 |
*/
|
342 |
public FLyrGeoRaster getLyrGeoRaster() {
|
343 |
return lyrGeoRaster;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* Obtiene la capa de puntos.
|
348 |
* @return Returns the lyrPoints.
|
349 |
*/
|
350 |
public FLyrPoints getLyrPoints() {
|
351 |
try{
|
352 |
if(lyrPoints == null) |
353 |
this.loadLayer();
|
354 |
}catch(InstantiationException e){ |
355 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
356 |
PluginServices.getText(this, "error_capa_puntos")); |
357 |
} |
358 |
return lyrPoints;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* @return Returns the dialog.
|
363 |
*/
|
364 |
public GeoreferencingDialog getDialog() {
|
365 |
try{
|
366 |
if(dialog == null) |
367 |
this.loadLayer();
|
368 |
}catch(InstantiationException e){ |
369 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
370 |
PluginServices.getText(this, "error_capa_puntos")); |
371 |
} |
372 |
return dialog;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* Asigna el viewPort recalculado
|
377 |
* @param vp ViewPort
|
378 |
*/
|
379 |
public void setNewViewPort(ViewPort vp){ |
380 |
canvas.setNewViewPort(vp); |
381 |
} |
382 |
|
383 |
/**
|
384 |
* Obtiene el viewPort recalculado
|
385 |
* @return vp ViewPort
|
386 |
*/
|
387 |
public ViewPort getNewViewPort(){
|
388 |
return canvas.getNewViewPort();
|
389 |
} |
390 |
|
391 |
/**
|
392 |
* Asigna al canvas la propiedad de visibilidad a verdadero o falso.
|
393 |
* @param visible true para mostrar el canvas y false para ocultarlo
|
394 |
*/
|
395 |
public void setVisible(boolean visible){ |
396 |
canvas.setVisible(visible); |
397 |
canvas.draw = true;
|
398 |
canvas.repaint(); |
399 |
} |
400 |
|
401 |
/**
|
402 |
* Asigna el punto sobre el que se centrar? el zoom de la minimagen
|
403 |
* @param pto
|
404 |
*/
|
405 |
public void setCenterPoint(Point2D pto){ |
406 |
getCanvas().setCenterPoint(pto); |
407 |
} |
408 |
|
409 |
/**
|
410 |
* Recupera el n?mero de punto que se est? tratando
|
411 |
* @param n
|
412 |
*/
|
413 |
public int getNumberPoint(){ |
414 |
try{
|
415 |
if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0) |
416 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
417 |
else
|
418 |
return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1; |
419 |
}catch(NullPointerException exc){ |
420 |
return -1; |
421 |
} |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Activa o desactiva este panel y todos los que lo componen
|
426 |
* @param enabled variable booleana para la activaci?n y/o desactivaci?n
|
427 |
*/
|
428 |
public void setEnabled(boolean enabled){ |
429 |
this.getBZoomMas().setEnabled(enabled);
|
430 |
this.getBZoomMenos().setEnabled(enabled);
|
431 |
this.getCanvas().setEnableEvent(enabled);
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* Obtiene el modificador de escala aplicado a zoom m?s
|
436 |
* @return
|
437 |
*/
|
438 |
public double getZoomMas() { |
439 |
return zoomMas;
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* Obtiene el modificador de escala aplicado a zoom m?s
|
444 |
* @return
|
445 |
*/
|
446 |
public double getZoomMenos() { |
447 |
return zoomMenos;
|
448 |
} |
449 |
|
450 |
//**********************End Setters & Getters*****************
|
451 |
/**
|
452 |
* Control que representa la zona de dibujado de la ventana. Este se encarga de
|
453 |
* repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
|
454 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
455 |
*/
|
456 |
public class CanvasZone extends JPanel implements MouseListener, MouseMotionListener{ |
457 |
|
458 |
//**********************Params********************************
|
459 |
/**
|
460 |
* Zoom inicial de la miniimagen
|
461 |
*/
|
462 |
private int initZoom = 20; |
463 |
//**********************End Params****************************
|
464 |
|
465 |
//**********************Vars**********************************
|
466 |
private ZoomControlPanel zoomControl = null; |
467 |
private int ancho; |
468 |
private int alto; |
469 |
private FLayers flayers = null; |
470 |
private ViewPort newViewPort = null; |
471 |
private Point2D centerPoint = null; |
472 |
private Image dobleBuffer = null; |
473 |
private BufferedImage imgTmp = null; |
474 |
private Graphics dbGraphics = null; |
475 |
|
476 |
/**
|
477 |
* Variable que estar? a true cuando queremos limpiar el canvas y a false cuando queremos
|
478 |
* dibujar las capas.
|
479 |
*/
|
480 |
private boolean cleanCanvas = false; |
481 |
/**
|
482 |
* Cuando el control est? desactivado necesitamos controlar con esta variable que
|
483 |
* aunque se pinche sobre el canvas no se capture el evento
|
484 |
*/
|
485 |
private boolean enableEvent = true; |
486 |
|
487 |
private Point2D initCrux = null; |
488 |
/**
|
489 |
* Variable que esta a true si estamos arrastrando la cruz por el canvas.
|
490 |
*/
|
491 |
private boolean dragged = false; |
492 |
private Image redCursor = null; |
493 |
|
494 |
private Image blueCursor = null; |
495 |
/**
|
496 |
* Esta variable se usa para informar cuando debe recargarse el buffer de las miniimagenes. Si siempre
|
497 |
* est? a true no para de llamar al draw de FLyers para que pinte sobre el minicanvas.
|
498 |
*/
|
499 |
public boolean draw = true; |
500 |
/**
|
501 |
* Esta variable estar? a false si no queremos que no se pinte la capa de puntos rojos sobre
|
502 |
* la miniimagenes
|
503 |
*/
|
504 |
private boolean drawRedCrux = true; |
505 |
/**
|
506 |
* Esta variable estar? a false si no queremos que no se pinte la capa de puntos azules sobre
|
507 |
* la miniimagenes
|
508 |
*/
|
509 |
private boolean drawBlueCrux = true; |
510 |
|
511 |
//**********************End Vars******************************
|
512 |
|
513 |
//**********************Classes*******************************
|
514 |
class CancellableClass implements Cancellable{ |
515 |
private boolean cancel = false; |
516 |
public void setCanceled(boolean canceled) { |
517 |
this.cancel = canceled;
|
518 |
} |
519 |
|
520 |
public boolean isCanceled() { |
521 |
return this.cancel; |
522 |
} |
523 |
} |
524 |
//**********************End Classes***************************
|
525 |
|
526 |
//**********************Methods*******************************
|
527 |
/**
|
528 |
*
|
529 |
*/
|
530 |
public CanvasZone( int anc,int alt, ZoomControlPanel zc) { |
531 |
zoomControl = zc; |
532 |
ancho = anc; |
533 |
alto = alt; |
534 |
|
535 |
if(redCursor == null){ |
536 |
try{
|
537 |
redCursor = new ImageIcon(getClass().getClassLoader().getResource("images/icoRed.png")).getImage(); |
538 |
}catch(NullPointerException e){ |
539 |
//Sin icono
|
540 |
} |
541 |
} |
542 |
|
543 |
if(blueCursor == null){ |
544 |
try{
|
545 |
blueCursor = new ImageIcon(getClass().getClassLoader().getResource("images/icoBlue.png")).getImage(); |
546 |
}catch(NullPointerException e){ |
547 |
//Sin icono
|
548 |
} |
549 |
} |
550 |
|
551 |
this.setSize(ancho, alto);
|
552 |
this.setBackground(Color.WHITE); |
553 |
|
554 |
imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
555 |
dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB); |
556 |
dbGraphics = dobleBuffer.getGraphics(); |
557 |
} |
558 |
|
559 |
/**
|
560 |
* Calcula el zoom dependiendo del factor de escala pasado por
|
561 |
* par?metro.
|
562 |
*/
|
563 |
public void calcZoom(double factor){ |
564 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
565 |
double nuevoX = centerPoint.getX() -
|
566 |
((newViewPort.getExtent().getWidth() * factor) / 2.0);
|
567 |
double nuevoY = centerPoint.getY() -
|
568 |
((newViewPort.getExtent().getHeight() * factor) / 2.0);
|
569 |
r.x = nuevoX; |
570 |
r.y = nuevoY; |
571 |
r.width = newViewPort.getExtent().getWidth() * factor; |
572 |
r.height = newViewPort.getExtent().getHeight() * factor; |
573 |
newViewPort.setExtent(r); |
574 |
newViewPort.refreshExtent(); |
575 |
} |
576 |
|
577 |
/**
|
578 |
* Calculamos el viewPort para el zoom de la minimagen
|
579 |
* @param vp ViewPort inicial
|
580 |
* @param center Centro del ViewPort a calcular.
|
581 |
* @param vpDest ViewPort de destino. Si este es null se crear? un nuevo ViewPort sino se asignar?n los cambios a este.
|
582 |
* @return
|
583 |
*/
|
584 |
public ViewPort initViewPort(ViewPort vp, Point2D center, ViewPort vpDest, double zoom){ |
585 |
if(center != null){ |
586 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
587 |
double relacionPixelWcWidth = ((vp.getExtent().getMaxX() - vp.getExtent().getMinX()) / initZoom) / ancho;
|
588 |
double relacionPixelWcHeight = ((vp.getExtent().getMaxY() - vp.getExtent().getMinY()) / initZoom) / alto;
|
589 |
|
590 |
double wcOriginX = center.getX() - ((vp.getImageWidth() * relacionPixelWcWidth) / 2); |
591 |
double wcOriginY = center.getY() - ((vp.getImageHeight() * relacionPixelWcHeight) / 2); |
592 |
|
593 |
double wcDstMinX = wcOriginX;
|
594 |
double wcDstMinY = wcOriginY;
|
595 |
double wcDstMaxX = wcDstMinX + (vp.getImageWidth()*relacionPixelWcWidth);
|
596 |
double wcDstMaxY = wcDstMinY + (vp.getImageHeight()*relacionPixelWcHeight);
|
597 |
|
598 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
599 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
600 |
|
601 |
Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
602 |
|
603 |
if(vpDest == null){ |
604 |
newViewPort = vp.cloneViewPort(); |
605 |
newViewPort.setExtent(ext); |
606 |
newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));
|
607 |
newViewPort.refreshExtent(); |
608 |
if(zoom != 1 && zoom != 0) |
609 |
newViewPort = GeoUtils.calcZoom(newViewPort, zoom); |
610 |
return newViewPort;
|
611 |
}else{
|
612 |
vpDest.setExtent(ext); |
613 |
vpDest.refreshExtent(); |
614 |
if(zoom != 1 && zoom != 0) |
615 |
vpDest = GeoUtils.calcZoom(vpDest, zoom); |
616 |
return vpDest;
|
617 |
} |
618 |
|
619 |
} |
620 |
return null; |
621 |
} |
622 |
|
623 |
/**
|
624 |
* Dibuja sobre el graphics de la mini imagen la imagen
|
625 |
* definida en el newViewPort.
|
626 |
*/
|
627 |
public void loadBuffer() { |
628 |
Graphics2D gTmp = (Graphics2D) imgTmp.getGraphics(); |
629 |
|
630 |
dbGraphics.setColor(Color.WHITE);
|
631 |
dbGraphics.fillRect(0, 0, ancho, alto); |
632 |
gTmp.setColor(Color.WHITE);
|
633 |
gTmp.fillRect(0, 0, ancho, alto); |
634 |
try {
|
635 |
if (newViewPort != null) { |
636 |
// Si no tenemos las capas las cargamos
|
637 |
if (flayers == null) { |
638 |
View theView = null; |
639 |
try {
|
640 |
theView = (View) PluginServices.getMDIManager()
|
641 |
.getActiveWindow(); |
642 |
} catch (ClassCastException exc) { |
643 |
return;
|
644 |
} |
645 |
flayers = theView.getMapControl().getMapContext() |
646 |
.getLayers(); |
647 |
} |
648 |
|
649 |
/*
|
650 |
* Dibujamos sobre las miniimagenes Forzamos un draw de las
|
651 |
* capas para dibujar la vista sobre el control de las
|
652 |
* miniimagenes. Como la capa gr?fica est? en FMap esta no
|
653 |
* aparece en el dibujado de FLayers por los que forzaremos
|
654 |
* el pintado tambi?n de la capa de puntos sobre nuestro
|
655 |
* control
|
656 |
*/
|
657 |
|
658 |
Cancellable cancellable = new CancellableClass();
|
659 |
|
660 |
if (zoomControl.getDialog().isEnlarge()) {
|
661 |
if (zoomControl.getNumberPoint() != -1) { |
662 |
draw(new BufferedImage(newViewPort.getImageWidth(), |
663 |
newViewPort.getImageHeight(), |
664 |
BufferedImage.TYPE_INT_ARGB),
|
665 |
(Graphics2D) dbGraphics, newViewPort,
|
666 |
cancellable, flayers.getMapContext() |
667 |
.getScaleView()); |
668 |
if (zoomControl.isRightControl()) {
|
669 |
if (drawRedCrux)
|
670 |
zoomControl.getLyrPoints().drawPixelCrux( |
671 |
(Graphics2D) dbGraphics,
|
672 |
newViewPort, cancellable); |
673 |
} else {
|
674 |
if (drawBlueCrux)
|
675 |
zoomControl.getLyrPoints().drawMapCrux( |
676 |
(Graphics2D) dbGraphics,
|
677 |
newViewPort, cancellable); |
678 |
} |
679 |
|
680 |
} |
681 |
} |
682 |
|
683 |
draw(new BufferedImage(newViewPort.getImageWidth(), |
684 |
newViewPort.getImageHeight(), |
685 |
BufferedImage.TYPE_INT_ARGB), gTmp, newViewPort,
|
686 |
cancellable, flayers.getMapContext().getScaleView()); |
687 |
if (zoomControl.isRightControl()) {
|
688 |
if (drawRedCrux)
|
689 |
zoomControl.getLyrPoints().drawPixelCrux(gTmp, |
690 |
newViewPort, cancellable); |
691 |
} else {
|
692 |
if (drawBlueCrux)
|
693 |
zoomControl.getLyrPoints().drawMapCrux(gTmp, |
694 |
newViewPort, cancellable); |
695 |
} |
696 |
} |
697 |
} catch (ReadDriverException e) {
|
698 |
e.printStackTrace(); |
699 |
} |
700 |
} |
701 |
|
702 |
/**
|
703 |
* Esta funci?n es una copia de la de Flyers modificada para para
|
704 |
* dibujar sobre las miniimagenes. En la miniimagen con los controles a
|
705 |
* la derecha solo dibujar? el raster a georreferenciar. En la
|
706 |
* miniimagen con los controles a la izquierda dibujar? la cartograf?a
|
707 |
* de base.
|
708 |
*
|
709 |
* @param image
|
710 |
* @param g
|
711 |
* @param viewPort
|
712 |
* @param cancel
|
713 |
* @param scale
|
714 |
* @throws ReadDriverException
|
715 |
* @throws DriverException
|
716 |
*/
|
717 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
718 |
Cancellable cancel,double scale) throws ReadDriverException { |
719 |
for(int i=0;i<flayers.getLayersCount();i++){ |
720 |
if (cancel.isCanceled())
|
721 |
break;
|
722 |
FLayer lyr = flayers.getLayer(i); |
723 |
if(zoomControl.isRightControl()){
|
724 |
if(lyr instanceof FLyrGeoRaster) |
725 |
lyr.draw(image, g, viewPort, cancel,scale); |
726 |
}else{
|
727 |
if (lyr.isVisible()){
|
728 |
if(!(lyr instanceof FLyrGeoRaster)) |
729 |
lyr.draw(image, g, viewPort, cancel,scale); |
730 |
} |
731 |
} |
732 |
|
733 |
} |
734 |
} |
735 |
|
736 |
/**
|
737 |
*
|
738 |
*/
|
739 |
public void update(Graphics g){ |
740 |
draw = true;
|
741 |
this.paint(g);
|
742 |
} |
743 |
|
744 |
/**
|
745 |
* Dibuja sobre el Graphics2D pasado el viewPort solicitado a
|
746 |
* la lista de capas.
|
747 |
* @param g
|
748 |
*/
|
749 |
public void paint( Graphics g ) { |
750 |
if(!cleanCanvas){
|
751 |
if(draw){
|
752 |
loadBuffer(); |
753 |
draw = false;
|
754 |
} |
755 |
g.drawImage(dobleBuffer, 0, 0, null); |
756 |
this.invalidate();
|
757 |
AdjustGeorefPanel p = zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel(); |
758 |
try{
|
759 |
if(!this.zoomControl.isRightControl()) |
760 |
p.setLZoomLeft("1:"+((int)newViewPort.getScale())); |
761 |
else
|
762 |
p.setLZoomRight("1:"+((int)newViewPort.getScale())); |
763 |
}catch(NullPointerException exc){ |
764 |
//No ponemos la escala
|
765 |
} |
766 |
}else{
|
767 |
dbGraphics.setColor( Color.WHITE );
|
768 |
dbGraphics.fillRect( 0,0,ancho,alto ); |
769 |
g.setColor( Color.WHITE );
|
770 |
g.fillRect( 0,0,ancho,alto ); |
771 |
cleanCanvas = false;
|
772 |
} |
773 |
} |
774 |
|
775 |
/* (non-Javadoc)
|
776 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
777 |
*/
|
778 |
public void mouseClicked(MouseEvent ev) { |
779 |
|
780 |
} |
781 |
|
782 |
/**
|
783 |
* Cuando el rat?n entra dentro del control fijamos el valor de las coordenadas
|
784 |
* que tiene el punto seleccionado. De esta forma cuando salga del control podr?
|
785 |
* volver a restaurarlo en caso de que no haya sido cambiado.
|
786 |
*/
|
787 |
public void mouseEntered(MouseEvent arg0) { |
788 |
if(isEnableEvent()){
|
789 |
if(!zoomControl.rightControl)
|
790 |
zoomControl.getDialog().getPointManager().setCurrentWC(); |
791 |
else
|
792 |
zoomControl.getDialog().getPointManager().setCurrentPixelCoord(); |
793 |
} |
794 |
} |
795 |
|
796 |
/**
|
797 |
* Al sacar el rat?n de la zona de dibujado de la miniimagen restauramos los valores
|
798 |
* de los JTextField.
|
799 |
*
|
800 |
* Se actualizaran los correspondientes a las coordenadas del mundo real
|
801 |
* en el caso de que el control tenga botones a la izquierda.
|
802 |
*
|
803 |
* Se actualizaran los correspondientes a las coordenadas en pixels cuando se trata del control con
|
804 |
* botones a la derecha.
|
805 |
*/
|
806 |
public void mouseExited(MouseEvent arg0) { |
807 |
if(isEnableEvent()){
|
808 |
if(!zoomControl.rightControl)
|
809 |
zoomControl.getDialog().getPointManager().replaceWC(); |
810 |
else
|
811 |
zoomControl.getDialog().getPointManager().replacePixelCoord(); |
812 |
drawRedCrux = drawBlueCrux = true;
|
813 |
repaint(); |
814 |
} |
815 |
} |
816 |
|
817 |
/**
|
818 |
* Controla la actualizaci?n del valor de un punto en los JTextDialog. Cuando se mueve sobre
|
819 |
* el panel con controles a la izquierda actualizamos las coordenadas del mapa. Cuando se mueve sobre
|
820 |
* el panel con controles a la derecha actualizamos las coordenadas de la imagen.
|
821 |
*/
|
822 |
public void mouseMoved(MouseEvent arg0) { |
823 |
if( isEnableEvent() &&
|
824 |
zoomControl.getLyrPoints() != null &&
|
825 |
zoomControl.getLyrPoints().getCountPoints() > 0 &&
|
826 |
this.newViewPort != null && |
827 |
this.newViewPort.getExtent() != null){ |
828 |
|
829 |
double newWCPointX = this.newViewPort.getExtent().getMinX() + ((arg0.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth()); |
830 |
int ptoSelectY = (int)(this.getHeight() - arg0.getY()); |
831 |
double newWCPointY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight()); |
832 |
if(!zoomControl.rightControl){
|
833 |
zoomControl.getDialog().getPointManager().setTempWC(newWCPointX, newWCPointY); |
834 |
}else{
|
835 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
|
836 |
if(pixelImg != null) |
837 |
zoomControl.getDialog().getPointManager().setTempPixelCoord(pixelImg.getX(), pixelImg.getY()); |
838 |
else
|
839 |
//Si pixelImg es null es que nos hemos salido de la imagen por lo que reponemos los valores originales hasta que vuelva a entrar.
|
840 |
zoomControl.getDialog().getPointManager().replacePixelCoord(); |
841 |
|
842 |
} |
843 |
} |
844 |
} |
845 |
|
846 |
/**
|
847 |
* Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
|
848 |
*
|
849 |
*/
|
850 |
public void mousePressed(MouseEvent ev) { |
851 |
int cte = 10; |
852 |
if( (ev.getX() > ((getWidth() >> 1) - cte)) && (ev.getX() < ((getWidth() >> 1) + cte)) && |
853 |
(ev.getY() > ((getHeight() >> 1) - cte)) && (ev.getY() < ((getHeight() >> 1) + cte))){ |
854 |
this.dragged = true; |
855 |
|
856 |
try{
|
857 |
if(zoomControl.isRightControl()){
|
858 |
drawRedCrux = false;
|
859 |
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(redCursor, new Point(16, 16), "")); |
860 |
}else{
|
861 |
drawBlueCrux = false;
|
862 |
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(blueCursor, new Point(16, 16), "")); |
863 |
} |
864 |
|
865 |
zoomControl.loadLayer(); |
866 |
initCrux = new Point2D.Double(); |
867 |
initCrux.setLocation(this.getWidth() / 2, this.getHeight() / 2); |
868 |
draw = true;
|
869 |
repaint(); |
870 |
}catch(InstantiationException e){ |
871 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
872 |
PluginServices.getText(this, "error_capa_puntos")); |
873 |
} |
874 |
} |
875 |
} |
876 |
|
877 |
/* (non-Javadoc)
|
878 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
879 |
*/
|
880 |
public void mouseReleased(MouseEvent ev) { |
881 |
if(!dragged)
|
882 |
return;
|
883 |
dragged = false;
|
884 |
View theView = null; |
885 |
try{
|
886 |
theView = (View) PluginServices.getMDIManager().getActiveWindow();
|
887 |
}catch(ClassCastException exc){ |
888 |
return;
|
889 |
} |
890 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
891 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
892 |
|
893 |
Point2D point = newViewPort.toMapPoint(ev.getX(), ev.getY());
|
894 |
int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
895 |
|
896 |
FLyrPoints lp = zoomControl.getLyrPoints();//(FLyrPoints)lyr;
|
897 |
|
898 |
if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen |
899 |
Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(point);
|
900 |
//Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
|
901 |
|
902 |
if(pixelImg == null){ |
903 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
904 |
PluginServices.getText(this, "fuera_de_extent")); |
905 |
return;
|
906 |
} |
907 |
|
908 |
zoomControl.getDialog().getPointManager().updateData( nPoint, pixelImg, null,
|
909 |
zoomControl.getDialog(), null);
|
910 |
setCenterPoint(point); |
911 |
newViewPort = GeoUtils.shiftExtent(lyrPoints.getCenterPoint(dialog.getSelectedPoint(), false), point, lyrPoints.getMiniExtent(dialog.getSelectedPoint(), false)); |
912 |
lyrPoints.setMiniExtent(nPoint - 1, point, newViewPort, false); |
913 |
calcZoom(lyrPoints.getZoomLeft(dialog.getSelectedPoint())); |
914 |
zoomControl.getDialog().getPointManager().setCurrentPixelCoord(); |
915 |
}else{ //Control de actualizaci?n de coordenadas del mundo |
916 |
zoomControl.getDialog().getPointManager().updateData( nPoint, null, point,
|
917 |
zoomControl.getDialog(), null);
|
918 |
setCenterPoint(point); |
919 |
newViewPort = GeoUtils.shiftExtent(lyrPoints.getCenterPoint(dialog.getSelectedPoint(), true), point, lyrPoints.getMiniExtent(dialog.getSelectedPoint(), true)); |
920 |
lyrPoints.setMiniExtent(nPoint - 1, point, newViewPort, true); |
921 |
calcZoom(lyrPoints.getZoomRight(dialog.getSelectedPoint())); |
922 |
zoomControl.getDialog().getPointManager().setCurrentWC(); |
923 |
} |
924 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
925 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
926 |
|
927 |
draw = true;
|
928 |
drawRedCrux = drawBlueCrux = true;
|
929 |
repaint(); |
930 |
theView.getMapControl().getMapContext().invalidate(); |
931 |
} |
932 |
|
933 |
/* (non-Javadoc)
|
934 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
935 |
*/
|
936 |
public void mouseDragged(MouseEvent ev) { |
937 |
this.mouseMoved(ev);
|
938 |
} |
939 |
//**********************End Methods***************************
|
940 |
|
941 |
//**********************Setters & Getters*********************
|
942 |
/**
|
943 |
* @param cleanCanvas The cleanCanvas to set.
|
944 |
*/
|
945 |
public void setCleanCanvas(boolean cleanCanvas) { |
946 |
this.cleanCanvas = cleanCanvas;
|
947 |
} |
948 |
|
949 |
/**
|
950 |
* Asigna el punto donde se centrar? la vista de la minimagen
|
951 |
* @param pto Punto central.
|
952 |
*/
|
953 |
public void setCenterPoint(Point2D pto){ |
954 |
this.centerPoint = pto;
|
955 |
} |
956 |
|
957 |
/**
|
958 |
* Asigna el viewPort
|
959 |
* @param vp ViewPort
|
960 |
*/
|
961 |
public void setViewPort(ViewPort vp, double zoom){ |
962 |
this.initViewPort(vp, this.centerPoint, null, zoom); |
963 |
} |
964 |
|
965 |
/**
|
966 |
* Asigna el viewPort recalculado
|
967 |
* @param vp ViewPort
|
968 |
*/
|
969 |
public void setNewViewPort(ViewPort vp){ |
970 |
this.newViewPort = vp;
|
971 |
} |
972 |
|
973 |
/**
|
974 |
* Obtiene el viewPort recalculado
|
975 |
* @return vp ViewPort
|
976 |
*/
|
977 |
public ViewPort getNewViewPort(){
|
978 |
return this.newViewPort; |
979 |
} |
980 |
|
981 |
/**
|
982 |
* Obtiene el valor del desactivador de eventos sobre el canvas.
|
983 |
* @return
|
984 |
*/
|
985 |
public boolean isEnableEvent() { |
986 |
return enableEvent;
|
987 |
} |
988 |
|
989 |
/**
|
990 |
* Asigna el desactivador de eventos sobre el canvas
|
991 |
* @param enableEvent
|
992 |
*/
|
993 |
public void setEnableEvent(boolean enableEvent) { |
994 |
this.enableEvent = enableEvent;
|
995 |
} |
996 |
|
997 |
//**********************End Setters & Getters*****************
|
998 |
|
999 |
} |
1000 |
} |