Revision 3079 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/toolListeners/GeorefMovePointListener.java
GeorefMovePointListener.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.gui.toolListeners; |
42 | 42 |
|
43 |
import java.awt.Component; |
|
43 | 44 |
import java.awt.event.MouseEvent; |
44 | 45 |
import java.awt.geom.Point2D; |
45 | 46 |
|
47 |
import javax.swing.JOptionPane; |
|
48 |
|
|
46 | 49 |
import com.iver.andami.PluginServices; |
47 | 50 |
import com.iver.cit.gvsig.fmap.ViewPort; |
48 | 51 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
... | ... | |
66 | 69 |
public class GeorefMovePointListener extends GeorefDraggListenerImpl { |
67 | 70 |
|
68 | 71 |
private GeoreferencingDialog dialog = null; |
69 |
private View theView = null; |
|
70 | 72 |
private FLyrPoints lyrPoints = null; |
71 | 73 |
private FLyrGeoRaster lyrGeoRaster = null; |
74 |
private View theView = null; |
|
75 |
private ViewPort viewPort = null; |
|
72 | 76 |
|
73 | 77 |
/** |
74 | 78 |
* Posici?n del punto a ser seleccionado. |
... | ... | |
100 | 104 |
public void press(PointEvent event) throws BehaviorException { |
101 | 105 |
super.press(event); |
102 | 106 |
|
103 |
View theView = (View) PluginServices.getMDIManager().getActiveView();
|
|
104 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
|
|
107 |
theView = (View) PluginServices.getMDIManager().getActiveView(); |
|
108 |
viewPort = theView.getMapControl().getMapContext().getViewPort(); |
|
105 | 109 |
FLayers flayers = theView.getMapControl().getMapContext().getLayers(); |
106 | 110 |
|
107 | 111 |
//Obtenci?n de la capa de puntos. |
108 |
FLyrPoints lyrPoints = null; |
|
109 |
FLyrGeoRaster lyrGeoRaster = null; |
|
112 |
|
|
110 | 113 |
for(int i=0;i<flayers.getLayersCount();i++){ |
111 | 114 |
FLayer lyr = flayers.getLayer(i); |
112 | 115 |
if(lyr instanceof FLyrGeoRaster) |
... | ... | |
120 | 123 |
//Hallamos el punto m?s cercano a donde hemos pinchado |
121 | 124 |
Point2D init = viewPort.toMapPoint(event.getPoint()); |
122 | 125 |
double distance = Double.MAX_VALUE; |
123 |
|
|
126 |
System.out.println("---"+distance+" "+lyrPoints.getCountPoints()+" "+lyrPoints.length()); |
|
124 | 127 |
for(int i=0;i<lyrPoints.length();i++){ |
125 | 128 |
Point2D pixel = lyrGeoRaster.img2World(lyrPoints.getPoint(i).pixelPoint); |
126 | 129 |
Point2D map = lyrPoints.getPoint(i).mapPoint; |
127 | 130 |
double d1 = init.distance(pixel.getX(), pixel.getY()); |
131 |
System.out.println(d1); |
|
128 | 132 |
if(d1 < distance){ |
129 | 133 |
distance = d1; |
130 | 134 |
posPoint = i; |
... | ... | |
148 | 152 |
* @throws BehaviorException Excepci?n lanzada cuando el Maptool. |
149 | 153 |
*/ |
150 | 154 |
public void release(PointEvent e) throws BehaviorException { |
155 |
System.out.println("--*-"+posPoint); |
|
151 | 156 |
if(posPoint != -1){ |
152 | 157 |
if(isPixel){ |
153 | 158 |
//Comprobamos que el punto siga dentro de la imagen |
159 |
Point2D pixelPoint = lyrGeoRaster.world2Img(viewPort.toMapPoint(e.getPoint())); |
|
160 |
if(pixelPoint == null){ |
|
161 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
|
162 |
PluginServices.getText(this, "fuera_de_extent")); |
|
163 |
return; |
|
164 |
} |
|
154 | 165 |
|
166 |
if(theView != null && lyrGeoRaster != null && lyrPoints != null) |
|
167 |
lyrGeoRaster.updateData(posPoint + 1, |
|
168 |
pixelPoint, |
|
169 |
null, |
|
170 |
lyrGeoRaster.getGeoDialog(), |
|
171 |
theView, |
|
172 |
lyrPoints); |
|
173 |
|
|
155 | 174 |
}else{ |
156 |
|
|
175 |
Point2D mapPoint = viewPort.toMapPoint(e.getPoint()); |
|
176 |
if(theView != null && lyrGeoRaster != null && lyrPoints != null) |
|
177 |
lyrGeoRaster.updateData(posPoint + 1, |
|
178 |
null, |
|
179 |
mapPoint, |
|
180 |
lyrGeoRaster.getGeoDialog(), |
|
181 |
theView, |
|
182 |
lyrPoints); |
|
157 | 183 |
} |
158 | 184 |
} |
159 | 185 |
} |
Also available in: Unified diff