Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / FPanelLocConfig.java @ 655

History | View | Annotate | Download (14.8 KB)

1
/*
2
 * Created on 18-jun-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
package com.iver.cit.gvsig.gui;
8

    
9
import java.awt.Color;
10
import java.awt.event.ActionEvent;
11
import java.awt.event.ActionListener;
12
import java.io.File;
13

    
14
import javax.swing.BorderFactory;
15
import javax.swing.DefaultListModel;
16
import javax.swing.JDialog;
17
import javax.swing.JOptionPane;
18
import javax.swing.JPanel;
19

    
20
import org.cresques.cts.IProjection;
21
import org.cresques.cts.ProjectionPool;
22

    
23
import com.hardcode.driverManager.DriverLoadException;
24
import com.hardcode.gdbms.engine.data.DBDriver;
25
import com.iver.andami.PluginServices;
26
import com.iver.andami.Utilities;
27
import com.iver.andami.ui.mdiManager.View;
28
import com.iver.andami.ui.mdiManager.ViewInfo;
29
import com.iver.cit.gvsig.fmap.DriverException;
30
import com.iver.cit.gvsig.fmap.NewMapControl;
31
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
32
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver;
33
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
34
import com.iver.cit.gvsig.fmap.layers.CancelationException;
35
import com.iver.cit.gvsig.fmap.layers.FLayer;
36
import com.iver.cit.gvsig.fmap.layers.FLayers;
37
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
38
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
39
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow;
40

    
41
/**
42
 * @author FJP
43
 *
44
 * TODO To change the template for this generated type comment go to
45
 * Window - Preferences - Java - Code Generation - Code and Comments
46
 */
47
public class FPanelLocConfig extends JPanel implements ActionListener,View {
48
        private javax.swing.JLabel jLabel = null;
49
        private javax.swing.JList jList = null;
50
        private javax.swing.JButton jBtnUp = null;
51
        private javax.swing.JButton jBtnDown = null;
52
        private javax.swing.JButton jBtnAddLayer = null;  //
53
        private javax.swing.JButton jBtnRemoveLayer = null;
54
        private javax.swing.JButton jBtnEditLegend = null;
55
        private javax.swing.JButton jBtnCancel = null;
56
        
57
        //private JDialog m_Owner;
58
        private NewMapControl mapCtrl;
59
        private FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow();
60
        private ViewInfo m_viewinfo = null;
61
        /**
62
         * This is the default constructor
63
         */
64
        public FPanelLocConfig( NewMapControl mc) {
65
                super();
66
                mapCtrl = mc;
67
                initialize();
68
                refreshList();
69
                updateControls(null);
70
        }
71
        
72
        private void refreshList()
73
        {
74
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
75
                lstModel.clear();
76
                for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--)
77
                {
78
                        FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i);
79
                        lstModel.addElement(lyr.getName());
80
                }        
81
        }
82
        
83
        /**
84
         * This method initializes this
85
         * 
86
         * @return void
87
         */
88
        private  void initialize() {
89
                this.setLayout(null);
90
                this.setSize(370, 200);
91
                this.setPreferredSize(new java.awt.Dimension(370,200));
92
                this.add(getJLabel(), null);
93
                this.add(getJList(), null);
94
                this.add(getJBtnUp(), null);
95
                this.add(getJBtnDown(), null);
96
                this.add(getJBtnAddLayer(), null);
97
                this.add(getJBtnRemoveLayer(), null);
98
                this.add(getJBtnEditLegend(), null);
99
                this.add(getJBtnCancel(), null);
100
        }
101
        /**
102

103
         * This method initializes jLabel        
104

105
         *         
106

107
         * @return javax.swing.JLabel        
108

109
         */    
110
        private javax.swing.JLabel getJLabel() {
111
                if (jLabel == null) {
112
                        jLabel = new javax.swing.JLabel();
113
                        jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":");
114
                        jLabel.setBounds(22, 15, 132, 25);
115
                }
116
                return jLabel;
117
        }
118

    
119
        /**
120

121
         * This method initializes jList        
122

123
         *         
124

125
         * @return javax.swing.JList        
126

127
         */    
128
        private javax.swing.JList getJList() {
129
                if (jList == null) {
130
                        jList = new javax.swing.JList(new DefaultListModel());
131
                        jList.setBounds(22, 49, 179, 139);
132
                        jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
133
                        jList.setBorder(BorderFactory.createLineBorder(Color.BLACK));
134
                        jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { 
135

    
136
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {    
137
                                        updateControls(e);
138
                                }
139
                        });
140

    
141
                }
142
                return jList;
143
        }
144
        
145
        private void updateControls(javax.swing.event.ListSelectionEvent e)
146
        {
147
                System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged()
148
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
149
                int selIndex = jList.getSelectedIndex();
150
                jBtnDown.setEnabled(false);
151
                jBtnUp.setEnabled(false);
152
                
153
                if (selIndex != -1)
154
                {
155
                        if (lstModel.getSize() > 1)
156
                        {
157
                                if (selIndex < (lstModel.getSize()-1))
158
                                        jBtnDown.setEnabled(true);
159
                                
160
                                if (selIndex > 0)
161
                                        jBtnUp.setEnabled(true);
162
                        }
163
                        
164
                }
165

    
166
                
167
        }
168

    
169
        /**
170

171
         * This method initializes jBtnUp        
172

173
         *         
174

175
         * @return javax.swing.JButton        
176

177
         */    
178
        private javax.swing.JButton getJBtnUp() {
179
                if (jBtnUp == null) {
180
                        jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
181
                                        javax.swing.SwingConstants.NORTH);
182
                        jBtnUp.setBounds(206, 49, 25, 23);
183
                        jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa"));
184
                        jBtnUp.addActionListener(this);
185
                        jBtnUp.setActionCommand("UP");
186

    
187
                }
188
                return jBtnUp;
189
        }
190

    
191
        /**
192

193
         * This method initializes jBtnDown        
194

195
         *         
196

197
         * @return javax.swing.JButton        
198

199
         */    
200
        private javax.swing.JButton getJBtnDown() {
201
                if (jBtnDown == null) {
202
                        jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
203
                                        javax.swing.SwingConstants.SOUTH);
204
                        jBtnDown.setBounds(206, 164, 25, 23);
205
                        jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa"));
206
                        jBtnDown.setActionCommand("DOWN");
207
                        jBtnDown.addActionListener(this);
208
                }
209
                return jBtnDown;
210
        }
211

    
212
        /**
213

214
         * This method initializes jButton2        
215

216
         *         
217

218
         * @return javax.swing.JButton        
219

220
         */    
221
        private javax.swing.JButton getJBtnAddLayer() {
222
                if (jBtnAddLayer == null) {
223
                        jBtnAddLayer = new javax.swing.JButton();
224
                        jBtnAddLayer.setBounds(251, 49, 109, 23);
225
                        jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"...");
226
                        jBtnAddLayer.addActionListener(this);
227
                        jBtnAddLayer.setActionCommand("ADD_LAYER");
228
                }
229
                return jBtnAddLayer;
230
        }
231

    
232
        /**
233

234
         * This method initializes jBtnRemoveLayer        
235

236
         *         
237

238
         * @return javax.swing.JButton        
239

240
         */    
241
        private javax.swing.JButton getJBtnRemoveLayer() {
242
                if (jBtnRemoveLayer == null) {
243
                        jBtnRemoveLayer = new javax.swing.JButton();
244
                        jBtnRemoveLayer.setBounds(251, 78, 109, 23);
245
                        jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"...");
246
                        jBtnRemoveLayer.addActionListener(this);
247
                        jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
248
                        
249
                }
250
                return jBtnRemoveLayer;
251
        }
252

    
253
        /**
254

255
         * This method initializes jBtnEditLegend        
256

257
         *         
258

259
         * @return javax.swing.JButton        
260

261
         */    
262
        private javax.swing.JButton getJBtnEditLegend() {
263
                if (jBtnEditLegend == null) {
264
                        jBtnEditLegend = new javax.swing.JButton();
265
                        jBtnEditLegend.setBounds(251, 113, 109, 23);
266
                        jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"...");
267
                        jBtnEditLegend.addActionListener(this);
268
                        jBtnEditLegend.setActionCommand("EDIT_LEGEND");
269
                }
270
                return jBtnEditLegend;
271
        }
272

    
273
        /**
274

275
         * This method initializes jBtnCancel        
276

277
         *         
278

279
         * @return javax.swing.JButton        
280

281
         */    
282
        private javax.swing.JButton getJBtnCancel() {
283
                if (jBtnCancel == null) {
284
                        jBtnCancel = new javax.swing.JButton();
285
                        jBtnCancel.setBounds(251, 162, 109, 23);
286
                        jBtnCancel.setText(PluginServices.getText(this,"Cerrar"));
287
                        jBtnCancel.setActionCommand("CANCEL");
288
                        jBtnCancel.addActionListener(this); 
289

    
290
                }
291
                return jBtnCancel;
292
        }
293
        /* (non-Javadoc)
294
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
295
         */
296
        public void actionPerformed(ActionEvent e)
297
        {
298
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
299
                FLayers theLayers = mapCtrl.getMapContext().getLayers();
300
                // TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
301
                IProjection proj = ProjectionPool.get("ed50utm30");
302
                
303
                int numLayers = theLayers.getLayersCount()-1;
304

    
305
                if (e.getActionCommand() == "CANCEL")
306
                {
307
                        if (PluginServices.getMainFrame() != null)
308
                        {
309
                                PluginServices.getMDIManager().closeView(FPanelLocConfig.this);
310
                        }
311
                        else
312
                        {
313
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
314
                        }
315
                }
316
                if (e.getActionCommand() == "ADD_LAYER")
317
                {
318
            FOpenDialog fopen = new FOpenDialog();            
319
            if (PluginServices.getMainFrame() != null)
320
            {
321
                FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class, GeorreferencedRasterDriver.class});
322
                DataBaseOpenDialog dbop = new DataBaseOpenDialog();
323
                dbop.setClasses(new Class[] { DBDriver.class });
324
                fopen.addTab("Fichero", fileDlg);
325
                fopen.addTab("Base de datos", dbop);
326
                PluginServices.getMDIManager().addView(fopen);
327

    
328
                if (fopen.isAccepted()) {
329
                    // TODO: Hacer lo de la capa WMS tambi?n.
330
                    if (fileDlg.getFiles() == null) {
331
                        return;
332
                    }
333

    
334
                    FLayer lyr = null;
335
                    File[] files = fileDlg.getFiles();
336

    
337
                    for (int iFile = 0; iFile < files.length; iFile++) {
338
                        File fich = files[iFile];
339
                        String layerName = fich.getName();
340
                        String layerPath = fich.getAbsolutePath();
341

    
342
                        try {
343
                            lyr = LayerFactory.createLayer(layerName, fileDlg.getDriverName(),
344
                                    fich, proj);
345

    
346
                            if (lyr != null) {
347
                                try {
348

    
349
                                    lyr.setVisible(true);
350
                                    mapCtrl.getMapContext().getLayers()
351
                                           .addLayer(lyr);
352
                                } catch (CancelationException ex) {
353
                                    // TODO Auto-generated catch block
354
                                    ex.printStackTrace();
355
                                }
356

    
357
                            }
358
                        } catch (DriverException ex) {
359
                        }
360
                    } // for
361
                }
362
                    
363
            }
364
            else
365
            {
366
                    JDialog dlg = new JDialog();
367
                dlg.setModal(true);
368
                FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class});
369
                DataBaseOpenDialog dbop = new DataBaseOpenDialog();
370
                dbop.setClasses(new Class[]{DBDriver.class});
371
                
372
                fopen = new FOpenDialog();
373
                fopen.addTab("Fichero", fileDlg);
374
                fopen.addTab("Base de datos", dbop);
375
                // fileDlg.setPreferredSize(fopen.getSize());
376
                dlg.setSize(fopen.getSize());
377
                dlg.getContentPane().add(fopen);
378
                dlg.pack();
379
                dlg.show();
380
                
381
      
382
                // TODO: Hacer lo de la capa WMS tambi?n.
383
                        if (fileDlg.getFiles() == null) return;
384
                        FLayer lyr = null;
385
                        File[] files = fileDlg.getFiles();
386
                        for  (int iFile=0; iFile < files.length; iFile++)
387
                        {
388
                                File fich = files[iFile];
389
                                String layerName = fich.getName();
390
                                String layerPath = fich.getAbsolutePath();
391
                                
392
                                try {
393
                                        lyr = LayerFactory.createLayer(layerName, fileDlg.getDriverName(), fich, proj);
394

    
395
                                        lyr.setVisible(true);
396
                                        lyr.setName(layerName);
397
                                        if (lyr != null )
398
                                        {
399
                                                try {
400
                                                        mapCtrl.getMapContext().getLayers().addLayer(lyr);
401
                                                } catch (CancelationException ex) {
402
                                                        // TODO Auto-generated catch block
403
                                                        ex.printStackTrace();
404
                                                }
405
                                        }                    
406
                                        
407
                                } catch (DriverException ex) {
408
                                        ex.printStackTrace();
409
                                    }
410
                        } // for
411
           //  lstModel.addElement(lyr.getName());
412
            }
413
            refreshList();
414
            updateControls(null);
415
            mapCtrl.getMapContext().fireInvalidEvent();
416
                    
417
                 }
418
                if (e.getActionCommand() == "REMOVE_LAYER")
419
                {
420
                        if (jList.getSelectedIndex() != -1)
421
                        {
422
                                theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
423
                                lstModel.remove(jList.getSelectedIndex());
424
                                mapCtrl.drawMap();
425
                                updateControls(null);
426
                        }
427
                }
428
                if (e.getActionCommand() == "EDIT_LEGEND")
429
                {
430
                        int idSelec = jList.getSelectedIndex(); 
431
                        if (idSelec != -1)
432
                        {
433
                                FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
434
                                if (lyr instanceof Classifiable)
435
                                {
436
                                        try {
437
                                                theLayers.setActive(false);
438
                                                lyr.setActive(true);
439
                                                m_LegendEditor.setMapContext(mapCtrl.getMapContext());
440
                                        } catch (DriverException e1) {
441
                                                // TODO Auto-generated catch block
442
                                                e1.printStackTrace();
443
                                        }
444
                                        if (PluginServices.getMainFrame() == null) {
445
                                                JDialog dlg = new JDialog();
446
                                                                                                            
447
                                                m_LegendEditor.setPreferredSize(m_LegendEditor.getSize());
448
                                                dlg.getContentPane().add(m_LegendEditor);
449
                                                dlg.setModal(true);                        
450
                                                dlg.pack();
451
                                                dlg.show();
452
                                                
453
                                        } else
454
                                                PluginServices.getMDIManager().addView(m_LegendEditor);                                        
455
                                }
456
                                else
457
                                {
458
                                        JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo para capas vectoriales")+".");
459
                                }
460

    
461
                        }
462

    
463
                }
464
                if (e.getActionCommand() == "UP")
465
                {
466
                        int idSelec = jList.getSelectedIndex();
467
                    int fromIndex = idSelec;
468
                    int toIndex = idSelec-1;
469
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
470
                        try {
471
                                        theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
472
                                } catch (CancelationException e1) {
473
                                        e1.printStackTrace();
474
                                }
475
                        
476
                        lstModel.remove(fromIndex);
477
                        lstModel.add(toIndex,aux.getName());
478
                        
479
                        jList.setSelectedIndex(toIndex);
480
                        
481
                        mapCtrl.drawMap();
482
                }
483
                if (e.getActionCommand() == "DOWN")
484
                {
485
                        int idSelec = jList.getSelectedIndex();
486
                    int fromIndex = idSelec;
487
                    int toIndex = idSelec+1;
488
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
489
                        try {
490
                                theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
491
                                } catch (CancelationException e1) {
492
                                        e1.printStackTrace();
493
                                }
494
                        
495
                        lstModel.remove(fromIndex);
496
                        lstModel.add(toIndex,aux.getName());
497
                        
498
                        jList.setSelectedIndex(toIndex);
499
                        
500
                        mapCtrl.drawMap();
501
                }
502
                
503
                
504
        }
505
        /* (non-Javadoc)
506
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
507
         */
508
        public ViewInfo getViewInfo() {
509
                if (m_viewinfo==null){
510
                    m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
511
                        m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador"));
512
                }
513
                        return m_viewinfo;
514
                }
515
        /**
516
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
517
         */
518
        public void viewActivated() {
519
        }
520

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