Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / gui / FPanelLocConfig.java @ 7979

History | View | Annotate | Download (12.2 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.project.documents.view.gui;
48

    
49
import java.awt.Color;
50
import java.awt.FlowLayout;
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53

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

    
61
import org.gvsig.gui.beans.swing.JButton;
62

    
63
import com.iver.andami.PluginServices;
64
import com.iver.andami.ui.mdiManager.IWindow;
65
import com.iver.andami.ui.mdiManager.WindowInfo;
66
import com.iver.cit.gvsig.AddLayer;
67
import com.iver.cit.gvsig.fmap.DriverException;
68
import com.iver.cit.gvsig.fmap.MapControl;
69
import com.iver.cit.gvsig.fmap.layers.CancelationException;
70
import com.iver.cit.gvsig.fmap.layers.FLayer;
71
import com.iver.cit.gvsig.fmap.layers.FLayers;
72
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
73
import com.iver.cit.gvsig.project.documents.view.MapOverview;
74
import com.iver.cit.gvsig.project.documents.view.legend.gui.FThemeManagerWindow;
75

    
76
/**
77
 * @author FJP
78
 *
79
 * TODO To change the template for this generated type comment go to
80
 * Window - Preferences - Java - Code Generation - Code and Comments
81
 */
82
public class FPanelLocConfig extends JPanel implements ActionListener,IWindow {
83
        private javax.swing.JLabel jLabel = null;
84
        private javax.swing.JList jList = null;  //  @jve:decl-index=0:visual-constraint="390,10"
85
        private JButton jBtnAddLayer = null;  //
86
        private JButton jBtnRemoveLayer = null;
87
        private JButton jBtnEditLegend = null;
88
        private JButton jBtnCancel = null;
89

    
90
        //private JDialog m_Owner;
91
        private MapControl mapCtrl;
92
        private WindowInfo m_viewinfo = null;
93
        private JPanel pnlButtons = null;  //  @jve:decl-index=0:visual-constraint="10,159"
94
        private BasicArrowButton jBtnUp;
95
        private BasicArrowButton jBtnDown;
96
        /**
97
         * This is the default constructor
98
         */
99
        public FPanelLocConfig( MapControl mc) {
100
                super();
101
                mapCtrl = mc;
102
                initialize();
103
                refreshList();
104
                updateControls(null);
105
        }
106

    
107
        private void refreshList()
108
        {
109
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
110
                lstModel.clear();
111
                for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--)
112
                {
113
                        FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i);
114
                        lstModel.addElement(lyr.getName());
115
                }
116
        }
117

    
118
        /**
119
         * This method initializes this
120
         *
121
         * @return void
122
         */
123
        private  void initialize() {
124
                this.setLayout(null);
125
                this.setSize(550, 200);
126
//                this.setPreferredSize(new java.awt.Dimension(370,200));
127
                this.add(getJLabel(), null);
128
                this.add(getJList(), null);
129
                this.add(getJBtnUp(), null);
130
                this.add(getJBtnDown(), null);
131
                this.add(getJPanel(), null);
132
        }
133
        /**
134

135
         * This method initializes jLabel
136

137
         *
138

139
         * @return javax.swing.JLabel
140

141
         */
142
        private javax.swing.JLabel getJLabel() {
143
                if (jLabel == null) {
144
                        jLabel = new javax.swing.JLabel();
145
                        jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":");
146
                        jLabel.setBounds(10, 15, 132, 25);
147
                }
148
                return jLabel;
149
        }
150

    
151
        /**
152

153
         * This method initializes jList
154

155
         *
156

157
         * @return javax.swing.JList
158

159
         */
160
        private javax.swing.JList getJList() {
161
                if (jList == null) {
162
                        jList = new javax.swing.JList(new DefaultListModel());
163
                        jList.setBounds(10, 49, 357, 139);
164
                        jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
165
                        jList.setBorder(BorderFactory.createLineBorder(Color.BLACK));
166
                        jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
167

    
168
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
169
                                        updateControls(e);
170
                                }
171
                        });
172

    
173
                }
174
                return jList;
175
        }
176

    
177
        private void updateControls(javax.swing.event.ListSelectionEvent e)
178
        {
179
                System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged()
180
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
181
                int selIndex = jList.getSelectedIndex();
182
                jBtnDown.setEnabled(false);
183
                jBtnUp.setEnabled(false);
184

    
185
                if (selIndex != -1)
186
                {
187
                        if (lstModel.getSize() > 1)
188
                        {
189
                                if (selIndex < (lstModel.getSize()-1))
190
                                        jBtnDown.setEnabled(true);
191

    
192
                                if (selIndex > 0)
193
                                        jBtnUp.setEnabled(true);
194
                        }
195

    
196
                }
197

    
198

    
199
        }
200

    
201
        /**
202

203
         * This method initializes jBtnUp
204

205
         *
206

207
         * @return JButton
208

209
         */
210
        private BasicArrowButton getJBtnUp() {
211
                if (jBtnUp == null) {
212
                        jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
213
                                        javax.swing.SwingConstants.NORTH);
214
                        jBtnUp.setBounds(374, 49, 25, 23);
215
                        jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa"));
216
                        jBtnUp.addActionListener(this);
217
                        jBtnUp.setActionCommand("UP");
218

    
219
                }
220
                return jBtnUp;
221
        }
222

    
223
        /**
224

225
         * This method initializes jBtnDown
226

227
         *
228

229
         * @return JButton
230

231
         */
232
        private BasicArrowButton getJBtnDown() {
233
                if (jBtnDown == null) {
234
                        jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
235
                                        javax.swing.SwingConstants.SOUTH);
236
                        jBtnDown.setBounds(374, 164, 25, 23);
237
                        jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa"));
238
                        jBtnDown.setActionCommand("DOWN");
239
                        jBtnDown.addActionListener(this);
240
                }
241
                return jBtnDown;
242
        }
243

    
244
        /**
245

246
         * This method initializes jButton2
247

248
         *
249

250
         * @return JButton
251

252
         */
253
        private JButton getJBtnAddLayer() {
254
                if (jBtnAddLayer == null) {
255
                        jBtnAddLayer = new JButton();
256
                        jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"...");
257
                        jBtnAddLayer.addActionListener(this);
258
                        jBtnAddLayer.setActionCommand("ADD_LAYER");
259
                }
260
                return jBtnAddLayer;
261
        }
262

    
263
        /**
264

265
         * This method initializes jBtnRemoveLayer
266

267
         *
268

269
         * @return JButton
270

271
         */
272
        private JButton getJBtnRemoveLayer() {
273
                if (jBtnRemoveLayer == null) {
274
                        jBtnRemoveLayer = new JButton();
275
                        jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"...");
276
                        jBtnRemoveLayer.addActionListener(this);
277
                        jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
278

    
279
                }
280
                return jBtnRemoveLayer;
281
        }
282

    
283
        /**
284

285
         * This method initializes jBtnEditLegend
286

287
         *
288

289
         * @return JButton
290

291
         */
292
        private JButton getJBtnEditLegend() {
293
                if (jBtnEditLegend == null) {
294
                        jBtnEditLegend = new JButton();
295
                        jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"...");
296
                        jBtnEditLegend.addActionListener(this);
297
                        jBtnEditLegend.setActionCommand("EDIT_LEGEND");
298
                }
299
                return jBtnEditLegend;
300
        }
301

    
302
        /**
303

304
         * This method initializes jBtnCancel
305

306
         *
307

308
         * @return JButton
309

310
         */
311
        private JButton getJBtnCancel() {
312
                if (jBtnCancel == null) {
313
                        jBtnCancel = new JButton();
314
                        jBtnCancel.setText(PluginServices.getText(this,"Cerrar"));
315
                        jBtnCancel.setActionCommand("CANCEL");
316
                        jBtnCancel.addActionListener(this);
317

    
318
                }
319
                return jBtnCancel;
320
        }
321

    
322
        /* (non-Javadoc)
323
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
324
         */
325
        public void actionPerformed(ActionEvent e)
326
        {
327
                DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
328
                FLayers theLayers = mapCtrl.getMapContext().getLayers();
329
       // IProjection proj = null;
330

    
331
                int numLayers = theLayers.getLayersCount()-1;
332

    
333
                if (e.getActionCommand() == "CANCEL")
334
                {
335
                        if (PluginServices.getMainFrame() != null)
336
                        {
337
                                PluginServices.getMDIManager().closeWindow(FPanelLocConfig.this);
338
                        }
339
                        else
340
                        {
341
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
342
                        }
343
                }
344
                if (e.getActionCommand() == "ADD_LAYER")
345
                {
346
            AddLayer addLayer = (AddLayer)PluginServices.getExtension( AddLayer.class);//new AddLayer();
347
            //addLayer.initialize();
348
            if (addLayer.addLayers(mapCtrl)) {
349
                    refreshList();
350
                    updateControls(null);
351
            }
352

    
353

    
354
                 }
355
                if (e.getActionCommand() == "REMOVE_LAYER")
356
                {
357
                        if (jList.getSelectedIndex() != -1)
358
                        {
359
                                theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
360
                                lstModel.remove(jList.getSelectedIndex());
361
                                ///mapCtrl.drawMap();
362
                                updateControls(null);
363
                                  if (mapCtrl instanceof MapOverview){
364
                        ((MapOverview)mapCtrl).refreshExtent();
365
                }
366
                        }
367
                }
368
                if (e.getActionCommand() == "EDIT_LEGEND")
369
                {
370
                        int idSelec = jList.getSelectedIndex();
371
                        if (idSelec != -1)
372
                        {
373
                                FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
374
                                if (lyr instanceof Classifiable)
375
                                {
376
                                        FThemeManagerWindow m_LegendEditor = new FThemeManagerWindow();
377
                                        try {
378
                                                theLayers.setActive(false);
379
                                                lyr.setActive(true);
380
                                                m_LegendEditor.setMapContext(mapCtrl.getMapContext());
381
                                        } catch (DriverException e1) {
382
                                                // TODO Auto-generated catch block
383
                                                e1.printStackTrace();
384
                                        }
385
                                        if (PluginServices.getMainFrame() == null) {
386
                                                JDialog dlg = new JDialog();
387

    
388
                                                m_LegendEditor.setPreferredSize(m_LegendEditor.getSize());
389
                                                dlg.getContentPane().add(m_LegendEditor);
390
                                                dlg.setModal(true);
391
                                                dlg.pack();
392
                                                dlg.show();
393

    
394
                                        } else {
395
                                                PluginServices.getMDIManager().addWindow(m_LegendEditor);
396
                                        }
397
                                }
398
                                else
399
                                {
400
                                        JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo_para_capas_vectoriales")+".");
401
                                }
402

    
403
                        }
404

    
405
                }
406
                if (e.getActionCommand() == "UP")
407
                {
408
                        int idSelec = jList.getSelectedIndex();
409
                    int fromIndex = idSelec;
410
                    int toIndex = idSelec-1;
411
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
412
                        try {
413
                                        theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
414
                                } catch (CancelationException e1) {
415
                                        e1.printStackTrace();
416
                                }
417

    
418
                        lstModel.remove(fromIndex);
419
                        lstModel.add(toIndex,aux.getName());
420

    
421
                        jList.setSelectedIndex(toIndex);
422

    
423
                        ///mapCtrl.drawMap();
424
                }
425
                if (e.getActionCommand() == "DOWN")
426
                {
427
                        int idSelec = jList.getSelectedIndex();
428
                    int fromIndex = idSelec;
429
                    int toIndex = idSelec+1;
430
                        FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
431
                        try {
432
                                theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex);
433
                                } catch (CancelationException e1) {
434
                                        e1.printStackTrace();
435
                                }
436

    
437
                        lstModel.remove(fromIndex);
438
                        lstModel.add(toIndex,aux.getName());
439

    
440
                        jList.setSelectedIndex(toIndex);
441

    
442
                        ///mapCtrl.drawMap();
443
                }
444

    
445

    
446
        }
447
        /* (non-Javadoc)
448
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
449
         */
450
        public WindowInfo getWindowInfo() {
451
                if (m_viewinfo==null){
452
                    m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
453
                        m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador"));
454
                        m_viewinfo.setWidth(this.getWidth()+8);
455
                        m_viewinfo.setHeight(this.getHeight()+8);
456
                }
457
                        return m_viewinfo;
458
                }
459
        /**
460
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
461
         */
462
        public void viewActivated() {
463
        }
464

    
465
        /**
466
         * This method initializes jPanel
467
         *
468
         * @return javax.swing.JPanel
469
         */
470
        private JPanel getJPanel() {
471
                if (pnlButtons == null) {
472
                        pnlButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
473
                        pnlButtons.setBounds(new java.awt.Rectangle(0,200, this.getWidth(),37));
474
                        pnlButtons.add(getJBtnAddLayer(), null);
475
                        pnlButtons.add(getJBtnRemoveLayer(), null);
476
                        pnlButtons.add(getJBtnEditLegend(), null);
477
                        pnlButtons.add(getJBtnCancel(), null);
478
                }
479
                return pnlButtons;
480
        }
481

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