root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / toolListeners / GeorefPointerListener.java @ 2987
History | View | Annotate | Download (6.05 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 com.iver.cit.gvsig.gui.toolListeners; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.geom.Point2D; |
45 |
|
46 |
import javax.swing.JOptionPane; |
47 |
|
48 |
import com.iver.andami.PluginServices; |
49 |
import com.iver.cit.gvsig.fmap.DriverException; |
50 |
import com.iver.cit.gvsig.fmap.ViewPort; |
51 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
52 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
54 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
55 |
import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl; |
56 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
57 |
import com.iver.cit.gvsig.gui.View; |
58 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
59 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
60 |
import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
61 |
|
62 |
|
63 |
/**
|
64 |
* <p>Extensi?n de la clase GeorefPointerListenerImpl de FMap para poder llamar a m?todos de
|
65 |
* andami o de gvSIG.</p>
|
66 |
* <p>Este listener salva puntos clickeados desde una vista sobre una capa de puntos.</p>
|
67 |
*
|
68 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
69 |
*/
|
70 |
public class GeorefPointerListener extends GeorefPointerListenerImpl { |
71 |
|
72 |
private GeoreferencingDialog dialog = null; |
73 |
private View theView = null; |
74 |
private FLyrPoints lyrPoints = null; |
75 |
private FLyrGeoRaster lyrGeoRaster = null; |
76 |
|
77 |
/**
|
78 |
* true si se va a seleccionar el primer punto y false si se selecciona el segundo.
|
79 |
*
|
80 |
*/
|
81 |
public static boolean firstPoint = true; |
82 |
|
83 |
|
84 |
/**
|
85 |
* Posici?n del punto a ser seleccionado.
|
86 |
*/
|
87 |
public static int posPoint = -1; |
88 |
|
89 |
/**
|
90 |
* Constructor
|
91 |
*
|
92 |
* @param mapCtrl
|
93 |
*/
|
94 |
public GeorefPointerListener(GeoreferencingDialog dialog) {
|
95 |
super();
|
96 |
this.dialog = dialog;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Captura de puntos sobre una capa FlyrPoint
|
101 |
*
|
102 |
* @param event Evento de un punto sobre la vista
|
103 |
*
|
104 |
* @throws BehaviorException
|
105 |
*/
|
106 |
public void point(PointEvent event) throws BehaviorException { |
107 |
super.point(event);
|
108 |
|
109 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
110 |
//Obtenemos la capa de puntos y la capa de georaster
|
111 |
|
112 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
113 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
114 |
if(lyr instanceof FLyrPoints) |
115 |
lyrPoints = (FLyrPoints)lyr; |
116 |
if(lyr instanceof FLyrGeoRaster && lyr.getName().startsWith("*")) |
117 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
118 |
} |
119 |
|
120 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
121 |
Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
|
122 |
|
123 |
if(firstPoint){
|
124 |
if(lyrPoints != null){ |
125 |
|
126 |
//Si el punto cae fuera de la imagen mostramos un mensaje y salimos
|
127 |
while( wcPoint.getX() < lyrGeoRaster.getMinX() ||
|
128 |
wcPoint.getX() > lyrGeoRaster.getMaxX() || |
129 |
wcPoint.getY() < lyrGeoRaster.getMinY() || |
130 |
wcPoint.getY() > lyrGeoRaster.getMaxY()){ |
131 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
132 |
PluginServices.getText(this, "fuera_de_extent")); |
133 |
return;
|
134 |
} |
135 |
|
136 |
//Hallamos pixelImg q son las coordenadas en pixeles de la imagen que corresponden
|
137 |
//con el punto seleccionado
|
138 |
double wcWidth = 0.0, wcHeight = 0.0, ptoWCX = 0.0, ptoWCY = 0.0; |
139 |
int pixelImgX = 0, pixelImgY = 0; |
140 |
try{
|
141 |
wcWidth = lyrGeoRaster.getFullExtent().getWidth(); |
142 |
wcHeight = lyrGeoRaster.getFullExtent().getHeight(); |
143 |
ptoWCX = wcPoint.getX() - lyrGeoRaster.getFullExtent().getMinX(); |
144 |
ptoWCY = wcPoint.getY() - lyrGeoRaster.getFullExtent().getMinY(); |
145 |
pixelImgX = (int)((ptoWCX * SelectFilePanel.widthPxImg) / wcWidth);
|
146 |
pixelImgY = (int)((ptoWCY * SelectFilePanel.heightPxImg) / wcHeight);
|
147 |
}catch(DriverException ex){}
|
148 |
|
149 |
|
150 |
//Salvamos el primer punto pinchado en la capa. (Pixeles de la imagen)
|
151 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint = new Point2D.Double(); |
152 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint.setLocation(pixelImgX, pixelImgY); |
153 |
//Cargamos en la ventana el nuevo punto
|
154 |
dialog.getSelectPointsPanel().getTX().setText(String.valueOf(pixelImgX));
|
155 |
dialog.getSelectPointsPanel().getTY().setText(String.valueOf(pixelImgY));
|
156 |
firstPoint = false;
|
157 |
} |
158 |
}else{
|
159 |
//Salvamos el segundo punto pinchado en la capa (Coordenadas de georreferenciaci?n)
|
160 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint = new Point2D.Double(); |
161 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint.setLocation(wcPoint); |
162 |
//Cargamos en la ventana el nuevo punto
|
163 |
dialog.getSelectPointsPanel().getLongitud().setText(SelectPointsPanel.tailDecimal(String.valueOf(wcPoint.getX())));
|
164 |
dialog.getSelectPointsPanel().getLatitud().setText(SelectPointsPanel.tailDecimal(String.valueOf(wcPoint.getY())));
|
165 |
|
166 |
//Deseleccionamos la herramienta de marcado de puntos
|
167 |
theView.getMapControl().setTool(lyrPoints.getLastTool()); |
168 |
firstPoint = true;
|
169 |
} |
170 |
theView.getMapControl().getMapContext().invalidate(); |
171 |
lyrPoints.showPoints(); |
172 |
} |
173 |
} |