root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / listeners / GeorefMovePointListener.java @ 5217
History | View | Annotate | Download (5.51 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.georeferencing.gui.listeners; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.geom.Point2D; |
45 |
|
46 |
import javax.swing.JOptionPane; |
47 |
|
48 |
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog; |
49 |
import org.gvsig.georeferencing.layers.FLyrGeoRaster; |
50 |
import org.gvsig.georeferencing.layers.FLyrPoints; |
51 |
import org.gvsig.georeferencing.tools.GeorefDraggListenerImpl; |
52 |
|
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
57 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
58 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
59 |
import com.iver.cit.gvsig.gui.View; |
60 |
|
61 |
|
62 |
/**
|
63 |
* <p>Extensi?n de la clase GeorefPointerListenerImpl de FMap para poder llamar a m?todos de
|
64 |
* andami o de gvSIG.</p>
|
65 |
* <p>Este listener mueve puntos desde una vista correspondientes a la capa de puntos.</p>
|
66 |
*
|
67 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
68 |
*/
|
69 |
public class GeorefMovePointListener extends GeorefDraggListenerImpl { |
70 |
|
71 |
private GeoreferencingDialog dialog = null; |
72 |
private FLyrPoints lyrPoints = null; |
73 |
private FLyrGeoRaster lyrGeoRaster = null; |
74 |
private View theView = null; |
75 |
private ViewPort viewPort = null; |
76 |
|
77 |
/**
|
78 |
* Posici?n del punto a ser seleccionado.
|
79 |
*/
|
80 |
private int posPoint = -1; |
81 |
/**
|
82 |
* Es true si el punto que se ha movido corresponde con el pixel
|
83 |
* de la imagen y false si corresponde con el punto de la vista
|
84 |
*/
|
85 |
private boolean isPixel = true; |
86 |
|
87 |
/**
|
88 |
* Constructor
|
89 |
*
|
90 |
* @param mapCtrl
|
91 |
*/
|
92 |
public GeorefMovePointListener(GeoreferencingDialog dialog) {
|
93 |
super();
|
94 |
this.dialog = dialog;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Captura de puntos sobre una capa FlyrPoint
|
99 |
*
|
100 |
* @param event Evento de un punto sobre la vista
|
101 |
*
|
102 |
* @throws BehaviorException
|
103 |
*/
|
104 |
public void press(PointEvent event) throws BehaviorException { |
105 |
super.press(event);
|
106 |
|
107 |
try{
|
108 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
109 |
}catch(ClassCastException exc){ |
110 |
return;
|
111 |
} |
112 |
viewPort = theView.getMapControl().getMapContext().getViewPort(); |
113 |
FLayers flayers = theView.getMapControl().getMapContext().getLayers(); |
114 |
|
115 |
//Obtenci?n de la capa de puntos.
|
116 |
|
117 |
for(int i=0;i<flayers.getLayersCount();i++){ |
118 |
FLayer lyr = flayers.getLayer(i); |
119 |
if(lyr instanceof FLyrGeoRaster) |
120 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
121 |
} |
122 |
lyrPoints = lyrGeoRaster.getFLyrPoints(); |
123 |
if(lyrGeoRaster == null || lyrPoints == null) |
124 |
return;
|
125 |
|
126 |
|
127 |
//Hallamos el punto m?s cercano a donde hemos pinchado
|
128 |
Point2D init = viewPort.toMapPoint(event.getPoint());
|
129 |
double distance = Double.MAX_VALUE; |
130 |
|
131 |
for(int i=0;i<lyrPoints.length();i++){ |
132 |
Point2D pixel = lyrGeoRaster.img2World(lyrPoints.getPoint(i).pixelPoint);
|
133 |
Point2D map = lyrPoints.getPoint(i).mapPoint;
|
134 |
double d1 = init.distance(pixel.getX(), pixel.getY());
|
135 |
|
136 |
if(d1 < distance){
|
137 |
distance = d1; |
138 |
posPoint = i; |
139 |
isPixel = true;
|
140 |
} |
141 |
d1 = init.distance(map.getX(), map.getY()); |
142 |
if(d1 < distance){
|
143 |
distance = d1; |
144 |
posPoint = i; |
145 |
isPixel = false;
|
146 |
} |
147 |
} |
148 |
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
153 |
*
|
154 |
* @param e MouseEvent
|
155 |
*
|
156 |
* @throws BehaviorException Excepci?n lanzada cuando el Maptool.
|
157 |
*/
|
158 |
public void release(PointEvent e) throws BehaviorException { |
159 |
|
160 |
if(posPoint != -1){ |
161 |
//Seleccionamos en el dialogo el punto que se est? moviendo
|
162 |
lyrGeoRaster.getGeoDialog().getSelectPointsPanel().changePoint(true, posPoint);
|
163 |
|
164 |
if(isPixel){
|
165 |
//Comprobamos que el punto siga dentro de la imagen
|
166 |
Point2D pixelPoint = lyrGeoRaster.world2Img(viewPort.toMapPoint(e.getPoint()));
|
167 |
if(pixelPoint == null){ |
168 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
169 |
PluginServices.getText(this, "fuera_de_extent")); |
170 |
return;
|
171 |
} |
172 |
|
173 |
if(theView != null && lyrGeoRaster != null && lyrPoints != null) |
174 |
lyrGeoRaster.getFLyrPoints().getPointManager(). |
175 |
updateData(posPoint + 1,
|
176 |
pixelPoint, |
177 |
null,
|
178 |
lyrGeoRaster.getGeoDialog(), |
179 |
theView); |
180 |
|
181 |
}else{
|
182 |
Point2D mapPoint = viewPort.toMapPoint(e.getPoint());
|
183 |
if(theView != null && lyrGeoRaster != null && lyrPoints != null) |
184 |
lyrGeoRaster.getFLyrPoints().getPointManager(). |
185 |
updateData(posPoint + 1,
|
186 |
null,
|
187 |
mapPoint, |
188 |
lyrGeoRaster.getGeoDialog(), |
189 |
theView); |
190 |
} |
191 |
|
192 |
} |
193 |
} |
194 |
} |