Statistics
| Revision:

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

History | View | Annotate | Download (13.5 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.awt.event.ComponentEvent;
8
import java.awt.event.ComponentListener;
9
import java.beans.PropertyVetoException;
10

    
11
import javax.swing.JButton;
12
import javax.swing.JFileChooser;
13
import javax.swing.JInternalFrame;
14
import javax.swing.JPanel;
15

    
16
import org.cresques.cts.IProjection;
17

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

    
39
/**
40
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
41
 * interiores
42
 *
43
 * @author Nacho Brodin (brodin_ign@gva.es)
44
 */
45
public class GeoreferencingDialog extends JPanel implements ActionListener, ComponentListener {
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 = 395;
62
        private int normalHeight = 250;
63
        private int enlargeHeight = 417;
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
            frame.addComponentListener(this);
74
            initialize();
75
    }
76

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

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

    
176
                /**
177
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
178
                 */
179
                public void error(Exception e) {
180
                }
181

    
182
                /**
183
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
184
                 */
185
                public void wizardStateChanged(boolean finishable) {
186
                        getBProcesar().setEnabled(finishable);
187
                }
188
                
189
        }
190
        public static IProjection getLastProjection() {
191
                return proj;
192
        }
193
        public static void setLastProjection(IProjection proj) {
194
                GeoreferencingDialog.proj = proj;
195
        }
196

    
197

    
198

    
199
        /**
200
         * @return Returns the GeoRedimBehavior.
201
         */
202
        public GeoRedimBehavior getGeoRedimBehavior() {
203
                return rb;
204
        }
205

    
206
        /**
207
         * @param rb The GeoRedimBehavior to set.
208
         */
209
        public void setGeoRedimBehavior(GeoRedimBehavior rb) {
210
                this.rb = rb;
211
        }
212
        
213
        /**
214
         * @return Returns the GeoMoveBehavior
215
         */
216
        public GeoMoveBehavior getGeoMoveBehavior() {
217
                return mb;
218
        }
219

    
220
        /**
221
         * @param mb The GeoMoveBehavior to set.
222
         */
223
        public void setGeoMoveBehavior(GeoMoveBehavior mb) {
224
                this.mb = mb;
225
        }
226
        
227
        
228
        /* (non-Javadoc)
229
         * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
230
         */
231
        /*public ViewInfo getViewInfo() {
232
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG |
233
                                ViewInfo.RESIZABLE);
234
                m_viewinfo.setWidth(this.getWidth());
235
                m_viewinfo.setHeight(this.getHeight());
236
                m_viewinfo.setTitle(PluginServices.getText(this,
237
                                "cargar_sin_georef"));
238

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

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

    
372
        /**
373
         * @return Returns the extended.
374
         */
375
        public boolean isEnlarge() {
376
                return enlarge;
377
        }
378

    
379
        /**
380
         * @param extended The extended to set.
381
         */
382
        public void setEnlarge(boolean enlarge) {
383
                this.enlarge = enlarge;
384
                if(!enlarge){
385
                        this.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight));
386
                        this.setSize(new Dimension(this.normalWidth, this.normalHeight));
387
                        frame.setSize(new Dimension(this.normalWidth, this.normalHeight + 10));
388
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight + 10));
389
                        this.getConectorPanel().setCanvasVisible(false);
390
                }else{
391
                        this.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight));
392
                        this.setSize(new Dimension(this.normalWidth, this.enlargeHeight));
393
                        frame.setSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
394
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
395
                        this.getConectorPanel().setCanvasVisible(true);
396
                }
397
                frame.pack();
398
        }
399

    
400
        public SelectPointsPanel getSelectPointsPanel(){
401
                return this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel();
402
        }
403
        
404

    
405
        /* (non-Javadoc)
406
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
407
         */
408
        public void componentHidden(ComponentEvent arg0) {
409
                // TODO Auto-generated method stub
410

    
411
        }
412
        /* (non-Javadoc)
413
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
414
         */
415
        public void componentMoved(ComponentEvent arg0) {
416
                // TODO Auto-generated method stub
417

    
418
        }
419
        /* (non-Javadoc)
420
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
421
         */
422
        public void componentResized(ComponentEvent ev) {
423
                //this.newFrameSize(frame.getWidth(), frame.getHeight());
424

    
425
        }
426
        /* (non-Javadoc)
427
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
428
         */
429
        public void componentShown(ComponentEvent arg0) {
430
                // TODO Auto-generated method stub
431

    
432
        }
433
        
434
        /**
435
         * Calculo del nuevo tama?o a partir de un frame redimensionado
436
         * @param w Ancho del frame
437
         * @param h Alto del frame
438
         */
439
        public void newFrameSize(int w, int h){
440
                int initWFrame = 385;
441
                int initW = 395;
442
                
443
                normalWidth = (int)((initW * w)/initWFrame);
444
                //System.out.println(normalWidth+" "+normalHeight);
445
                
446
                this.resize(new java.awt.Dimension(normalWidth, normalHeight));
447
                
448
        this.getConectorPanel().newFrameSize(w, h);
449
        
450
        }
451

    
452
}  //  @jve:decl-index=0:visual-constraint="10,10"
453
 //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
454
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"