root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Dialogs / GeoreferencingDialog.java @ 3012
History | View | Annotate | Download (11.3 KB)
1 | 2844 | nacho | package com.iver.cit.gvsig.gui.Dialogs; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | import java.awt.FlowLayout; |
||
5 | 3009 | nacho | import java.awt.event.ActionListener; |
6 | 2945 | nacho | import java.beans.PropertyVetoException; |
7 | 2844 | nacho | |
8 | import javax.swing.JButton; |
||
9 | import javax.swing.JFileChooser; |
||
10 | 2945 | nacho | import javax.swing.JInternalFrame; |
11 | 2844 | nacho | import javax.swing.JPanel; |
12 | |||
13 | import org.cresques.cts.IProjection; |
||
14 | |||
15 | import com.iver.andami.PluginServices; |
||
16 | 2854 | nacho | import com.iver.cit.gvsig.fmap.MapControl; |
17 | 2947 | nacho | import com.iver.cit.gvsig.fmap.layers.FLayer; |
18 | import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
||
19 | 2987 | nacho | import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
20 | 2854 | nacho | import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
21 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
22 | 2894 | nacho | import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior; |
23 | import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior; |
||
24 | 2854 | nacho | import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
25 | import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
||
26 | 2947 | nacho | import com.iver.cit.gvsig.gui.View; |
27 | 3012 | nacho | import com.iver.cit.gvsig.gui.Panels.DataPointsTabPanel; |
28 | 2844 | nacho | import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
29 | import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
||
30 | 3012 | nacho | import com.iver.cit.gvsig.gui.Panels.TablePointsPanel; |
31 | 2854 | nacho | import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener; |
32 | 2958 | nacho | import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener; |
33 | 2854 | nacho | import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
34 | 2894 | nacho | import com.iver.cit.gvsig.gui.toolListeners.ZoomGeorefListener; |
35 | 2844 | nacho | import com.iver.cit.gvsig.gui.wizards.WizardListener; |
36 | import com.iver.cit.gvsig.project.Project; |
||
37 | |||
38 | /**
|
||
39 | * Panel que contiene el Wizard de georeferenciaci?n con los tabs
|
||
40 | * interiores
|
||
41 | *
|
||
42 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
43 | */
|
||
44 | 3009 | nacho | public class GeoreferencingDialog extends JPanel implements ActionListener { |
45 | 2844 | nacho | |
46 | 2945 | nacho | |
47 | 2844 | nacho | static private IProjection proj = Project.getProjection(); |
48 | private JFileChooser fileChooser; |
||
49 | 2958 | nacho | private JPanel pBotones = null; // @jve:decl-index=0: |
50 | private JButton bProcesar = null; // @jve:decl-index=0: |
||
51 | private JButton bCancelar = null; // @jve:decl-index=0: |
||
52 | 2844 | nacho | private WizardListener wizardListener = new DialogWizardListener(); |
53 | 2958 | nacho | private JButton bSave = null; // @jve:decl-index=0: |
54 | 2894 | nacho | private GeoRedimBehavior rb = null; |
55 | private GeoMoveBehavior mb = null; |
||
56 | 2854 | nacho | private static boolean loadTools = false; |
57 | 2945 | nacho | private JInternalFrame frame = null; |
58 | 3012 | nacho | |
59 | 2958 | nacho | private SelectFilePanel selectFilePanel = null; |
60 | private SelectPointsPanel selectPointsPanel = null; |
||
61 | 3012 | nacho | private TablePointsPanel tablePointsPanel = null; |
62 | private DataPointsTabPanel dataPointsTabPanel = null; |
||
63 | 2844 | nacho | |
64 | 2987 | nacho | private JButton bAceptar = null; |
65 | 3012 | nacho | |
66 | 2844 | nacho | /**
|
67 | * Constructor.
|
||
68 | */
|
||
69 | 2945 | nacho | public GeoreferencingDialog(JInternalFrame f) { |
70 | frame = f; |
||
71 | 2844 | nacho | initialize(); |
72 | } |
||
73 | |||
74 | /**
|
||
75 | 2993 | nacho | * Asigna el frame
|
76 | * @param f
|
||
77 | */
|
||
78 | public void setFrame(JInternalFrame f){ |
||
79 | frame = f; |
||
80 | } |
||
81 | |||
82 | /**
|
||
83 | 2893 | nacho | * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos
|
84 | * ls herramientas para manejar las imagenes a georeferenciar.
|
||
85 | 2844 | nacho | */
|
86 | private void initialize() { |
||
87 | 2931 | nacho | //Cargamos las herramientas la primera vez que abrimos la ventana
|
88 | 2854 | nacho | if(!loadTools){
|
89 | GeoreferencingDialog.loadTools = true;
|
||
90 | com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
||
91 | MapControl mapCtrl = vista.getMapControl(); |
||
92 | |||
93 | StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
||
94 | |||
95 | ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
|
||
96 | 2894 | nacho | ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
|
97 | 2903 | nacho | rb = new GeoRedimBehavior(zigl, this); |
98 | 2893 | nacho | mapCtrl.addMapTool("geoZoom", new Behavior[]{rb, |
99 | 2854 | nacho | new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
100 | |||
101 | GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
||
102 | 2903 | nacho | mb = new GeoMoveBehavior(pl, this); |
103 | 2894 | nacho | mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
104 | 2958 | nacho | |
105 | //Seleccion de un punto sobre la vista
|
||
106 | GeorefPointerListener psl = new GeorefPointerListener(this); |
||
107 | mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)}); |
||
108 | |||
109 | 2854 | nacho | } |
110 | 2931 | nacho | |
111 | this.setLayout(new BorderLayout()); |
||
112 | this.setPreferredSize(new java.awt.Dimension(400,315)); |
||
113 | this.setSize(new java.awt.Dimension(400,315)); |
||
114 | this.setLocation(new java.awt.Point(0,0)); |
||
115 | this.add(getPBotones(), java.awt.BorderLayout.SOUTH);
|
||
116 | 3012 | nacho | tablePointsPanel = new TablePointsPanel();
|
117 | 2958 | nacho | selectPointsPanel = new SelectPointsPanel();
|
118 | 3012 | nacho | this.add(this.getDataPointsPanel(), null); |
119 | |||
120 | 2964 | nacho | |
121 | 2844 | nacho | } |
122 | 2987 | nacho | |
123 | 2844 | nacho | /**
|
124 | 3012 | nacho | * Obtiene el panel que contiene los tabs de selecci?n de puntos y tabla de puntos.
|
125 | * @return
|
||
126 | 2844 | nacho | */
|
127 | 3012 | nacho | public DataPointsTabPanel getDataPointsPanel() {
|
128 | if (dataPointsTabPanel == null) { |
||
129 | dataPointsTabPanel = new DataPointsTabPanel(this.selectPointsPanel, this.tablePointsPanel); |
||
130 | dataPointsTabPanel.setBounds(0, 0, 519, 352); |
||
131 | } |
||
132 | |||
133 | return dataPointsTabPanel;
|
||
134 | 2844 | nacho | } |
135 | |||
136 | /**
|
||
137 | * This method initializes jPanel
|
||
138 | *
|
||
139 | * @return javax.swing.JPanel
|
||
140 | */
|
||
141 | private JPanel getPBotones() { |
||
142 | if (pBotones == null) { |
||
143 | FlowLayout flowLayout1 = new FlowLayout(); |
||
144 | pBotones = new JPanel(); |
||
145 | pBotones.setLayout(flowLayout1); |
||
146 | 2987 | nacho | flowLayout1.setHgap(10);
|
147 | 2844 | nacho | pBotones.add(getBProcesar(), null);
|
148 | pBotones.add(getBSave(), null);
|
||
149 | 2987 | nacho | pBotones.add(getBAceptar(), null);
|
150 | 2844 | nacho | pBotones.add(getBCancelar(), null);
|
151 | } |
||
152 | return pBotones;
|
||
153 | } |
||
154 | |||
155 | 2993 | nacho | |
156 | |||
157 | 2844 | nacho | public class DialogWizardListener implements WizardListener { |
158 | |||
159 | /**
|
||
160 | * @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
|
||
161 | */
|
||
162 | public void error(Exception e) { |
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
|
||
167 | */
|
||
168 | public void wizardStateChanged(boolean finishable) { |
||
169 | getBProcesar().setEnabled(finishable); |
||
170 | } |
||
171 | |||
172 | } |
||
173 | public static IProjection getLastProjection() { |
||
174 | return proj;
|
||
175 | } |
||
176 | public static void setLastProjection(IProjection proj) { |
||
177 | GeoreferencingDialog.proj = proj; |
||
178 | } |
||
179 | |||
180 | 2893 | nacho | |
181 | 2993 | nacho | |
182 | 2893 | nacho | /**
|
183 | 2894 | nacho | * @return Returns the GeoRedimBehavior.
|
184 | 2893 | nacho | */
|
185 | 2903 | nacho | public GeoRedimBehavior getGeoRedimBehavior() {
|
186 | 2893 | nacho | return rb;
|
187 | } |
||
188 | |||
189 | /**
|
||
190 | 2894 | nacho | * @param rb The GeoRedimBehavior to set.
|
191 | 2893 | nacho | */
|
192 | 2903 | nacho | public void setGeoRedimBehavior(GeoRedimBehavior rb) { |
193 | 2893 | nacho | this.rb = rb;
|
194 | } |
||
195 | 2894 | nacho | |
196 | /**
|
||
197 | * @return Returns the GeoMoveBehavior
|
||
198 | */
|
||
199 | public GeoMoveBehavior getGeoMoveBehavior() {
|
||
200 | return mb;
|
||
201 | } |
||
202 | |||
203 | /**
|
||
204 | * @param mb The GeoMoveBehavior to set.
|
||
205 | */
|
||
206 | public void setGeoMoveBehavior(GeoMoveBehavior mb) { |
||
207 | this.mb = mb;
|
||
208 | } |
||
209 | 2945 | nacho | |
210 | |||
211 | /* (non-Javadoc)
|
||
212 | * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
||
213 | */
|
||
214 | /*public ViewInfo getViewInfo() {
|
||
215 | ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG |
|
||
216 | ViewInfo.RESIZABLE);
|
||
217 | m_viewinfo.setWidth(this.getWidth());
|
||
218 | m_viewinfo.setHeight(this.getHeight());
|
||
219 | m_viewinfo.setTitle(PluginServices.getText(this,
|
||
220 | "cargar_sin_georef"));
|
||
221 | |||
222 | return m_viewinfo;
|
||
223 | }*/
|
||
224 | |||
225 | /**
|
||
226 | * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
|
||
227 | */
|
||
228 | /*public Object getViewModel() {
|
||
229 | return "GeoreferencingDialog";
|
||
230 | }*/
|
||
231 | 2958 | nacho | |
232 | /**
|
||
233 | * @return Returns the selectFilePanel.
|
||
234 | */
|
||
235 | public SelectFilePanel getSelectFilePanel() {
|
||
236 | return selectFilePanel;
|
||
237 | } |
||
238 | |||
239 | /**
|
||
240 | * @param selectFilePanel The selectFilePanel to set.
|
||
241 | */
|
||
242 | public void setSelectFilePanel(SelectFilePanel selectFilePanel) { |
||
243 | this.selectFilePanel = selectFilePanel;
|
||
244 | } |
||
245 | |||
246 | /**
|
||
247 | * @return Returns the selectPointsPanel.
|
||
248 | */
|
||
249 | public SelectPointsPanel getSelectPointsPanel() {
|
||
250 | return selectPointsPanel;
|
||
251 | } |
||
252 | |||
253 | /**
|
||
254 | * @param selectPointsPanel The selectPointsPanel to set.
|
||
255 | */
|
||
256 | public void setSelectPointsPanel(SelectPointsPanel selectPointsPanel) { |
||
257 | this.selectPointsPanel = selectPointsPanel;
|
||
258 | } |
||
259 | 3012 | nacho | |
260 | 2987 | nacho | /**
|
261 | * This method initializes jButton
|
||
262 | *
|
||
263 | * @return javax.swing.JButton
|
||
264 | */
|
||
265 | private JButton getBAceptar() { |
||
266 | if (bAceptar == null) { |
||
267 | bAceptar = new JButton(); |
||
268 | bAceptar.setText("aceptar");
|
||
269 | 3009 | nacho | bAceptar.addActionListener(this);
|
270 | } |
||
271 | return bAceptar;
|
||
272 | } |
||
273 | |||
274 | 3012 | nacho | /**
|
275 | * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
|
||
276 | * <UL>
|
||
277 | * <LI>Cambiamos el nombre a la capa georraster</LI>
|
||
278 | * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
|
||
279 | * <LI>Cerramos la ventana</LI>
|
||
280 | * </UL>
|
||
281 | */
|
||
282 | 3009 | nacho | public void actionPerformed(java.awt.event.ActionEvent e) { |
283 | if(e.getSource() == bAceptar){
|
||
284 | View theView = (View) PluginServices.getMDIManager().getActiveView(); |
||
285 | FLyrGeoRaster lyrGeoRaster = null;
|
||
286 | FLyrPoints lyrPoints = null;
|
||
287 | |||
288 | for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
||
289 | FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
||
290 | if( lyr instanceof FLyrGeoRaster && |
||
291 | lyr.getName().startsWith("*") &&
|
||
292 | lyr.isActive()){ |
||
293 | 3012 | nacho | |
294 | //Campbiamos el nombre a la capa GeoRaster
|
||
295 | 3009 | nacho | lyr.setName(lyr.getName().substring(1, lyr.getName().length()));
|
296 | lyr.setActive(false);
|
||
297 | lyrGeoRaster = (FLyrGeoRaster)lyr; |
||
298 | } |
||
299 | 2987 | nacho | |
300 | 3009 | nacho | if( lyr instanceof FLyrPoints) |
301 | lyrPoints = (FLyrPoints)lyr; |
||
302 | } |
||
303 | |||
304 | 3012 | nacho | //A la capa Georraster le asignamos la capa de puntos para poder recuperarla
|
305 | if(lyrGeoRaster != null) |
||
306 | 3009 | nacho | lyrGeoRaster.setFLyrPoints(lyrPoints); |
307 | 3012 | nacho | |
308 | 3009 | nacho | |
309 | theView.getMapControl().setTool("zoomIn");
|
||
310 | |||
311 | //Cerramos la ventana
|
||
312 | //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
|
||
313 | try{
|
||
314 | frame.setClosed(true);
|
||
315 | }catch(PropertyVetoException exc){} |
||
316 | 2987 | nacho | } |
317 | 3009 | nacho | |
318 | 2987 | nacho | } |
319 | 2993 | nacho | |
320 | /**
|
||
321 | * This method initializes bProcesar
|
||
322 | *
|
||
323 | * @return javax.swing.JButton
|
||
324 | */
|
||
325 | private JButton getBProcesar() { |
||
326 | if (bProcesar == null) { |
||
327 | bProcesar = new JButton(); |
||
328 | bProcesar.setText(PluginServices.getText(this,"procesar")); |
||
329 | bProcesar.setEnabled(false);
|
||
330 | bProcesar.setPreferredSize(new java.awt.Dimension(87,25)); |
||
331 | bProcesar.addActionListener(new java.awt.event.ActionListener() {
|
||
332 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
333 | /*if (PluginServices.getMainFrame() == null) {
|
||
334 | ((JDialog) (getParent().getParent().getParent()
|
||
335 | .getParent())).dispose();
|
||
336 | } else {
|
||
337 | PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this);
|
||
338 | }*/
|
||
339 | } |
||
340 | }); |
||
341 | } |
||
342 | return bProcesar;
|
||
343 | } |
||
344 | |||
345 | /**
|
||
346 | * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
|
||
347 | * y cierra la ventana.
|
||
348 | *
|
||
349 | * @return javax.swing.JButton
|
||
350 | */
|
||
351 | private JButton getBCancelar() { |
||
352 | if (bCancelar == null) { |
||
353 | bCancelar = new JButton(); |
||
354 | bCancelar.setText(PluginServices.getText(this,"cancelar")); |
||
355 | bCancelar.addActionListener(new java.awt.event.ActionListener() {
|
||
356 | 2998 | nacho | public void actionPerformed(java.awt.event.ActionEvent e) { |
357 | //Cerramos la ventana
|
||
358 | //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
|
||
359 | 2993 | nacho | try{
|
360 | frame.setClosed(true);
|
||
361 | }catch(PropertyVetoException exc){} |
||
362 | } |
||
363 | }); |
||
364 | } |
||
365 | return bCancelar;
|
||
366 | } |
||
367 | |||
368 | /**
|
||
369 | * This method initializes jButton
|
||
370 | *
|
||
371 | * @return javax.swing.JButton
|
||
372 | */
|
||
373 | private JButton getBSave() { |
||
374 | if (bSave == null) { |
||
375 | bSave = new JButton(); |
||
376 | bSave.setText(PluginServices.getText(this,"guardar")); |
||
377 | bSave.setEnabled(false);
|
||
378 | } |
||
379 | return bSave;
|
||
380 | } |
||
381 | 2844 | nacho | } // @jve:decl-index=0:visual-constraint="10,10"
|
382 | // @jve:visual-info decl-index=0 visual-constraint="10,10"
|
||
383 | // @jve:visual-info decl-index=0 visual-constraint="10,10" |