svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / ui / GeoLocationDialog.java @ 14135
History | View | Annotate | Download (6.67 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.rastertools.geolocation.ui; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.geom.AffineTransform; |
23 |
import java.io.IOException; |
24 |
|
25 |
import javax.swing.JPanel; |
26 |
|
27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
28 |
import org.gvsig.raster.util.RasterToolsUtil; |
29 |
import org.gvsig.rastertools.geolocation.behavior.ITransformIO; |
30 |
|
31 |
import com.iver.andami.PluginServices; |
32 |
import com.iver.andami.ui.mdiManager.IWindow; |
33 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
34 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
35 |
import com.iver.cit.gvsig.fmap.MapControl; |
36 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
37 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
38 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
39 |
|
40 |
/**
|
41 |
* Dialogo de geolocalizaci?n de raster.
|
42 |
*
|
43 |
* @version 30/07/2007
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
45 |
*
|
46 |
*/
|
47 |
public class GeoLocationDialog extends JPanel implements IWindow, IWindowListener, ITransformIO { |
48 |
private static final long serialVersionUID = 7362459094802955247L; |
49 |
private GeoLocationPanel geolocationPanel = null; |
50 |
|
51 |
/**
|
52 |
* Posici?n de la ventana en X y en Y
|
53 |
*/
|
54 |
private int posWindowX = 0; |
55 |
private int posWindowY = 0; |
56 |
|
57 |
private int widthWindow = 260; |
58 |
private int heightWindow = 140; |
59 |
|
60 |
private String lastTool = null; |
61 |
|
62 |
//private FLyrRasterSE lyr = null;
|
63 |
|
64 |
|
65 |
/**
|
66 |
* Constructor
|
67 |
*/
|
68 |
public GeoLocationDialog() {
|
69 |
BorderLayout bl = new BorderLayout(5, 5); |
70 |
this.setLayout(bl);
|
71 |
|
72 |
this.add(getGeoLocationPanel());
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* Constructor. Asigna la capa raster.
|
77 |
*
|
78 |
*/
|
79 |
public GeoLocationDialog(FLyrRasterSE lyr) {
|
80 |
BorderLayout bl = new BorderLayout(5, 5); |
81 |
this.setLayout(bl);
|
82 |
|
83 |
this.add(getGeoLocationPanel());
|
84 |
getGeoLocationPanel().setLayer(lyr); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Calculo de la posici?n de la ventana
|
89 |
*/
|
90 |
public void calcPosition() { |
91 |
IWindow[] list = PluginServices.getMDIManager().getAllWindows();
|
92 |
for (int i = 0; i < list.length; i++) { |
93 |
if(list[i] instanceof IView) { |
94 |
WindowInfo wInfo = PluginServices.getMDIManager().getWindowInfo(list[i]); |
95 |
posWindowX = wInfo.getX() + (wInfo.getWidth() / 2) - (widthWindow / 2); |
96 |
posWindowY = wInfo.getY() + (wInfo.getHeight() / 2) - (heightWindow / 2); |
97 |
} |
98 |
} |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Referencia la capa que est? seleccionada
|
103 |
*
|
104 |
*/
|
105 |
private void loadLayer() { |
106 |
if(getGeoLocationPanel().getLayer() != null) |
107 |
return;
|
108 |
//Este c?digo es para poder lanzar la funcionalidad desde la barra de herramientas y no desde el TOC
|
109 |
FLayers flyrs = getGeoLocationPanel().getMapCtrl().getMapContext().getLayers(); |
110 |
FLayer[] actives = flyrs.getActives();
|
111 |
for (int i = 0; i < actives.length; i++) { |
112 |
if(actives[i] instanceof FLyrRasterSE) { |
113 |
getGeoLocationPanel().setLayer(((FLyrRasterSE)actives[i])); |
114 |
break;
|
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Acciones de inicializaci?n
|
121 |
*
|
122 |
*/
|
123 |
public void init(MapControl mapCtrl) { |
124 |
geolocationPanel.setMapCtrl(mapCtrl); |
125 |
lastTool = mapCtrl.getCurrentTool(); |
126 |
loadLayer(); |
127 |
FLyrRasterSE lyr = getGeoLocationPanel().getLayer(); |
128 |
if(lyr != null) { |
129 |
lyr.getAffineTransformHistorical().clear(); |
130 |
lyr.getAffineTransformHistorical().add(lyr.getAffineTransform()); |
131 |
loadTransform(lyr.getAffineTransform()); |
132 |
} |
133 |
activeButtons(); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Carga los par?metros en el dialogo a partir de la capa
|
138 |
* @param lyr Capa raster
|
139 |
*/
|
140 |
public void loadTransform(AffineTransform at) { |
141 |
geolocationPanel.loadTransform(at); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
|
146 |
* del estado de la lista de transformaciones.
|
147 |
* @return
|
148 |
*/
|
149 |
public void applyTransformation() { |
150 |
geolocationPanel.setModify(true);
|
151 |
geolocationPanel.activeButtons(); |
152 |
} |
153 |
/**
|
154 |
* Obtiene el panel con el histograma
|
155 |
* @return HistogramPanel
|
156 |
*/
|
157 |
public GeoLocationPanel getGeoLocationPanel(){
|
158 |
if (geolocationPanel == null) |
159 |
geolocationPanel = new GeoLocationPanel();
|
160 |
|
161 |
return geolocationPanel;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
|
166 |
* del estado de la lista de transformaciones.
|
167 |
* @return
|
168 |
*/
|
169 |
public void activeButtons() { |
170 |
getGeoLocationPanel().activeButtons(); |
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
176 |
*/
|
177 |
public WindowInfo getWindowInfo() {
|
178 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
|
179 |
m_viewinfo.setHeight(heightWindow); |
180 |
m_viewinfo.setWidth(widthWindow); |
181 |
m_viewinfo.setX(posWindowX); |
182 |
m_viewinfo.setY(posWindowY); |
183 |
return m_viewinfo;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Asigna el ?ltimo tool seleccionado antes de abrir el di?logo para
|
188 |
* restaurarlo cuando se cierre este.
|
189 |
* @param tool
|
190 |
*/
|
191 |
public void setLastTool(String tool) { |
192 |
this.lastTool = tool;
|
193 |
} |
194 |
|
195 |
/*
|
196 |
* (non-Javadoc)
|
197 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowActivated()
|
198 |
*/
|
199 |
public void windowActivated() { |
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
|
205 |
*/
|
206 |
public void windowClosed() { |
207 |
//Se consulta si se desean salvar los cambios
|
208 |
if(geolocationPanel.getModify()) {
|
209 |
if(RasterToolsUtil.messageBoxYesOrNot(PluginServices.getText(this,"aviso_salir_salvando"), geolocationPanel)) { |
210 |
try {
|
211 |
geolocationPanel.getLayer().saveGeoToRmf(); |
212 |
} catch (IOException e1) { |
213 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this,"error_salvando_rmf"), geolocationPanel); |
214 |
} |
215 |
} |
216 |
geolocationPanel.setModify(false);
|
217 |
} |
218 |
|
219 |
//Restauramos la tool que hab?a antes de de activar la actual
|
220 |
if(lastTool != null) |
221 |
getGeoLocationPanel().getMapCtrl().setTool(lastTool); |
222 |
|
223 |
//TODO: Si queremos usar la funcionalidad de geolocalizaci?n desde la barra de herramientas deberemos
|
224 |
//, al cerrar la ventana, asignar la capa raster de GeoRasterBehevior a null ya que sino se aplicar?n las
|
225 |
//transformaciones sobre la ?ltima capa que se abri? desde el men? del TOC
|
226 |
} |
227 |
} |