Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FPanelLegendManager.java @ 10626

History | View | Annotate | Download (18.8 KB)

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

    
46
import java.awt.CardLayout;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49

    
50
import javax.swing.ButtonGroup;
51
import javax.swing.ImageIcon;
52
import javax.swing.JButton;
53
import javax.swing.JCheckBox;
54
import javax.swing.JComboBox;
55
import javax.swing.JLabel;
56
import javax.swing.JPanel;
57
import javax.swing.JRadioButton;
58
import javax.swing.JScrollPane;
59
import javax.swing.JTextArea;
60

    
61
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
62
import com.iver.andami.PluginServices;
63
import com.iver.cit.gvsig.fmap.MapContext;
64
import com.iver.cit.gvsig.fmap.layers.FLayer;
65
import com.iver.cit.gvsig.fmap.layers.XMLException;
66
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
67
import com.iver.cit.gvsig.fmap.rendering.IntervalLegend;
68
import com.iver.cit.gvsig.fmap.rendering.Legend;
69
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
70
import com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend;
71
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
72
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
73
/**
74
 *
75
 * @author jmorell
76
 *
77
 * TODO To change the template for this generated type comment go to
78
 * Window - Preferences - Java - Code Style - Code Templates
79
 */
80
public class FPanelLegendManager extends AbstractPanel {
81

    
82
 private ImageIcon iuniqueValues= new ImageIcon(this.getClass().getClassLoader()
83
                         .getResource("images/ValoresUnicos.png"));
84
        private ImageIcon iintervalValues= new ImageIcon(this.getClass().getClassLoader()
85
                        .getResource("images/Intervalos.png"));
86
//        private ImageIcon iuniqueValues= new ImageIcon("images/ValoresUnicos.png");
87
//        private ImageIcon iintervalValues= new ImageIcon("images/Intervalos.png");
88
        private MapContext mapContext;
89
        private FLayer layer;
90
    private Legend renderer; // Le asignaremos la leyenda del primer tema activo.
91
    private FPanelLegendDefault m_defaultLegendPanel;
92
    private FPanelLegendValues m_valuesLegendPanel;
93
    private PanelLegendBreaks m_breaksLegendPanel;
94
    private FPanelLegendLabels m_labelsLegendPanel;
95
    private JPanel cards;
96
    private ComandosListener m_actionListener = new ComandosListener(this);
97
    private int visibleCard;
98
    private final String oneSymHelp = PluginServices.getText(this,"Muestra_todos_los_elementos_de_una_capa_usando_el_mismo_simbolo");
99
    private final String oneValHelp = PluginServices.getText(this,"Dado_un_campo_de_atributos") + "," + PluginServices.getText(this,"muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + ".";
100
    private final String intervalsHelp = PluginServices.getText(this,"Muestra_los_elementos_de_la_capa_usando_una_gama_de_colores_en_funcion_del_valor_de_un_determinado_campo_de_atributos") + ".";
101
    private final String labelsHelp = PluginServices.getText(this,"Permite_etiquetar_los_elementos_del_mapa_con_el_valor_de_un_determinado_campo") + ".";
102

    
103
        private JPanel topPanel = null;
104
        private JLabel jLabel = null;
105
        private JComboBox jComboBox = null;
106
        private JButton jButton = null;
107
        private JButton jButton1 = null;
108
        private JCheckBox jCheckBox = null;
109
        private JPanel jPanel = null;
110
        private JTextArea jTextArea = null;
111

    
112
        private JPanel jPanel1 = null;
113

    
114
        private JRadioButton symbolButton;
115
        private JRadioButton valuesButton;
116
        private JRadioButton intervalsButton;
117
        private JRadioButton labelsButton;
118

    
119
        private JScrollPane jScrollPane = null;
120
        public FPanelLegendManager() {
121
                initialize();
122
                this.setSize(500, 360);
123
        }
124

    
125
    private void initialize() {
126
                visibleCard=0;
127
        JPanel selector = new JPanel();
128
        selector.setLayout(null);
129

    
130
        symbolButton = new JRadioButton();
131
        symbolButton.setText(PluginServices.getText(this,"Simbolo_unico"));
132
        symbolButton.setActionCommand("SYMBOL_CHOOSE");
133
        symbolButton.addActionListener(m_actionListener);
134

    
135
        valuesButton = new JRadioButton();
136
        valuesButton.setText(PluginServices.getText(this,"Valores_unicos"));
137
        valuesButton.setActionCommand("VALUES_CHOOSE");
138
        valuesButton.addActionListener(m_actionListener);
139

    
140
        intervalsButton = new JRadioButton();
141
        intervalsButton.setText(PluginServices.getText(this,"Intervalos"));
142
        intervalsButton.setActionCommand("BREAKS_CHOOSE");
143
        intervalsButton.addActionListener(m_actionListener);
144

    
145
                labelsButton = new JRadioButton();
146
                labelsButton.setText(PluginServices.getText(this,"Etiquetados"));
147
                labelsButton.setActionCommand("LABELS_CHOOSE");
148
                labelsButton.addActionListener(m_actionListener);
149

    
150
                ButtonGroup jButtonGroup = new ButtonGroup();
151
                jButtonGroup.add(symbolButton);
152
                jButtonGroup.add(valuesButton);
153
                jButtonGroup.add(intervalsButton);
154
                jButtonGroup.add(labelsButton);
155

    
156

    
157
            //Create the cards.
158
        m_defaultLegendPanel = new FPanelLegendDefault();
159
        m_valuesLegendPanel = new FPanelLegendValues();
160
        m_breaksLegendPanel = new PanelLegendBreaks();
161
        m_labelsLegendPanel = new FPanelLegendLabels(this);
162

    
163
        //Create the panel that contains the cards.
164
        cards = new JPanel(new CardLayout());
165
        this.setLayout(null);
166
        selector.setBounds(5, 41, 134, 197);
167
        selector.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
168
        selector.setBackground(java.awt.SystemColor.text);
169
        cards.setBounds(143, 88, 502, 270);
170
        cards.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
171
        symbolButton.setBounds(5, 5, 131, 23);
172
        symbolButton.setSelected(true);
173
        symbolButton.setBackground(java.awt.SystemColor.text);
174
        valuesButton.setBounds(5, 28, 131, 23);
175
        valuesButton.setBackground(java.awt.SystemColor.text);
176
        intervalsButton.setBounds(5, 51, 131, 23);
177
        intervalsButton.setBackground(java.awt.SystemColor.text);
178
        labelsButton.setBounds(5, 74, 131, 23);
179
        labelsButton.setBackground(java.awt.SystemColor.text);
180
        this.setSize(649, 377);
181
        cards.add(m_defaultLegendPanel, "symbol");
182
        this.add(selector, null);
183
        selector.add(symbolButton, null);
184
        cards.add(m_valuesLegendPanel, "values");
185
        this.add(cards, null);
186
        selector.add(valuesButton, null);
187
        cards.add(m_breaksLegendPanel, "breaks");
188
        selector.add(intervalsButton, null);
189
        this.add(getTopPanel(), null);
190
        cards.add(m_labelsLegendPanel, "labels");
191
        selector.add(labelsButton, null);
192
        this.add(getJPanel(), null);
193
        this.add(getJPanel1(), null);
194
    }
195

    
196

    
197

    
198
    /**
199
     * En esta funci?n se coge el primer tema activo del TOC y se usa su
200
     * renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
201
     * cuadro de di?logo, en el  openLegendManager() de la vista.
202
     *
203
     * @param mapContext TOC que abre este cuadro de di?logo.
204
     * @throws DriverException
205
     */
206
    public void setMapContext(MapContext mapContext) throws ReadDriverException {
207
        this.mapContext = mapContext;
208
        layer = getFirstActiveLayerVect(mapContext.getLayers());
209
                try {
210
                        ClassifiableVectorial aux = (ClassifiableVectorial) layer;
211
                        renderer = aux.getLegend().cloneLegend();
212
                } catch (XMLException e) {
213
                        // TODO Auto-generated catch block
214
                        e.printStackTrace();
215
                }
216
        actualizar();
217
    }
218

    
219
    /**
220
     * DOCUMENT ME!
221
     */
222
    public void actualizar() {
223
            FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers());
224

    
225
        m_defaultLegendPanel.setLayer(lyrSelected, renderer);
226
        m_valuesLegendPanel.setLayer(lyrSelected, renderer);
227
        m_breaksLegendPanel.setLayer(lyrSelected, renderer);
228
        m_labelsLegendPanel.setLayer(lyrSelected, renderer);
229

    
230
        CardLayout cl = (CardLayout)(cards.getLayout());
231
        if (renderer instanceof SingleSymbolLegend) {
232
                jTextArea.setText(oneSymHelp);
233
                getJPanel1().removeAll();
234
                    getJPanel1().add(m_defaultLegendPanel.getM_previewSymbol());
235
                    getJPanel1().repaint();
236
                symbolButton.setSelected(true);
237
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Simbolo_unico") + ")");
238
            cl.show(cards, "symbol");
239
            setVisibleCard(0);
240
        }
241
        if (renderer instanceof UniqueValueLegend) {
242
                jTextArea.setText(oneValHelp);
243
                getJPanel1().removeAll();
244
                getJPanel1().repaint();
245
                valuesButton.setSelected(true);
246
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Valores_unicos") + ")");
247
            cl.show(cards, "values");
248
            setVisibleCard(1);
249
        }
250
        if (renderer instanceof IntervalLegend) {
251
                jTextArea.setText(intervalsHelp);
252
                getJPanel1().removeAll();
253
                    getJPanel1().repaint();
254
                intervalsButton.setSelected(true);
255
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Intervalos") + ")");
256
            cl.show(cards, "breaks");
257
            setVisibleCard(2);
258
        }
259

    
260
    }
261

    
262
        public void setLayer(FLayer lyr, Legend r) {
263
                layer = lyr;
264
                if (r instanceof SingleSymbolLegend) {
265
                        getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Simbolo_unico") + ")");
266
                        renderer = (SingleSymbolLegend)r;
267
                        getJPanel1().add(m_defaultLegendPanel.getM_previewSymbol());
268
            CardLayout cl = (CardLayout)(cards.getLayout());
269
            cl.show(cards, "symbol");
270
            setVisibleCard(0);
271
                } else if (r instanceof VectorialUniqueValueLegend) {
272
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Valores_unicos") + ")");
273
                        renderer = (VectorialUniqueValueLegend)r;
274
            CardLayout cl = (CardLayout)(cards.getLayout());
275
            cl.show(cards, "values");
276
            setVisibleCard(1);
277
                } else if (r instanceof VectorialIntervalLegend) {
278
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Intervalos") + ")");
279
                        renderer = (VectorialIntervalLegend)r;
280
            CardLayout cl = (CardLayout)(cards.getLayout());
281
            cl.show(cards, "breaks");
282
            setVisibleCard(2);
283
                } else {
284
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Etiquetas_estandar") + ")");
285
                        renderer = (SingleSymbolLegend)r;
286
            CardLayout cl = (CardLayout)(cards.getLayout());
287
            cl.show(cards, "labels");
288
            setVisibleCard(3);
289
                }
290
        }
291

    
292
    private class ComandosListener implements ActionListener {
293
     //   private FPanelLegendManager fPanSimMan;
294

    
295
        public ComandosListener(FPanelLegendManager fPanSimMan) {
296
        //        this.fPanSimMan = fPanSimMan;
297
        }
298

    
299
        public void actionPerformed(ActionEvent e) {
300
            if (e.getActionCommand() == "SYMBOL_CHOOSE") {
301
                    jTextArea.setText(oneSymHelp);
302
                        getJPanel1().removeAll();
303
                        getJPanel1().add(m_defaultLegendPanel.getM_previewSymbol());
304
                        getJPanel1().repaint();
305
                CardLayout cl = (CardLayout)(cards.getLayout());
306
                cl.show(cards, "symbol");
307
                visibleCard=0;
308
                System.out.println("Symbol");
309
            } else if (e.getActionCommand() == "VALUES_CHOOSE") {
310
                    jTextArea.setText(oneValHelp);
311
                        getJPanel1().removeAll();
312
                        getJPanel1().add(new JLabel(iuniqueValues));
313
                        getJPanel1().repaint();
314
                CardLayout cl = (CardLayout)(cards.getLayout());
315
                cl.show(cards, "values");
316
                visibleCard=1;
317
                    System.out.println("Values");
318
            } else if (e.getActionCommand() == "BREAKS_CHOOSE") {
319
                    jTextArea.setText(intervalsHelp);
320
                        getJPanel1().removeAll();
321
                        getJPanel1().add(new JLabel(iintervalValues));
322
                        getJPanel1().repaint();
323
                CardLayout cl = (CardLayout)(cards.getLayout());
324
                cl.show(cards, "breaks");
325
                visibleCard=2;
326
                    System.out.println("Breaks");
327
            } else if (e.getActionCommand() == "LABELS_CHOOSE") {
328
                    jTextArea.setText(labelsHelp);
329
                        getJPanel1().removeAll();
330
                        getJPanel1().add(m_labelsLegendPanel.getFPreviewSymbol());
331
                        getJPanel1().repaint();
332
                CardLayout cl = (CardLayout)(cards.getLayout());
333
                cl.show(cards, "labels");
334
                visibleCard=3;
335
                    System.out.println("Labels");
336
            } else {}
337
        }
338
    }
339

    
340
        public int getVisibleCard() {
341
                return visibleCard;
342
        }
343

    
344
        /**
345
         * This method initializes jPanel
346
         *
347
         * @return javax.swing.JPanel
348
         */
349
        private JPanel getTopPanel() {
350
                if (topPanel == null) {
351
                        jLabel = new JLabel();
352
                        topPanel = new JPanel();
353
                        topPanel.setLayout(null);
354
                        topPanel.setBounds(5, 5, 638, 31);
355
                        topPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
356
                        jLabel.setBounds(6, 4, 68, 22);
357
                        jLabel.setText(PluginServices.getText(this,"Leyenda") + ":");
358
                        topPanel.add(jLabel, null);
359
                        topPanel.add(getJComboBox(), null);
360
                        topPanel.add(getJButton(), null);
361
                        topPanel.add(getJButton1(), null);
362
                        topPanel.add(getJCheckBox(), null);
363
                }
364
                return topPanel;
365
        }
366
        /**
367
         * This method initializes jComboBox
368
         *
369
         * @return javax.swing.JComboBox
370
         */
371
        public JComboBox getJComboBox() {
372
                if (jComboBox == null) {
373
                        jComboBox = new JComboBox();
374
                        jComboBox.setBounds(78, 5, 250, 22);
375
                }
376
                return jComboBox;
377
        }
378
        /**
379
         * This method initializes jButton
380
         *
381
         * @return javax.swing.JButton
382
         */
383
        private JButton getJButton() {
384
                if (jButton == null) {
385
                        jButton = new JButton();
386
                        jButton.setBounds(345, 4, 22, 22);
387
                        jButton.setEnabled(false);
388
                }
389
                return jButton;
390
        }
391
        /**
392
         * This method initializes jButton1
393
         *
394
         * @return javax.swing.JButton
395
         */
396
        private JButton getJButton1() {
397
                if (jButton1 == null) {
398
                        jButton1 = new JButton();
399
                        jButton1.setBounds(371, 4, 22, 22);
400
                        jButton1.setEnabled(false);
401
                }
402
                return jButton1;
403
        }
404
        /**
405
         * This method initializes jCheckBox
406
         *
407
         * @return javax.swing.JCheckBox
408
         */
409
        private JCheckBox getJCheckBox() {
410
                if (jCheckBox == null) {
411
                        jCheckBox = new JCheckBox();
412
                        jCheckBox.setBounds(417, 4, 202, 22);
413
                        jCheckBox.setText(PluginServices.getText(this,"Leyenda_Por_Defecto"));
414
                        jCheckBox.setEnabled(false);
415
                }
416
                return jCheckBox;
417
        }
418
        /**
419
         * This method initializes jPanel
420
         *
421
         * @return javax.swing.JPanel
422
         */
423
        private JPanel getJPanel() {
424
                if (jPanel == null) {
425
                        jPanel = new JPanel();
426
                        jPanel.setLayout(null);
427
                        jPanel.setBounds(143, 39, 501, 46);
428
                        jPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
429
                        jPanel.add(getJScrollPane(), null);
430
                }
431
                return jPanel;
432
        }
433
        /**
434
         * This method initializes jTextArea
435
         *
436
         * @return javax.swing.JTextArea
437
         */
438
        private JTextArea getJTextArea() {
439
                if (jTextArea == null) {
440
                        jTextArea = new JTextArea();
441
                        jTextArea.setText(oneSymHelp);
442
                        jTextArea.setBackground(java.awt.SystemColor.control);
443
                        jTextArea.setLineWrap(true);
444
                        jTextArea.setRows(0);
445
                        jTextArea.setWrapStyleWord(false);
446
                        jTextArea.setEditable(false);
447
                        jTextArea.setPreferredSize(new java.awt.Dimension(495,40));
448
                }
449
                return jTextArea;
450
        }
451
        /**
452
         * This method initializes jPanel1
453
         *
454
         * @return javax.swing.JPanel
455
         */
456
        private JPanel getJPanel1() {
457
                if (jPanel1 == null) {
458
                        jPanel1 = new JPanel();
459
                        jPanel1.setBounds(6, 242, 132, 117);
460
                        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
461
                        jPanel1.setBackground(java.awt.SystemColor.text);
462
                }
463
                return jPanel1;
464
        }
465
        /**
466
         * @return Returns the m_breaksLegendPanel.
467
         */
468
        public PanelLegendBreaks getM_breaksLegendPanel() {
469
                return m_breaksLegendPanel;
470
        }
471
        /**
472
         * @param legendPanel The m_breaksLegendPanel to set.
473
         */
474
        public void setM_breaksLegendPanel(PanelLegendBreaks legendPanel) {
475
                m_breaksLegendPanel = legendPanel;
476
        }
477
        /**
478
         * @return Returns the m_defaultLegendPanel.
479
         */
480
        public FPanelLegendDefault getM_defaultLegendPanel() {
481
                return m_defaultLegendPanel;
482
        }
483
        /**
484
         * @param legendPanel The m_defaultLegendPanel to set.
485
         */
486
        public void setM_defaultLegendPanel(FPanelLegendDefault legendPanel) {
487
                m_defaultLegendPanel = legendPanel;
488
        }
489
        /**
490
         * @return Returns the m_labelsLegendPanel.
491
         */
492
        public FPanelLegendLabels getM_labelsLegendPanel() {
493
                return m_labelsLegendPanel;
494
        }
495
        /**
496
         * @param legendPanel The m_labelsLegendPanel to set.
497
         */
498
        public void setM_labelsLegendPanel(FPanelLegendLabels legendPanel) {
499
                m_labelsLegendPanel = legendPanel;
500
        }
501
        /**
502
         * @return Returns the m_valuesLegendPanel.
503
         */
504
        public FPanelLegendValues getM_valuesLegendPanel() {
505
                return m_valuesLegendPanel;
506
        }
507
        /**
508
         * @param legendPanel The m_valuesLegendPanel to set.
509
         */
510
        public void setM_valuesLegendPanel(FPanelLegendValues legendPanel) {
511
                m_valuesLegendPanel = legendPanel;
512
        }
513
        /**
514
         * @return Returns the renderer.
515
         */
516
        public Legend getRenderer() {
517
                return renderer;
518
        }
519
        /**
520
         * @param renderer The renderer to set.
521
         */
522
        public void setRenderer(Legend renderer) {
523
                this.renderer = renderer;
524
        }
525
        /**
526
         * @param visibleCard The visibleCard to set.
527
         */
528
        public void setVisibleCard(int visibleCard) {
529
                this.visibleCard = visibleCard;
530
        }
531
        /**
532
         * This method initializes jScrollPane
533
         *
534
         * @return javax.swing.JScrollPane
535
         */
536
        private JScrollPane getJScrollPane() {
537
                if (jScrollPane == null) {
538
                        jScrollPane = new JScrollPane();
539
                        jScrollPane.setBounds(2, 2, 498, 42);
540
                        jScrollPane.setViewportView(getJTextArea());
541
                }
542
                return jScrollPane;
543
        }
544
         }  //  @jve:decl-index=0:visual-constraint="26,17"