root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / ui / GeoLocationDialog.java @ 13328
History | View | Annotate | Download (6.08 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.rastertools.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 = 245; |
58 |
private int heightWindow = 135; |
59 |
|
60 |
private String lastTool = null; |
61 |
|
62 |
//private FLyrRasterSE lyr = null;
|
63 |
|
64 |
|
65 |
/**
|
66 |
* Crea la ventana del histograma con un ancho y alto.
|
67 |
* @param width Ancho de la ventana
|
68 |
* @param height Alto de la ventana
|
69 |
*/
|
70 |
public GeoLocationDialog() {
|
71 |
BorderLayout bl = new BorderLayout(5, 5); |
72 |
this.setLayout(bl);
|
73 |
|
74 |
this.add(getGeoLocationPanel());
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Calculo de la posici?n de la ventana
|
79 |
*/
|
80 |
public void calcPosition() { |
81 |
IWindow[] list = PluginServices.getMDIManager().getAllWindows();
|
82 |
for (int i = 0; i < list.length; i++) { |
83 |
if(list[i] instanceof IView) { |
84 |
WindowInfo wInfo = PluginServices.getMDIManager().getWindowInfo(list[i]); |
85 |
posWindowX = wInfo.getX() + (wInfo.getWidth() / 2) - (widthWindow / 2); |
86 |
posWindowY = wInfo.getY() + (wInfo.getHeight() / 2) - (heightWindow / 2); |
87 |
} |
88 |
} |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Referencia la capa que est? seleccionada
|
93 |
*
|
94 |
*/
|
95 |
private void loadLayer() { |
96 |
FLayers flyrs = getGeoLocationPanel().getMapCtrl().getMapContext().getLayers(); |
97 |
FLayer[] actives = flyrs.getActives();
|
98 |
for (int i = 0; i < actives.length; i++) { |
99 |
if(actives[i] instanceof FLyrRasterSE) { |
100 |
getGeoLocationPanel().setLayer(((FLyrRasterSE)actives[i])); |
101 |
break;
|
102 |
} |
103 |
} |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Acciones de inicializaci?n
|
108 |
*
|
109 |
*/
|
110 |
public void init(MapControl mapCtrl) { |
111 |
geolocationPanel.setMapCtrl(mapCtrl); |
112 |
lastTool = mapCtrl.getCurrentTool(); |
113 |
loadLayer(); |
114 |
FLyrRasterSE lyr = getGeoLocationPanel().getLayer(); |
115 |
if(lyr != null) { |
116 |
lyr.getAffineTransformHistorical().clear(); |
117 |
lyr.getAffineTransformHistorical().add(lyr.getAffineTransform()); |
118 |
loadTransform(lyr.getAffineTransform()); |
119 |
} |
120 |
activeButtons(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Carga los par?metros en el dialogo a partir de la capa
|
125 |
* @param lyr Capa raster
|
126 |
*/
|
127 |
public void loadTransform(AffineTransform at) { |
128 |
geolocationPanel.loadTransform(at); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
|
133 |
* del estado de la lista de transformaciones.
|
134 |
* @return
|
135 |
*/
|
136 |
public void applyTransformation() { |
137 |
geolocationPanel.setModify(true);
|
138 |
geolocationPanel.activeButtons(); |
139 |
} |
140 |
/**
|
141 |
* Obtiene el panel con el histograma
|
142 |
* @return HistogramPanel
|
143 |
*/
|
144 |
public GeoLocationPanel getGeoLocationPanel(){
|
145 |
if (geolocationPanel == null) |
146 |
geolocationPanel = new GeoLocationPanel();
|
147 |
|
148 |
return geolocationPanel;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
|
153 |
* del estado de la lista de transformaciones.
|
154 |
* @return
|
155 |
*/
|
156 |
public void activeButtons() { |
157 |
getGeoLocationPanel().activeButtons(); |
158 |
} |
159 |
|
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
163 |
*/
|
164 |
public WindowInfo getWindowInfo() {
|
165 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.RESIZABLE);
|
166 |
m_viewinfo.setHeight(heightWindow); |
167 |
m_viewinfo.setWidth(widthWindow); |
168 |
m_viewinfo.setX(posWindowX); |
169 |
m_viewinfo.setY(posWindowY); |
170 |
return m_viewinfo;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Asigna el ?ltimo tool seleccionado antes de abrir el di?logo para
|
175 |
* restaurarlo cuando se cierre este.
|
176 |
* @param tool
|
177 |
*/
|
178 |
public void setLastTool(String tool) { |
179 |
this.lastTool = tool;
|
180 |
} |
181 |
|
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowActivated()
|
185 |
*/
|
186 |
public void windowActivated() { |
187 |
} |
188 |
|
189 |
/*
|
190 |
* (non-Javadoc)
|
191 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
|
192 |
*/
|
193 |
public void windowClosed() { |
194 |
//Se consulta si se desean salvar los cambios
|
195 |
if(geolocationPanel.getModify()) {
|
196 |
if(RasterToolsUtil.messageBoxYesOrNot(PluginServices.getText(this,"aviso_salir_salvando"), geolocationPanel)) { |
197 |
try {
|
198 |
geolocationPanel.getLayer().saveGeoToRmf(); |
199 |
} catch (IOException e1) { |
200 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this,"error_salvando_rmf"), geolocationPanel); |
201 |
} |
202 |
} |
203 |
geolocationPanel.setModify(false);
|
204 |
} |
205 |
|
206 |
//Restauramos la tool que hab?a antes de de activar la actual
|
207 |
if(lastTool != null) |
208 |
getGeoLocationPanel().getMapCtrl().setTool(lastTool); |
209 |
} |
210 |
} |