Statistics
| Revision:

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

History | View | Annotate | Download (13 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
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.gui;
48

    
49
import java.awt.Color;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import java.awt.geom.Rectangle2D;
53
import java.io.File;
54

    
55
import javax.swing.BorderFactory;
56
import javax.swing.DefaultListModel;
57
import javax.swing.JDialog;
58
import javax.swing.JOptionPane;
59
import javax.swing.JPanel;
60

    
61
import org.cresques.cts.ICoordTrans;
62
import org.cresques.cts.IProjection;
63
import org.cresques.cts.ProjectionPool;
64
import org.cresques.cts.gt2.CoordSys;
65
import org.cresques.cts.gt2.CoordTrans;
66

    
67
import com.hardcode.driverManager.Driver;
68
import com.hardcode.driverManager.DriverLoadException;
69
import com.hardcode.gdbms.engine.data.driver.DBDriver;
70
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
71
import com.iver.andami.PluginServices;
72
import com.iver.andami.messages.NotificationManager;
73
import com.iver.andami.ui.mdiManager.View;
74
import com.iver.andami.ui.mdiManager.ViewInfo;
75
import com.iver.cit.gvsig.AddLayer;
76
import com.iver.cit.gvsig.fmap.DriverException;
77
import com.iver.cit.gvsig.fmap.MapControl;
78
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver;
79
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
80
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
81
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
82
import com.iver.cit.gvsig.fmap.layers.CancelationException;
83
import com.iver.cit.gvsig.fmap.layers.FLayer;
84
import com.iver.cit.gvsig.fmap.layers.FLayers;
85
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
86
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
87
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
88
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
89
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
90
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
91

    
92
/**
93
 * @author FJP
94
 *
95
 * TODO To change the template for this generated type comment go to
96
 * Window - Preferences - Java - Code Generation - Code and Comments
97
 */
98
public class FPanelLocConfig extends JPanel implements ActionListener,View {
99
        private javax.swing.JLabel jLabel = null;
100
        private javax.swing.JList jList = null;
101
        private javax.swing.JButton jBtnUp = null;
102
        private javax.swing.JButton jBtnDown = null;
103
        private javax.swing.JButton jBtnAddLayer = null;  //
104
        private javax.swing.JButton jBtnRemoveLayer = null;
105
        private javax.swing.JButton jBtnEditLegend = null;
106
        private javax.swing.JButton jBtnCancel = null;
107
        
108
        //private JDialog m_Owner;
109
        private MapControl mapCtrl;
110
        private ViewInfo m_viewinfo = null;
111
        /**
112
         * This is the default constructor
113
         */
114
        public FPanelLocConfig( MapControl mc) {
115
                super();
116
                mapCtrl = mc;
117
                initialize();
118
                refreshList();
119
                updateControls(null);
120
        }
121
        
122
        private void refreshList()
123
        {
124
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
125
                lstModel.clear();
126
                for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--)
127
                {
128
                        FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i);
129
                        lstModel.addElement(lyr.getName());
130
                }        
131
        }
132
        
133
        /**
134
         * This method initializes this
135
         * 
136
         * @return void
137
         */
138
        private  void initialize() {
139
                this.setLayout(null);
140
                this.setSize(370, 200);
141
                this.setPreferredSize(new java.awt.Dimension(370,200));
142
                this.add(getJLabel(), null);
143
                this.add(getJList(), null);
144
                this.add(getJBtnUp(), null);
145
                this.add(getJBtnDown(), null);
146
                this.add(getJBtnAddLayer(), null);
147
                this.add(getJBtnRemoveLayer(), null);
148
                this.add(getJBtnEditLegend(), null);
149
                this.add(getJBtnCancel(), null);
150
        }
151
        /**
152

153
         * This method initializes jLabel        
154

155
         *         
156

157
         * @return javax.swing.JLabel        
158

159
         */    
160
        private javax.swing.JLabel getJLabel() {
161
                if (jLabel == null) {
162
                        jLabel = new javax.swing.JLabel();
163
                        jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":");
164
                        jLabel.setBounds(22, 15, 132, 25);
165
                }
166
                return jLabel;
167
        }
168

    
169
        /**
170

171
         * This method initializes jList        
172

173
         *         
174

175
         * @return javax.swing.JList        
176

177
         */    
178
        private javax.swing.JList getJList() {
179
                if (jList == null) {
180
                        jList = new javax.swing.JList(new DefaultListModel());
181
                        jList.setBounds(22, 49, 179, 139);
182
                        jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
183
                        jList.setBorder(BorderFactory.createLineBorder(Color.BLACK));
184
                        jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { 
185

    
186
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {    
187
                                        updateControls(e);
188
                                }
189
                        });
190

    
191
                }
192
                return jList;
193
        }
194
        
195
        private void updateControls(javax.swing.event.ListSelectionEvent e)
196
        {
197
                System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged()
198
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
199
                int selIndex = jList.getSelectedIndex();
200
                jBtnDown.setEnabled(false);
201
                jBtnUp.setEnabled(false);
202
                
203
                if (selIndex != -1)
204
                {
205
                        if (lstModel.getSize() > 1)
206
                        {
207
                                if (selIndex < (lstModel.getSize()-1))
208
                                        jBtnDown.setEnabled(true);
209
                                
210
                                if (selIndex > 0)
211
                                        jBtnUp.setEnabled(true);
212
                        }
213
                        
214
                }
215

    
216
                
217
        }
218

    
219
        /**
220

221
         * This method initializes jBtnUp        
222

223
         *         
224

225
         * @return javax.swing.JButton        
226

227
         */    
228
        private javax.swing.JButton getJBtnUp() {
229
                if (jBtnUp == null) {
230
                        jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
231
                                        javax.swing.SwingConstants.NORTH);
232
                        jBtnUp.setBounds(206, 49, 25, 23);
233
                        jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa"));
234
                        jBtnUp.addActionListener(this);
235
                        jBtnUp.setActionCommand("UP");
236

    
237
                }
238
                return jBtnUp;
239
        }
240

    
241
        /**
242

243
         * This method initializes jBtnDown        
244

245
         *         
246

247
         * @return javax.swing.JButton        
248

249
         */    
250
        private javax.swing.JButton getJBtnDown() {
251
                if (jBtnDown == null) {
252
                        jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
253
                                        javax.swing.SwingConstants.SOUTH);
254
                        jBtnDown.setBounds(206, 164, 25, 23);
255
                        jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa"));
256
                        jBtnDown.setActionCommand("DOWN");
257
                        jBtnDown.addActionListener(this);
258
                }
259
                return jBtnDown;
260
        }
261

    
262
        /**
263

264
         * This method initializes jButton2        
265

266
         *         
267

268
         * @return javax.swing.JButton        
269

270
         */    
271
        private javax.swing.JButton getJBtnAddLayer() {
272
                if (jBtnAddLayer == null) {
273
                        jBtnAddLayer = new javax.swing.JButton();
274
                        jBtnAddLayer.setBounds(251, 49, 109, 23);
275
                        jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"...");
276
                        jBtnAddLayer.addActionListener(this);
277
                        jBtnAddLayer.setActionCommand("ADD_LAYER");
278
                }
279
                return jBtnAddLayer;
280
        }
281

    
282
        /**
283

284
         * This method initializes jBtnRemoveLayer        
285

286
         *         
287

288
         * @return javax.swing.JButton        
289

290
         */    
291
        private javax.swing.JButton getJBtnRemoveLayer() {
292
                if (jBtnRemoveLayer == null) {
293
                        jBtnRemoveLayer = new javax.swing.JButton();
294
                        jBtnRemoveLayer.setBounds(251, 78, 109, 23);
295
                        jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"...");
296
                        jBtnRemoveLayer.addActionListener(this);
297
                        jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
298
                        
299
                }
300
                return jBtnRemoveLayer;
301
        }
302

    
303
        /**
304

305
         * This method initializes jBtnEditLegend        
306

307
         *         
308

309
         * @return javax.swing.JButton        
310

311
         */    
312
        private javax.swing.JButton getJBtnEditLegend() {
313
                if (jBtnEditLegend == null) {
314
                        jBtnEditLegend = new javax.swing.JButton();
315
                        jBtnEditLegend.setBounds(251, 113, 109, 23);
316
                        jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"...");
317
                        jBtnEditLegend.addActionListener(this);
318
                        jBtnEditLegend.setActionCommand("EDIT_LEGEND");
319
                }
320
                return jBtnEditLegend;
321
        }
322

    
323
        /**
324

325
         * This method initializes jBtnCancel        
326

327
         *         
328

329
         * @return javax.swing.JButton        
330

331
         */    
332
        private javax.swing.JButton getJBtnCancel() {
333
                if (jBtnCancel == null) {
334
                        jBtnCancel = new javax.swing.JButton();
335
                        jBtnCancel.setBounds(251, 162, 109, 23);
336
                        jBtnCancel.setText(PluginServices.getText(this,"Cerrar"));
337
                        jBtnCancel.setActionCommand("CANCEL");
338
                        jBtnCancel.addActionListener(this); 
339

    
340
                }
341
                return jBtnCancel;
342
        }
343
        /* (non-Javadoc)
344
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
345
         */
346
        public void actionPerformed(ActionEvent e)
347
        {
348
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
349
                FLayers theLayers = mapCtrl.getMapContext().getLayers();
350
        IProjection proj = null; 
351
                
352
                int numLayers = theLayers.getLayersCount()-1;
353

    
354
                if (e.getActionCommand() == "CANCEL")
355
                {
356
                        if (PluginServices.getMainFrame() != null)
357
                        {
358
                                PluginServices.getMDIManager().closeView(FPanelLocConfig.this);
359
                        }
360
                        else
361
                        {
362
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
363
                        }
364
                }
365
                if (e.getActionCommand() == "ADD_LAYER")
366
                {
367
            AddLayer addLayer = (AddLayer)PluginServices.getExtension( AddLayer.class);//new AddLayer();
368
            //addLayer.initialize();
369
            if (addLayer.addLayers(mapCtrl)) {
370
                    refreshList();
371
                    updateControls(null);
372
            }
373
            
374

    
375
                 }
376
                if (e.getActionCommand() == "REMOVE_LAYER")
377
                {
378
                        if (jList.getSelectedIndex() != -1)
379
                        {
380
                                theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
381
                                lstModel.remove(jList.getSelectedIndex());
382
                                ///mapCtrl.drawMap();
383
                                updateControls(null);
384
                                  if (mapCtrl instanceof MapOverview){
385
                        ((MapOverview)mapCtrl).refreshExtent();
386
                }
387
                        }
388
                }
389
                if (e.getActionCommand() == "EDIT_LEGEND")
390
                {
391
                        int idSelec = jList.getSelectedIndex(); 
392
                        if (idSelec != -1)
393
                        {
394
                                FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
395
                                if (lyr instanceof Classifiable)
396
                                {
397
                                        FThemeManagerWindow m_LegendEditor = new FThemeManagerWindow();
398
                                        try {
399
                                                theLayers.setActive(false);
400
                                                lyr.setActive(true);
401
                                                m_LegendEditor.setMapContext(mapCtrl.getMapContext());
402
                                        } catch (DriverException e1) {
403
                                                // TODO Auto-generated catch block
404
                                                e1.printStackTrace();
405
                                        }
406
                                        if (PluginServices.getMainFrame() == null) {
407
                                                JDialog dlg = new JDialog();
408
                                                                                                            
409
                                                m_LegendEditor.setPreferredSize(m_LegendEditor.getSize());
410
                                                dlg.getContentPane().add(m_LegendEditor);
411
                                                dlg.setModal(true);                        
412
                                                dlg.pack();
413
                                                dlg.show();
414
                                                
415
                                        } else {
416
                                                PluginServices.getMDIManager().addView(m_LegendEditor);
417
                                        }
418
                                }
419
                                else
420
                                {
421
                                        JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo_para_capas_vectoriales")+".");
422
                                }
423

    
424
                        }
425

    
426
                }
427
                if (e.getActionCommand() == "UP")
428
                {
429
                        int idSelec = jList.getSelectedIndex();
430
                    int fromIndex = idSelec;
431
                    int toIndex = idSelec-1;
432
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
433
                        try {
434
                                        theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
435
                                } catch (CancelationException e1) {
436
                                        e1.printStackTrace();
437
                                }
438
                        
439
                        lstModel.remove(fromIndex);
440
                        lstModel.add(toIndex,aux.getName());
441
                        
442
                        jList.setSelectedIndex(toIndex);
443
                        
444
                        ///mapCtrl.drawMap();
445
                }
446
                if (e.getActionCommand() == "DOWN")
447
                {
448
                        int idSelec = jList.getSelectedIndex();
449
                    int fromIndex = idSelec;
450
                    int toIndex = idSelec+1;
451
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
452
                        try {
453
                                theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
454
                                } catch (CancelationException e1) {
455
                                        e1.printStackTrace();
456
                                }
457
                        
458
                        lstModel.remove(fromIndex);
459
                        lstModel.add(toIndex,aux.getName());
460
                        
461
                        jList.setSelectedIndex(toIndex);
462
                        
463
                        ///mapCtrl.drawMap();
464
                }
465
                
466
                
467
        }
468
        /* (non-Javadoc)
469
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
470
         */
471
        public ViewInfo getViewInfo() {
472
                if (m_viewinfo==null){
473
                    m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
474
                        m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador"));
475
                }
476
                        return m_viewinfo;
477
                }
478
        /**
479
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
480
         */
481
        public void viewActivated() {
482
        }
483

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