Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Dialogs / GeoreferencingDialog.java @ 3023

History | View | Annotate | Download (12 KB)

1
package com.iver.cit.gvsig.gui.Dialogs;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
5
import java.awt.FlowLayout;
6
import java.awt.event.ActionListener;
7
import java.beans.PropertyVetoException;
8

    
9
import javax.swing.JButton;
10
import javax.swing.JFileChooser;
11
import javax.swing.JInternalFrame;
12
import javax.swing.JPanel;
13

    
14
import org.cresques.cts.IProjection;
15

    
16
import com.iver.andami.PluginServices;
17
import com.iver.cit.gvsig.fmap.MapControl;
18
import com.iver.cit.gvsig.fmap.layers.FLayer;
19
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
20
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
21
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
22
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
23
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior;
24
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior;
25
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
26
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
27
import com.iver.cit.gvsig.gui.View;
28
import com.iver.cit.gvsig.gui.Panels.ConectorPanel;
29
import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel;
30
import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener;
31
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener;
32
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
33
import com.iver.cit.gvsig.gui.toolListeners.ZoomGeorefListener;
34
import com.iver.cit.gvsig.gui.wizards.WizardListener;
35
import com.iver.cit.gvsig.project.Project;
36

    
37
/**
38
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
39
 * interiores
40
 *
41
 * @author Nacho Brodin (brodin_ign@gva.es)
42
 */
43
public class GeoreferencingDialog extends JPanel implements ActionListener {
44
            
45

    
46
        static private IProjection proj = Project.getProjection();
47
    private JFileChooser fileChooser;
48
        private JPanel pBotones = null;  //  @jve:decl-index=0:
49
        private JButton bProcesar = null;  //  @jve:decl-index=0:
50
        private JButton bCancelar = null;  //  @jve:decl-index=0:
51
        private WizardListener wizardListener = new DialogWizardListener();
52
        private JButton bSave = null;  //  @jve:decl-index=0:
53
        private GeoRedimBehavior rb = null;
54
        private GeoMoveBehavior mb = null;
55
        private static boolean loadTools = false;
56
        private JInternalFrame frame = null;
57

    
58
        private ConectorPanel        conectorPanel = null;
59
        
60
        private boolean enlarge = false;
61
        private int normalWidth = 410;
62
        private int normalHeight = 315;
63
        private int enlargeHeight = 600;
64
        
65
        private JButton bAceptar = null;
66
        private JPanel pGeneral = null;
67
        
68
    /**
69
     * Constructor.
70
     */
71
    public GeoreferencingDialog(JInternalFrame f) {
72
            frame = f;
73
            initialize();
74
    }
75

    
76
    /**
77
     * Asigna el frame
78
     * @param f
79
     */
80
    public void setFrame(JInternalFrame f){
81
            frame = f;
82
    }
83
    
84
    /**
85
     * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos 
86
     * ls herramientas para manejar las imagenes a georeferenciar.
87
     */
88
    private void initialize() {
89
            //Cargamos las herramientas la primera vez que abrimos la ventana
90
        if(!loadTools){
91
                GeoreferencingDialog.loadTools = true;
92
                com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
93
                MapControl mapCtrl = vista.getMapControl();
94

    
95
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
96
                        
97
                        ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
98
                        ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
99
                        rb = new GeoRedimBehavior(zigl, this);
100
                        mapCtrl.addMapTool("geoZoom", new Behavior[]{rb,
101
                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
102
                                                        
103
                        GeorefPanListener pl = new GeorefPanListener(mapCtrl);
104
                        mb = new GeoMoveBehavior(pl, this);
105
                        mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
106
                        
107
                        //Seleccion de un punto sobre la vista
108
                GeorefPointerListener psl = new GeorefPointerListener(this);
109
                mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
110
                
111
        }
112
        
113
        this.setLayout(new BorderLayout());
114
        if(!enlarge){
115
                this.setPreferredSize(new java.awt.Dimension(normalWidth, normalHeight));
116
                this.setSize(new java.awt.Dimension(normalWidth, normalHeight));
117
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(false);
118
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(false);
119
        }else{
120
                this.setPreferredSize(new java.awt.Dimension(normalWidth, enlargeHeight));
121
                this.setSize(new java.awt.Dimension(normalWidth, enlargeHeight));
122
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(true);
123
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(true);
124
        }
125
        this.setLocation(new java.awt.Point(0,0));
126
        
127
        this.add(this.getPBotones(), BorderLayout.SOUTH);
128
        this.add(this.getConectorPanel(), BorderLayout.NORTH);
129
   
130
               
131
    }
132
    
133
    
134
    public ConectorPanel getConectorPanel() {
135
            if (conectorPanel == null) {                            
136
                    conectorPanel = new ConectorPanel(this);
137
            }
138
        
139
            return conectorPanel;
140
    }
141
            
142
      
143
        /**
144
         * This method initializes jPanel        
145
         *         
146
         * @return javax.swing.JPanel        
147
         */    
148
        private JPanel getPBotones() {
149
                if (pBotones == null) {
150
                        FlowLayout flowLayout1 = new FlowLayout();
151
                        pBotones = new JPanel();
152
                        pBotones.setLayout(flowLayout1);
153
                        flowLayout1.setHgap(10);
154
                        pBotones.add(getBProcesar(), null);
155
                        pBotones.add(getBSave(), null);
156
                        pBotones.add(getBAceptar(), null);
157
                        pBotones.add(getBCancelar(), null);
158
                }
159
                return pBotones;
160
        }
161
        
162
        
163
        
164
        public class DialogWizardListener implements WizardListener {
165

    
166
                /**
167
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
168
                 */
169
                public void error(Exception e) {
170
                }
171

    
172
                /**
173
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
174
                 */
175
                public void wizardStateChanged(boolean finishable) {
176
                        getBProcesar().setEnabled(finishable);
177
                }
178
                
179
        }
180
        public static IProjection getLastProjection() {
181
                return proj;
182
        }
183
        public static void setLastProjection(IProjection proj) {
184
                GeoreferencingDialog.proj = proj;
185
        }
186

    
187

    
188

    
189
        /**
190
         * @return Returns the GeoRedimBehavior.
191
         */
192
        public GeoRedimBehavior getGeoRedimBehavior() {
193
                return rb;
194
        }
195

    
196
        /**
197
         * @param rb The GeoRedimBehavior to set.
198
         */
199
        public void setGeoRedimBehavior(GeoRedimBehavior rb) {
200
                this.rb = rb;
201
        }
202
        
203
        /**
204
         * @return Returns the GeoMoveBehavior
205
         */
206
        public GeoMoveBehavior getGeoMoveBehavior() {
207
                return mb;
208
        }
209

    
210
        /**
211
         * @param mb The GeoMoveBehavior to set.
212
         */
213
        public void setGeoMoveBehavior(GeoMoveBehavior mb) {
214
                this.mb = mb;
215
        }
216
        
217
        
218
        /* (non-Javadoc)
219
         * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
220
         */
221
        /*public ViewInfo getViewInfo() {
222
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG |
223
                                ViewInfo.RESIZABLE);
224
                m_viewinfo.setWidth(this.getWidth());
225
                m_viewinfo.setHeight(this.getHeight());
226
                m_viewinfo.setTitle(PluginServices.getText(this,
227
                                "cargar_sin_georef"));
228

229
                return m_viewinfo;
230
        }*/
231
        
232
        /**
233
         * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
234
         */
235
        /*public Object getViewModel() {
236
                return "GeoreferencingDialog";
237
        }*/
238
        
239
                
240
        /**
241
         * This method initializes jButton        
242
         *         
243
         * @return javax.swing.JButton        
244
         */    
245
        private JButton getBAceptar() {
246
                if (bAceptar == null) {
247
                        bAceptar = new JButton();
248
                        bAceptar.setText("aceptar");
249
                        bAceptar.addActionListener(this);
250
                }
251
                return bAceptar;
252
        }
253
                
254
        /**
255
         * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
256
         * <UL>
257
         * <LI>Cambiamos el nombre a la capa georraster</LI>
258
         * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
259
         * <LI>Cerramos la ventana</LI>
260
         * </UL>
261
         */
262
        public void actionPerformed(java.awt.event.ActionEvent e) {
263
                if(e.getSource() == bAceptar){
264
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
265
                        FLyrGeoRaster lyrGeoRaster = null;
266
                        FLyrPoints lyrPoints = null;
267
                                
268
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
269
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
270
                                if(        lyr instanceof FLyrGeoRaster && 
271
                                        lyr.getName().startsWith("*") &&
272
                                        lyr.isActive()){
273
                                                                                        
274
                                        //Campbiamos el nombre a la capa GeoRaster
275
                                        lyr.setName(lyr.getName().substring(1, lyr.getName().length()));
276
                                        lyr.setActive(false);
277
                                        lyrGeoRaster = (FLyrGeoRaster)lyr;
278
                                }
279
                                        
280
                                if(        lyr instanceof FLyrPoints)
281
                                        lyrPoints = (FLyrPoints)lyr;
282
                        }
283
                                
284
                        //A la capa Georraster le asignamos la capa de puntos para poder recuperarla
285
                        if(lyrGeoRaster != null)
286
                                lyrGeoRaster.setFLyrPoints(lyrPoints);
287

    
288
                                                                
289
                        theView.getMapControl().setTool("zoomIn");
290
                                
291
                        //Cerramos la ventana
292
                        //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
293
                        try{
294
                                frame.setClosed(true);
295
                        }catch(PropertyVetoException exc){}
296
                }
297
                
298
        }
299
        
300
        /**
301
         * This method initializes bProcesar        
302
         *         
303
         * @return javax.swing.JButton        
304
         */    
305
        private JButton getBProcesar() {
306
                if (bProcesar == null) {
307
                        bProcesar = new JButton();
308
                        bProcesar.setText(PluginServices.getText(this,"procesar"));
309
                        bProcesar.setEnabled(false);
310
                        bProcesar.setPreferredSize(new java.awt.Dimension(87,25));
311
                        bProcesar.addActionListener(new java.awt.event.ActionListener() { 
312
                                public void actionPerformed(java.awt.event.ActionEvent e) {
313
                    /*if (PluginServices.getMainFrame() == null) {
314
                        ((JDialog) (getParent().getParent().getParent()
315
                                .getParent())).dispose();
316
                    } else {
317
                        PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this);
318
                    }*/
319
                                }
320
                        });
321
                }
322
                return bProcesar;
323
        }
324
        
325
        /**
326
         * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
327
         * y cierra la ventana.         
328
         *         
329
         * @return javax.swing.JButton        
330
         */    
331
        private JButton getBCancelar() {
332
                if (bCancelar == null) {
333
                        bCancelar = new JButton();
334
                        bCancelar.setText(PluginServices.getText(this,"cancelar"));
335
                        bCancelar.addActionListener(new java.awt.event.ActionListener() { 
336
                                public void actionPerformed(java.awt.event.ActionEvent e) {                                           
337
                                        //Cerramos la ventana 
338
                                        //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
339
                                        try{
340
                                                frame.setClosed(true);
341
                                        }catch(PropertyVetoException exc){}
342
                                }
343
                        });
344
                }
345
                return bCancelar;
346
        }
347
                
348
        /**
349
         * This method initializes jButton        
350
         *         
351
         * @return javax.swing.JButton        
352
         */
353
        private JButton getBSave() {
354
                if (bSave == null) {
355
                        bSave = new JButton();
356
                        bSave.setText(PluginServices.getText(this,"guardar"));
357
                        bSave.setEnabled(false);
358
                }
359
                return bSave;
360
        }
361

    
362
        /**
363
         * @return Returns the extended.
364
         */
365
        public boolean isEnlarge() {
366
                return enlarge;
367
        }
368

    
369
        /**
370
         * @param extended The extended to set.
371
         */
372
        public void setEnlarge(boolean enlarge) {
373
                this.enlarge = enlarge;
374
                if(!enlarge){
375
                        this.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight));
376
                        this.setSize(new Dimension(this.normalWidth, this.normalHeight));
377
                        frame.setSize(new Dimension(this.normalWidth, this.normalHeight + 10));
378
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight + 10));
379
                        this.getConectorPanel().setCanvasVisible(false);
380
                }else{
381
                        this.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight));
382
                        this.setSize(new Dimension(this.normalWidth, this.enlargeHeight));
383
                        frame.setSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
384
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
385
                        this.getConectorPanel().setCanvasVisible(true);
386
                }
387
                frame.pack();
388
        }
389

    
390
        public SelectPointsPanel getSelectPointsPanel(){
391
                return this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel();
392
        }
393

    
394
   }  //  @jve:decl-index=0:visual-constraint="10,10"
395
 //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
396
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"