Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extGraph_predes / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FPanelLegendManager2.java @ 11717

History | View | Annotate | Download (18.5 KB)

1
package com.iver.cit.gvsig.project.documents.view.legend.gui;
2

    
3
import java.awt.CardLayout;
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6

    
7
import javax.swing.ButtonGroup;
8
import javax.swing.ImageIcon;
9
import javax.swing.JButton;
10
import javax.swing.JCheckBox;
11
import javax.swing.JComboBox;
12
import javax.swing.JLabel;
13
import javax.swing.JPanel;
14
import javax.swing.JRadioButton;
15
import javax.swing.JScrollPane;
16
import javax.swing.JTextArea;
17

    
18
import com.iver.andami.PluginServices;
19
import com.iver.cit.gvsig.fmap.DriverException;
20
import com.iver.cit.gvsig.fmap.MapContext;
21
import com.iver.cit.gvsig.fmap.layers.FLayer;
22
import com.iver.cit.gvsig.fmap.layers.XMLException;
23
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
24
import com.iver.cit.gvsig.fmap.rendering.IntervalLegend;
25
import com.iver.cit.gvsig.fmap.rendering.Legend;
26
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
27
import com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend;
28
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
29
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
30
/**
31
 *
32
 * @author jmorell
33
 *
34
 * TODO To change the template for this generated type comment go to
35
 * Window - Preferences - Java - Code Style - Code Templates
36
 */
37
public class FPanelLegendManager2 extends AbstractPanel {
38

    
39
 private ImageIcon iuniqueValues= new ImageIcon(this.getClass().getClassLoader()
40
                         .getResource("images/ValoresUnicos.png"));
41
        private ImageIcon iintervalValues= new ImageIcon(this.getClass().getClassLoader()
42
                        .getResource("images/Intervalos.png"));
43
//        private ImageIcon iuniqueValues= new ImageIcon("images/ValoresUnicos.png");
44
//        private ImageIcon iintervalValues= new ImageIcon("images/Intervalos.png");
45
        private MapContext mapContext;
46
        private FLayer layer;
47
    private Legend renderer; // Le asignaremos la leyenda del primer tema activo.
48
    private FPanelLegendDefault m_defaultLegendPanel;
49
    private FPanelLegendValues m_valuesLegendPanel;
50
    private PanelLegendBreaks m_breaksLegendPanel;
51
    private FPanelLegendLabels m_labelsLegendPanel;
52
    private PanelLegendDotDensity dotDensityLegendPanel;
53
    private JPanel cards;
54
    private ComandosListener m_actionListener = new ComandosListener(this);
55
    private int visibleCard;
56
    private final String oneSymHelp = PluginServices.getText(this,"Muestra_todos_los_elementos_de_una_capa_usando_el_mismo_simbolo");
57
    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") + ".";
58
    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") + ".";
59
    private final String labelsHelp = PluginServices.getText(this,"Permite_etiquetar_los_elementos_del_mapa_con_el_valor_de_un_determinado_campo") + ".";
60
    private final String dotDensityHelp = PluginServices.getText(this,"Defines_a_dot_density_symbol_based_on_a_field_value") + ".";
61

    
62
        private JPanel topPanel = null;
63
        private JLabel jLabel = null;
64
        private JComboBox jComboBox = null;
65
        private JButton jButton = null;
66
        private JButton jButton1 = null;
67
        private JCheckBox jCheckBox = null;
68
        private JPanel jPanel = null;
69
        private JTextArea titleTextArea = null;
70

    
71
        private JPanel jPanel1 = null;
72

    
73
        private JRadioButton symbolButton;
74
        private JRadioButton valuesButton;
75
        private JRadioButton intervalsButton;
76
        private JRadioButton labelsButton;
77

    
78
        private JScrollPane jScrollPane = null;
79
        private JRadioButton dotDensityButton = null;
80
        public FPanelLegendManager2() {
81
                initialize();
82
                this.setSize(500, 360);
83
        }
84

    
85
    private void initialize() {
86
                visibleCard=0;
87
        JPanel selector = new JPanel();
88
        selector.setLayout(null);
89

    
90
        symbolButton = new JRadioButton();
91
        symbolButton.setText(PluginServices.getText(this,"Simbolo_unico"));
92
        symbolButton.setActionCommand("SYMBOL_CHOICE");
93
        symbolButton.addActionListener(m_actionListener);
94

    
95
        valuesButton = new JRadioButton();
96
        valuesButton.setText(PluginServices.getText(this,"Valores_unicos"));
97
        valuesButton.setActionCommand("VALUES_CHOICE");
98
        valuesButton.addActionListener(m_actionListener);
99

    
100
        intervalsButton = new JRadioButton();
101
        intervalsButton.setText(PluginServices.getText(this,"Intervalos"));
102
        intervalsButton.setActionCommand("BREAKS_CHOICE");
103
        intervalsButton.addActionListener(m_actionListener);
104

    
105
                labelsButton = new JRadioButton();
106
                labelsButton.setText(PluginServices.getText(this,"Etiquetados"));
107
                labelsButton.setActionCommand("LABELS_CHOICE");
108
                labelsButton.addActionListener(m_actionListener);
109

    
110
                dotDensityButton = new JRadioButton();
111
                dotDensityButton.setText(PluginServices.getText(this, "dot_density"));
112
                dotDensityButton.setActionCommand("DOT_DENSITY_CHOICE");
113
                dotDensityButton.addActionListener(m_actionListener);
114

    
115
                ButtonGroup jButtonGroup = new ButtonGroup();
116
                jButtonGroup.add(symbolButton);
117
                jButtonGroup.add(valuesButton);
118
                jButtonGroup.add(intervalsButton);
119
                jButtonGroup.add(labelsButton);
120
                jButtonGroup.add(dotDensityButton);
121

    
122

    
123
            //Create the cards.
124
        m_defaultLegendPanel = new FPanelLegendDefault();
125
        m_valuesLegendPanel = new FPanelLegendValues();
126
        m_breaksLegendPanel = new PanelLegendBreaks();
127
        m_labelsLegendPanel = new FPanelLegendLabels(this);
128
        dotDensityLegendPanel = new PanelLegendDotDensity();
129

    
130
        //Create the panel that contains the cards.
131
        cards = new JPanel(new CardLayout());
132
        this.setLayout(null);
133
        selector.setBounds(5, 41, 134, 197);
134
        selector.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
135
        selector.setBackground(java.awt.SystemColor.text);
136
        cards.setBounds(143, 88, 502, 270);
137
        cards.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
138
        symbolButton.setBounds(5, 5, 131, 23);
139
        symbolButton.setSelected(true);
140
        symbolButton.setBackground(java.awt.SystemColor.text);
141
        valuesButton.setBounds(5, 28, 131, 23);
142
        valuesButton.setBackground(java.awt.SystemColor.text);
143
        intervalsButton.setBounds(5, 51, 131, 23);
144
        intervalsButton.setBackground(java.awt.SystemColor.text);
145
        labelsButton.setBounds(5, 74, 131, 23);
146
        labelsButton.setBackground(java.awt.SystemColor.text);
147
        dotDensityButton.setBounds(5,97,131,21);
148
                dotDensityButton.setBackground(java.awt.SystemColor.text);
149
        this.setSize(649, 377);
150
        cards.add(m_defaultLegendPanel, "symbol");
151
        this.add(selector, null);
152
        selector.add(symbolButton, null);
153
        cards.add(m_valuesLegendPanel, "values");
154
        this.add(cards, null);
155
        selector.add(valuesButton, null);
156
        cards.add(m_breaksLegendPanel, "breaks");
157
        selector.add(intervalsButton, null);
158
        this.add(getTopPanel(), null);
159
        cards.add(m_labelsLegendPanel, "labels");
160
        selector.add(labelsButton, null);
161
        cards.add(dotDensityLegendPanel, "dot_density");
162
        selector.add(dotDensityButton, null);
163
        this.add(getJPanel(), null);
164
        this.add(getPreviewPanel(), null);
165
    }
166

    
167

    
168

    
169
    /**
170
     * En esta funci?n se coge el primer tema activo del TOC y se usa su
171
     * renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
172
     * cuadro de di?logo, en el  openLegendManager() de la vista.
173
     *
174
     * @param mapContext TOC que abre este cuadro de di?logo.
175
     * @throws DriverException
176
     */
177
    public void setMapContext(MapContext mapContext) throws DriverException {
178
        this.mapContext = mapContext;
179
        layer = getFirstActiveLayerVect(mapContext.getLayers());
180
                try {
181
                        ClassifiableVectorial aux = (ClassifiableVectorial) layer;
182
                        renderer = aux.getLegend().cloneLegend();
183
                } catch (XMLException e) {
184
                        // TODO Auto-generated catch block
185
                        e.printStackTrace();
186
                }
187
        actualizar();
188
    }
189

    
190
    /**
191
     * DOCUMENT ME!
192
     */
193
    public void actualizar() {
194
            FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers());
195

    
196
        m_defaultLegendPanel.setLayer(lyrSelected, renderer);
197
        m_valuesLegendPanel.setLayer(lyrSelected, renderer);
198
        m_breaksLegendPanel.setLayer(lyrSelected, renderer);
199
        m_labelsLegendPanel.setLayer(lyrSelected, renderer);
200
        dotDensityLegendPanel.setLayer(lyrSelected, renderer);
201
        CardLayout cl = (CardLayout)(cards.getLayout());
202
        if (renderer instanceof SingleSymbolLegend) {
203
                titleTextArea.setText(oneSymHelp);
204
                getPreviewPanel().removeAll();
205
                    getPreviewPanel().add(m_defaultLegendPanel.getM_previewSymbol());
206
                    getPreviewPanel().repaint();
207
                symbolButton.setSelected(true);
208
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Simbolo_unico") + ")");
209
            cl.show(cards, "symbol");
210
            setVisibleCard(0);
211
        }
212
        if (renderer instanceof UniqueValueLegend) {
213
                titleTextArea.setText(oneValHelp);
214
                getPreviewPanel().removeAll();
215
                getPreviewPanel().repaint();
216
                valuesButton.setSelected(true);
217
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Valores_unicos") + ")");
218
            cl.show(cards, "values");
219
            setVisibleCard(1);
220
        }
221
        if (renderer instanceof IntervalLegend) {
222
                titleTextArea.setText(intervalsHelp);
223
                getPreviewPanel().removeAll();
224
                    getPreviewPanel().repaint();
225
                intervalsButton.setSelected(true);
226
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Intervalos") + ")");
227
            cl.show(cards, "breaks");
228
            setVisibleCard(2);
229
        }
230

    
231
    }
232

    
233
        public void setLayer(FLayer lyr, Legend r) {
234
                layer = lyr;
235
                if (r instanceof SingleSymbolLegend) {
236
                        getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Simbolo_unico") + ")");
237
                        renderer = (SingleSymbolLegend)r;
238
                        getPreviewPanel().add(m_defaultLegendPanel.getM_previewSymbol());
239
            CardLayout cl = (CardLayout)(cards.getLayout());
240
            cl.show(cards, "symbol");
241
            setVisibleCard(0);
242
                } else if (r instanceof VectorialUniqueValueLegend) {
243
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Valores_unicos") + ")");
244
                        renderer = (VectorialUniqueValueLegend)r;
245
            CardLayout cl = (CardLayout)(cards.getLayout());
246
            cl.show(cards, "values");
247
            setVisibleCard(1);
248
                } else if (r instanceof VectorialIntervalLegend) {
249
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Intervalos") + ")");
250
                        renderer = (VectorialIntervalLegend)r;
251
            CardLayout cl = (CardLayout)(cards.getLayout());
252
            cl.show(cards, "breaks");
253
            setVisibleCard(2);
254
                } else {
255
            getJComboBox().getModel().setSelectedItem(layer.getName() + " (" + PluginServices.getText(this,"Etiquetas_estandar") + ")");
256
                        renderer = (SingleSymbolLegend)r;
257
            CardLayout cl = (CardLayout)(cards.getLayout());
258
            cl.show(cards, "labels");
259
            setVisibleCard(3);
260
                }
261
        }
262

    
263
    private class ComandosListener implements ActionListener {
264

    
265

    
266
        //   private FPanelLegendManager fPanSimMan;
267

    
268
        public ComandosListener(FPanelLegendManager2 fPanSimMan) {
269
        //        this.fPanSimMan = fPanSimMan;
270
        }
271

    
272
        public void actionPerformed(ActionEvent e) {
273
                getPreviewPanel().removeAll();
274

    
275
            if (e.getActionCommand() == "SYMBOL_CHOICE") {
276
                    titleTextArea.setText(oneSymHelp);
277
                        getPreviewPanel().add(m_defaultLegendPanel.getM_previewSymbol());
278
                    CardLayout cl = (CardLayout)(cards.getLayout());
279
                cl.show(cards, "symbol");
280
                visibleCard=0;
281
            } else if (e.getActionCommand() == "VALUES_CHOICE") {
282
                    titleTextArea.setText(oneValHelp);
283
                        getPreviewPanel().add(new JLabel(iuniqueValues));
284
                    CardLayout cl = (CardLayout)(cards.getLayout());
285
                cl.show(cards, "values");
286
                visibleCard=1;
287
            } else if (e.getActionCommand() == "BREAKS_CHOICE") {
288
                    titleTextArea.setText(intervalsHelp);
289
                        getPreviewPanel().add(new JLabel(iintervalValues));
290
                    CardLayout cl = (CardLayout)(cards.getLayout());
291
                cl.show(cards, "breaks");
292
                visibleCard=2;
293
            } else if (e.getActionCommand() == "LABELS_CHOICE") {
294
                    titleTextArea.setText(labelsHelp);
295
                        getPreviewPanel().add(m_labelsLegendPanel.getFPreviewSymbol());
296
                    CardLayout cl = (CardLayout)(cards.getLayout());
297
                cl.show(cards, "labels");
298
                visibleCard=3;
299
            } else if (e.getActionCommand() == "DOT_DENSITY_CHOICE") {
300
                    titleTextArea.setText(dotDensityHelp);
301
//    TODO set a preview                getPreviewPanel().add(dotDensityLegendPanel.getFPreviewSymbol());
302
                    CardLayout c1 = (CardLayout) (cards.getLayout());
303
                    c1.show(cards, "dot_density");
304
                    visibleCard=4;
305
            } else {}
306
                getPreviewPanel().repaint();
307

    
308
        }
309
    }
310

    
311
        public int getVisibleCard() {
312
                return visibleCard;
313
        }
314

    
315
        /**
316
         * This method initializes jPanel
317
         *
318
         * @return javax.swing.JPanel
319
         */
320
        private JPanel getTopPanel() {
321
                if (topPanel == null) {
322
                        jLabel = new JLabel();
323
                        topPanel = new JPanel();
324
                        topPanel.setLayout(null);
325
                        topPanel.setBounds(5, 5, 638, 31);
326
                        topPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
327
                        jLabel.setBounds(6, 4, 68, 22);
328
                        jLabel.setText(PluginServices.getText(this,"Leyenda") + ":");
329
                        topPanel.add(jLabel, null);
330
                        topPanel.add(getJComboBox(), null);
331
                        topPanel.add(getJButton(), null);
332
                        topPanel.add(getJButton1(), null);
333
                        topPanel.add(getJCheckBox(), null);
334
                }
335
                return topPanel;
336
        }
337
        /**
338
         * This method initializes jComboBox
339
         *
340
         * @return javax.swing.JComboBox
341
         */
342
        public JComboBox getJComboBox() {
343
                if (jComboBox == null) {
344
                        jComboBox = new JComboBox();
345
                        jComboBox.setBounds(78, 5, 250, 22);
346
                }
347
                return jComboBox;
348
        }
349
        /**
350
         * This method initializes jButton
351
         *
352
         * @return javax.swing.JButton
353
         */
354
        private JButton getJButton() {
355
                if (jButton == null) {
356
                        jButton = new JButton();
357
                        jButton.setBounds(345, 4, 22, 22);
358
                        jButton.setEnabled(false);
359
                }
360
                return jButton;
361
        }
362
        /**
363
         * This method initializes jButton1
364
         *
365
         * @return javax.swing.JButton
366
         */
367
        private JButton getJButton1() {
368
                if (jButton1 == null) {
369
                        jButton1 = new JButton();
370
                        jButton1.setBounds(371, 4, 22, 22);
371
                        jButton1.setEnabled(false);
372
                }
373
                return jButton1;
374
        }
375
        /**
376
         * This method initializes jCheckBox
377
         *
378
         * @return javax.swing.JCheckBox
379
         */
380
        private JCheckBox getJCheckBox() {
381
                if (jCheckBox == null) {
382
                        jCheckBox = new JCheckBox();
383
                        jCheckBox.setBounds(417, 4, 202, 22);
384
                        jCheckBox.setText(PluginServices.getText(this,"Leyenda_Por_Defecto"));
385
                        jCheckBox.setEnabled(false);
386
                }
387
                return jCheckBox;
388
        }
389
        /**
390
         * This method initializes jPanel
391
         *
392
         * @return javax.swing.JPanel
393
         */
394
        private JPanel getJPanel() {
395
                if (jPanel == null) {
396
                        jPanel = new JPanel();
397
                        jPanel.setLayout(null);
398
                        jPanel.setBounds(143, 39, 501, 46);
399
                        jPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
400
                        jPanel.add(getJScrollPane(), null);
401
                }
402
                return jPanel;
403
        }
404
        /**
405
         * This method initializes jTextArea
406
         *
407
         * @return javax.swing.JTextArea
408
         */
409
        private JTextArea getJTextArea() {
410
                if (titleTextArea == null) {
411
                        titleTextArea = new JTextArea();
412
                        titleTextArea.setText(oneSymHelp);
413
                        titleTextArea.setBackground(java.awt.SystemColor.control);
414
                        titleTextArea.setLineWrap(true);
415
                        titleTextArea.setRows(0);
416
                        titleTextArea.setWrapStyleWord(false);
417
                        titleTextArea.setEditable(false);
418
                        titleTextArea.setPreferredSize(new java.awt.Dimension(495,40));
419
                }
420
                return titleTextArea;
421
        }
422
        /**
423
         * This method initializes jPanel1
424
         *
425
         * @return javax.swing.JPanel
426
         */
427
        private JPanel getPreviewPanel() {
428
                if (jPanel1 == null) {
429
                        jPanel1 = new JPanel();
430
                        jPanel1.setBounds(6, 242, 132, 117);
431
                        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
432
                        jPanel1.setBackground(java.awt.SystemColor.text);
433
                }
434
                return jPanel1;
435
        }
436
        /**
437
         * @return Returns the m_breaksLegendPanel.
438
         */
439
        public PanelLegendBreaks getM_breaksLegendPanel() {
440
                return m_breaksLegendPanel;
441
        }
442
        /**
443
         * @param legendPanel The m_breaksLegendPanel to set.
444
         */
445
        public void setM_breaksLegendPanel(PanelLegendBreaks legendPanel) {
446
                m_breaksLegendPanel = legendPanel;
447
        }
448
        /**
449
         * @return Returns the m_defaultLegendPanel.
450
         */
451
        public FPanelLegendDefault getM_defaultLegendPanel() {
452
                return m_defaultLegendPanel;
453
        }
454
        /**
455
         * @param legendPanel The m_defaultLegendPanel to set.
456
         */
457
        public void setM_defaultLegendPanel(FPanelLegendDefault legendPanel) {
458
                m_defaultLegendPanel = legendPanel;
459
        }
460
        /**
461
         * @return Returns the m_labelsLegendPanel.
462
         */
463
        public FPanelLegendLabels getM_labelsLegendPanel() {
464
                return m_labelsLegendPanel;
465
        }
466
        /**
467
         * @param legendPanel The m_labelsLegendPanel to set.
468
         */
469
        public void setM_labelsLegendPanel(FPanelLegendLabels legendPanel) {
470
                m_labelsLegendPanel = legendPanel;
471
        }
472
        /**
473
         * @return Returns the m_valuesLegendPanel.
474
         */
475
        public FPanelLegendValues getM_valuesLegendPanel() {
476
                return m_valuesLegendPanel;
477
        }
478

    
479
        public PanelLegendDotDensity getPanelDotDensityLegend() {
480
                return dotDensityLegendPanel;
481
        }
482
        /**
483
         * @param legendPanel The m_valuesLegendPanel to set.
484
         */
485
        public void setM_valuesLegendPanel(FPanelLegendValues legendPanel) {
486
                m_valuesLegendPanel = legendPanel;
487
        }
488
        /**
489
         * @return Returns the renderer.
490
         */
491
        public Legend getRenderer() {
492
                return renderer;
493
        }
494
        /**
495
         * @param renderer The renderer to set.
496
         */
497
        public void setRenderer(Legend renderer) {
498
                this.renderer = renderer;
499
        }
500
        /**
501
         * @param visibleCard The visibleCard to set.
502
         */
503
        public void setVisibleCard(int visibleCard) {
504
                this.visibleCard = visibleCard;
505
        }
506
        /**
507
         * This method initializes jScrollPane
508
         *
509
         * @return javax.swing.JScrollPane
510
         */
511
        private JScrollPane getJScrollPane() {
512
                if (jScrollPane == null) {
513
                        jScrollPane = new JScrollPane();
514
                        jScrollPane.setBounds(2, 2, 498, 42);
515
                        jScrollPane.setViewportView(getJTextArea());
516
                }
517
                return jScrollPane;
518
        }
519

    
520
}  //  @jve:decl-index=0:visual-constraint="26,17"