Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / gui / FPanelLocConfig.java @ 40558

History | View | Annotate | Download (14.3 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.view.gui;
25

    
26
import java.awt.Color;
27
import java.awt.FlowLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30

    
31
import javax.swing.BorderFactory;
32
import javax.swing.DefaultListModel;
33
import javax.swing.JButton;
34
import javax.swing.JDialog;
35
import javax.swing.JOptionPane;
36
import javax.swing.JPanel;
37
import javax.swing.plaf.basic.BasicArrowButton;
38

    
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.ui.mdiManager.IWindow;
41
import org.gvsig.andami.ui.mdiManager.WindowInfo;
42
import org.gvsig.app.extension.AddLayer;
43
import org.gvsig.app.project.documents.view.MapOverview;
44
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow;
45
import org.gvsig.fmap.mapcontext.layers.CancelationException;
46
import org.gvsig.fmap.mapcontext.layers.FLayer;
47
import org.gvsig.fmap.mapcontext.layers.FLayers;
48
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable;
49
import org.gvsig.fmap.mapcontrol.MapControl;
50
import org.gvsig.tools.swing.api.ToolsSwingLocator;
51

    
52
/**
53
 * @author FJP
54
 * 
55
 *         TODO To change the template for this generated type comment go to
56
 *         Window - Preferences - Java - Code Generation - Code and Comments
57
 */
58
public class FPanelLocConfig extends JPanel implements ActionListener, IWindow {
59

    
60
    private static final long serialVersionUID = -3331364698732098356L;
61
    private javax.swing.JLabel jLabel = null;
62
    private javax.swing.JList jList = null; // @jve:decl-index=0:visual-constraint="390,10"
63
    private JButton jBtnAddLayer = null; //
64
    private JButton jBtnRemoveLayer = null;
65
    private JButton jBtnEditLegend = null;
66
    private JButton jBtnCancel = null;
67

    
68
    private MapControl mapCtrl;
69
    private WindowInfo m_viewinfo = null;
70
    private JPanel pnlButtons = null; // @jve:decl-index=0:visual-constraint="10,159"
71
    private BasicArrowButton jBtnUp;
72
    private BasicArrowButton jBtnDown;
73

    
74
    /**
75
     * This is the default constructor
76
     */
77
    public FPanelLocConfig(MapControl mc) {
78
        super();
79
        mapCtrl = mc;
80
        initialize();
81
        refreshList();
82
        updateControls(null);
83
    }
84

    
85
    private void refreshList() {
86
        DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
87
        lstModel.clear();
88
        for (int i = mapCtrl.getMapContext().getLayers().getLayersCount() - 1; i >= 0; i--) {
89
            FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i);
90
            lstModel.addElement(lyr.getName());
91
        }
92
    }
93

    
94
    /**
95
     * This method initializes this
96
     * 
97
     * @return void
98
     */
99
    private void initialize() {
100
        this.setLayout(null);
101
        this.setSize(550, 200);
102
        this.add(getJLabel(), null);
103
        this.add(getJList(), null);
104
        this.add(getJBtnUp(), null);
105
        this.add(getJBtnDown(), null);
106
        this.add(getJPanel(), null);
107
    }
108

    
109
    /**
110
     * This method initializes jLabel
111
     * 
112
     * @return javax.swing.JLabel
113
     */
114
    private javax.swing.JLabel getJLabel() {
115
        if (jLabel == null) {
116
            jLabel = new javax.swing.JLabel();
117
            jLabel.setText(PluginServices
118
                .getText(this, "Capas_del_localizador") + ":");
119
            jLabel.setBounds(10, 15, 132, 25);
120
        }
121
        return jLabel;
122
    }
123

    
124
    /**
125
     * This method initializes jList
126
     * 
127
     * @return javax.swing.JList
128
     */
129
    public javax.swing.JList getJList() {
130
        if (jList == null) {
131
            jList = new javax.swing.JList(new DefaultListModel());
132
            jList.setBounds(10, 49, 357, 139);
133
            jList
134
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
135
            jList.setBorder(BorderFactory.createLineBorder(Color.BLACK));
136
            jList
137
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
138

    
139
                    public void valueChanged(
140
                        javax.swing.event.ListSelectionEvent e) {
141
                        updateControls(e);
142
                    }
143
                });
144

    
145
        }
146
        return jList;
147
    }
148

    
149
    private void updateControls(javax.swing.event.ListSelectionEvent e) {
150
        System.out.println("valueChanged()"); // TODO Auto-generated Event stub
151
                                              // valueChanged()
152
        DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
153
        int selIndex = jList.getSelectedIndex();
154
        jBtnDown.setEnabled(false);
155
        jBtnUp.setEnabled(false);
156

    
157
        if (selIndex != -1) {
158
            if (lstModel.getSize() > 1) {
159
                if (selIndex < (lstModel.getSize() - 1)) {
160
                    jBtnDown.setEnabled(true);
161
                }
162

    
163
                if (selIndex > 0) {
164
                    jBtnUp.setEnabled(true);
165
                }
166
            }
167

    
168
        }
169

    
170
    }
171

    
172
    /**
173
     * This method initializes jBtnUp
174
     * 
175
     * @return JButton
176
     */
177
    private BasicArrowButton getJBtnUp() {
178
        if (jBtnUp == null) {
179
            jBtnUp =
180
                new javax.swing.plaf.basic.BasicArrowButton(
181
                    javax.swing.SwingConstants.NORTH);
182
            jBtnUp.setBounds(374, 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
     * This method initializes jBtnDown
193
     * 
194
     * @return JButton
195
     */
196
    private BasicArrowButton getJBtnDown() {
197
        if (jBtnDown == null) {
198
            jBtnDown =
199
                new javax.swing.plaf.basic.BasicArrowButton(
200
                    javax.swing.SwingConstants.SOUTH);
201
            jBtnDown.setBounds(374, 164, 25, 23);
202
            jBtnDown.setToolTipText(PluginServices.getText(this, "Bajar_capa"));
203
            jBtnDown.setActionCommand("DOWN");
204
            jBtnDown.addActionListener(this);
205
        }
206
        return jBtnDown;
207
    }
208

    
209
    /**
210
     * This method initializes jButton2
211
     * 
212
     * @return JButton
213
     */
214
    private JButton getJBtnAddLayer() {
215
        if (jBtnAddLayer == null) {
216
            jBtnAddLayer =
217
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
218
            jBtnAddLayer.setText(PluginServices.getText(this, "Anadir_capa")
219
                + "...");
220
            jBtnAddLayer.addActionListener(this);
221
            jBtnAddLayer.setActionCommand("ADD_LAYER");
222
        }
223
        return jBtnAddLayer;
224
    }
225

    
226
    /**
227
     * This method initializes jBtnRemoveLayer
228
     * 
229
     * @return JButton
230
     */
231
    private JButton getJBtnRemoveLayer() {
232
        if (jBtnRemoveLayer == null) {
233
            jBtnRemoveLayer =
234
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
235
            jBtnRemoveLayer.setText(PluginServices.getText(this, "Quitar_capa")
236
                + "...");
237
            jBtnRemoveLayer.addActionListener(this);
238
            jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
239

    
240
        }
241
        return jBtnRemoveLayer;
242
    }
243

    
244
    /**
245
     * This method initializes jBtnEditLegend
246
     * 
247
     * @return JButton
248
     */
249
    private JButton getJBtnEditLegend() {
250
        if (jBtnEditLegend == null) {
251
            jBtnEditLegend =
252
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
253
            jBtnEditLegend.setText(PluginServices.getText(this,
254
                "Editar_leyenda") + "...");
255
            jBtnEditLegend.addActionListener(this);
256
            jBtnEditLegend.setActionCommand("EDIT_LEGEND");
257
        }
258
        return jBtnEditLegend;
259
    }
260

    
261
    /**
262
     * This method initializes jBtnCancel
263
     * 
264
     * @return JButton
265
     */
266
    private JButton getJBtnCancel() {
267
        if (jBtnCancel == null) {
268
            jBtnCancel =
269
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
270
            jBtnCancel.setText(PluginServices.getText(this, "Cerrar"));
271
            jBtnCancel.setActionCommand("CANCEL");
272
            jBtnCancel.addActionListener(this);
273

    
274
        }
275
        return jBtnCancel;
276
    }
277

    
278
    public void actionPerformed(ActionEvent e) {
279
        DefaultListModel lstModel = (DefaultListModel) getJList().getModel();
280
        FLayers theLayers = mapCtrl.getMapContext().getLayers();
281

    
282
        int numLayers = theLayers.getLayersCount() - 1;
283

    
284
        if (e.getActionCommand() == "CANCEL") {
285
            if (PluginServices.getMainFrame() != null) {
286
                PluginServices.getMDIManager()
287
                    .closeWindow(FPanelLocConfig.this);
288
            } else {
289
                ((JDialog) (getParent().getParent().getParent().getParent()))
290
                    .dispose();
291
            }
292
        }
293
        if (e.getActionCommand() == "ADD_LAYER") {
294
            AddLayer addLayer =
295
                (AddLayer) PluginServices.getExtension(AddLayer.class);// new
296
                                                                       // AddLayer();
297
            // addLayer.initialize();
298
            if (addLayer.addLayers(mapCtrl)) {
299
                refreshList();
300
                updateControls(null);
301
            }
302
            if (mapCtrl instanceof MapOverview) {
303
                ((MapOverview) mapCtrl).refreshExtent();
304
            }
305

    
306
        }
307
        if (e.getActionCommand() == "REMOVE_LAYER") {
308
            if (jList.getSelectedIndex() != -1) {
309
                theLayers.removeLayer((String) lstModel.get(jList
310
                    .getSelectedIndex()));
311
                lstModel.remove(jList.getSelectedIndex());
312
                // /mapCtrl.drawMap();
313
                updateControls(null);
314
                if (mapCtrl instanceof MapOverview) {
315
                    ((MapOverview) mapCtrl).refreshExtent();
316
                }
317
            }
318
        }
319
        if (e.getActionCommand() == "EDIT_LEGEND") {
320
            int idSelec = jList.getSelectedIndex();
321
            if (idSelec != -1) {
322
                FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
323
                if (lyr instanceof Classifiable) {
324
                    ThemeManagerWindow m_LegendEditor =
325
                        new ThemeManagerWindow(lyr/* , mapCtrl.getMapContext() */);
326
                    theLayers.setActive(false);
327
                    lyr.setActive(true);
328
                    if (PluginServices.getMainFrame() == null) {
329
                        JDialog dlg = new JDialog();
330

    
331
                        m_LegendEditor.setPreferredSize(m_LegendEditor
332
                            .getSize());
333
                        dlg.getContentPane().add(m_LegendEditor);
334
                        dlg.setModal(true);
335
                        dlg.pack();
336
                        dlg.setVisible(true);
337

    
338
                    } else {
339
                        PluginServices.getMDIManager()
340
                            .addWindow(m_LegendEditor);
341
                    }
342
                } else {
343
                    JOptionPane.showMessageDialog(
344
                        null,
345
                        PluginServices.getText(this,
346
                            "Solo_para_capas_vectoriales") + ".");
347
                }
348

    
349
            }
350

    
351
        }
352
        if (e.getActionCommand() == "UP") {
353
            int idSelec = jList.getSelectedIndex();
354
            int fromIndex = idSelec;
355
            int toIndex = idSelec - 1;
356
            FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
357
            try {
358
                theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex);
359
            } catch (CancelationException e1) {
360
                e1.printStackTrace();
361
            }
362

    
363
            lstModel.remove(fromIndex);
364
            lstModel.add(toIndex, aux.getName());
365

    
366
            jList.setSelectedIndex(toIndex);
367
        }
368
        if (e.getActionCommand() == "DOWN") {
369
            int idSelec = jList.getSelectedIndex();
370
            int fromIndex = idSelec;
371
            int toIndex = idSelec + 1;
372
            FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
373
            try {
374
                theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex);
375
            } catch (CancelationException e1) {
376
                e1.printStackTrace();
377
            }
378

    
379
            lstModel.remove(fromIndex);
380
            lstModel.add(toIndex, aux.getName());
381

    
382
            jList.setSelectedIndex(toIndex);
383
        }
384

    
385
    }
386

    
387
    public WindowInfo getWindowInfo() {
388
        if (m_viewinfo == null) {
389
            m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
390
            m_viewinfo.setTitle(PluginServices.getText(this,
391
                "Configurar_localizador"));
392
            m_viewinfo.setWidth(this.getWidth() + 8);
393
            m_viewinfo.setHeight(this.getHeight() + 8);
394
        }
395
        return m_viewinfo;
396
    }
397

    
398
    /**
399
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
400
     */
401
    public void viewActivated() {
402
    }
403

    
404
    /**
405
     * This method initializes jPanel
406
     * 
407
     * @return javax.swing.JPanel
408
     */
409
    private JPanel getJPanel() {
410
        if (pnlButtons == null) {
411
            pnlButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
412
            pnlButtons.setBounds(new java.awt.Rectangle(0, 200,
413
                this.getWidth(), 37));
414
            pnlButtons.add(getJBtnAddLayer(), null);
415
            pnlButtons.add(getJBtnRemoveLayer(), null);
416
            pnlButtons.add(getJBtnEditLegend(), null);
417
            pnlButtons.add(getJBtnCancel(), null);
418
        }
419
        return pnlButtons;
420
    }
421

    
422
    /**
423
     * Obtiene el MapControl asociado al localizador
424
     * 
425
     * @return MapControl
426
     */
427
    public MapControl getMapCtrl() {
428
        return mapCtrl;
429
    }
430

    
431
    public Object getWindowProfile() {
432
        return WindowInfo.DIALOG_PROFILE;
433
    }
434

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