svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / ui / GeoLocationDialog.java @ 16326
History | View | Annotate | Download (6.7 KB)
1 | 12825 | nacho | /* 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 | 13127 | nacho | import java.io.IOException; |
24 | 12825 | nacho | |
25 | import javax.swing.JPanel; |
||
26 | |||
27 | import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
||
28 | 13622 | bsanchez | import org.gvsig.raster.util.RasterToolsUtil; |
29 | 12825 | nacho | 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 | 16326 | nbrodin | import com.iver.cit.gvsig.fmap.ViewPort; |
37 | 12825 | nacho | 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 | 12853 | nacho | * Dialogo de geolocalizaci?n de raster.
|
43 | 12825 | nacho | *
|
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 | 13310 | bsanchez | private static final long serialVersionUID = 7362459094802955247L; |
50 | private GeoLocationPanel geolocationPanel = null; |
||
51 | 13127 | nacho | |
52 | 13310 | bsanchez | /**
|
53 | * Posici?n de la ventana en X y en Y
|
||
54 | */
|
||
55 | private int posWindowX = 0; |
||
56 | private int posWindowY = 0; |
||
57 | |||
58 | 14135 | nbrodin | private int widthWindow = 260; |
59 | 16326 | nbrodin | private int heightWindow = 155; |
60 | 13310 | bsanchez | |
61 | private String lastTool = null; |
||
62 | |||
63 | /**
|
||
64 | 14135 | nbrodin | * Constructor
|
65 | */
|
||
66 | 13310 | bsanchez | public GeoLocationDialog() {
|
67 | BorderLayout bl = new BorderLayout(5, 5); |
||
68 | this.setLayout(bl);
|
||
69 | 13127 | nacho | |
70 | 13310 | bsanchez | this.add(getGeoLocationPanel());
|
71 | } |
||
72 | |||
73 | /**
|
||
74 | 14135 | nbrodin | * Constructor. Asigna la capa raster.
|
75 | *
|
||
76 | */
|
||
77 | 16326 | nbrodin | public GeoLocationDialog(FLyrRasterSE lyr, ViewPort vp) {
|
78 | 14135 | nbrodin | BorderLayout bl = new BorderLayout(5, 5); |
79 | this.setLayout(bl);
|
||
80 | |||
81 | this.add(getGeoLocationPanel());
|
||
82 | 16326 | nbrodin | getGeoLocationPanel().setParams(lyr, vp); |
83 | 14135 | nbrodin | } |
84 | |||
85 | /**
|
||
86 | 13310 | bsanchez | * 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 | 13127 | nacho | } |
97 | 13310 | bsanchez | } |
98 | |||
99 | /**
|
||
100 | * Referencia la capa que est? seleccionada
|
||
101 | *
|
||
102 | */
|
||
103 | 16326 | nbrodin | private void loadLayer(ViewPort vp) { |
104 | 14135 | nbrodin | 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 | 13310 | bsanchez | 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 | 16326 | nbrodin | getGeoLocationPanel().setParams(((FLyrRasterSE)actives[i]), vp); |
112 | 13310 | bsanchez | break;
|
113 | 12825 | nacho | } |
114 | } |
||
115 | 13310 | bsanchez | } |
116 | |||
117 | /**
|
||
118 | * Acciones de inicializaci?n
|
||
119 | *
|
||
120 | */
|
||
121 | public void init(MapControl mapCtrl) { |
||
122 | geolocationPanel.setMapCtrl(mapCtrl); |
||
123 | lastTool = mapCtrl.getCurrentTool(); |
||
124 | 16326 | nbrodin | loadLayer(mapCtrl.getViewPort()); |
125 | 13310 | bsanchez | FLyrRasterSE lyr = getGeoLocationPanel().getLayer(); |
126 | if(lyr != null) { |
||
127 | lyr.getAffineTransformHistorical().clear(); |
||
128 | lyr.getAffineTransformHistorical().add(lyr.getAffineTransform()); |
||
129 | loadTransform(lyr.getAffineTransform()); |
||
130 | 13127 | nacho | } |
131 | 13310 | bsanchez | 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 | 13127 | nacho | |
159 | 13310 | bsanchez | return geolocationPanel;
|
160 | } |
||
161 | 12825 | nacho | |
162 | 13310 | bsanchez | /**
|
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 | 14135 | nbrodin | WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
|
177 | 13310 | bsanchez | 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 | 12825 | nacho | |
184 | 13310 | bsanchez | /**
|
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 | 12825 | nacho | |
200 | 13310 | bsanchez | /*
|
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 | 13328 | nacho | geolocationPanel.getLayer().saveGeoToRmf(); |
210 | 13310 | bsanchez | } catch (IOException e1) { |
211 | RasterToolsUtil.messageBoxError(PluginServices.getText(this,"error_salvando_rmf"), geolocationPanel); |
||
212 | 13127 | nacho | } |
213 | } |
||
214 | 13310 | bsanchez | geolocationPanel.setModify(false);
|
215 | 12825 | nacho | } |
216 | 13310 | bsanchez | |
217 | //Restauramos la tool que hab?a antes de de activar la actual
|
||
218 | if(lastTool != null) |
||
219 | getGeoLocationPanel().getMapCtrl().setTool(lastTool); |
||
220 | 14135 | nbrodin | |
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 | 13310 | bsanchez | } |
225 | 12825 | nacho | } |