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