svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / listeners / GeorefPointSelectorListener.java @ 5818
History | View | Annotate | Download (3.76 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.listeners; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.awt.geom.Point2D; |
23 |
|
24 |
import javax.swing.JOptionPane; |
25 |
|
26 |
import org.gvsig.georeferencing.GeoreferencingToolsModule; |
27 |
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog; |
28 |
|
29 |
import com.iver.andami.PluginServices; |
30 |
import com.iver.cit.gvsig.fmap.ViewPort; |
31 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
32 |
import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl; |
33 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
34 |
import com.iver.cit.gvsig.gui.View; |
35 |
|
36 |
|
37 |
/**
|
38 |
* <p>Extensi?n de la clase GeorefPointerListenerImpl de FMap para poder llamar a m?todos de
|
39 |
* andami o de gvSIG.</p>
|
40 |
* <p>Este listener salva puntos clickeados desde una vista sobre una capa de puntos.</p>
|
41 |
*
|
42 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
43 |
*/
|
44 |
public class GeorefPointSelectorListener extends GeorefPointerListenerImpl { |
45 |
|
46 |
//**********************Vars**********************************
|
47 |
private GeoreferencingDialog dialog = null; |
48 |
private View theView = null; |
49 |
|
50 |
/**
|
51 |
* true si se va a seleccionar el primer punto y false si se selecciona el segundo.
|
52 |
*/
|
53 |
public static boolean firstPoint = true; |
54 |
|
55 |
/**
|
56 |
* Posici?n del punto a ser seleccionado.
|
57 |
*/
|
58 |
public static int posPoint = -1; |
59 |
//**********************End Vars******************************
|
60 |
|
61 |
//**********************Methods*******************************
|
62 |
/**
|
63 |
* Constructor
|
64 |
*
|
65 |
* @param mapCtrl
|
66 |
*/
|
67 |
public GeorefPointSelectorListener(GeoreferencingDialog dialog) {
|
68 |
super();
|
69 |
this.dialog = dialog;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Captura de puntos sobre una capa FlyrPoint
|
74 |
*
|
75 |
* @param event Evento de un punto sobre la vista
|
76 |
*
|
77 |
* @throws BehaviorException
|
78 |
*/
|
79 |
public void point(PointEvent event) throws BehaviorException { |
80 |
super.point(event);
|
81 |
|
82 |
try{
|
83 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
84 |
}catch(ClassCastException exc){ |
85 |
return;
|
86 |
} |
87 |
//Obtenemos la capa de puntos y la capa de georaster
|
88 |
|
89 |
if(dialog.getLyrPoints() == null || dialog.getLyrGeoRaster() == null){ |
90 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
91 |
PluginServices.getText(this, "error_capa_puntos")); |
92 |
return;
|
93 |
} |
94 |
|
95 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
96 |
Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
|
97 |
|
98 |
if(firstPoint){
|
99 |
if(dialog.getLyrPoints() != null){ |
100 |
//Obtenemos el punto seleccionado en coordenadas de la vista
|
101 |
Point2D pixelImg = dialog.getLyrGeoRaster().world2Img(wcPoint);
|
102 |
if(pixelImg == null){ |
103 |
dialog.getPointManager().restoreControlsValue(); |
104 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
105 |
PluginServices.getText(this, "fuera_de_extent")); |
106 |
return;
|
107 |
} |
108 |
|
109 |
dialog.getPointManager().selectFirstPoint(pixelImg); |
110 |
} |
111 |
}else
|
112 |
dialog.getPointManager().selectSecondPoint(wcPoint); |
113 |
|
114 |
} |
115 |
|
116 |
//**********************End Methods*******************************
|
117 |
} |