Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FPanelLegendLabels.java @ 6118

History | View | Annotate | Download (15.9 KB)

1 1671 jmorell
/*
2
 * Created on 01-jun-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels;
46
47
import java.awt.Font;
48
import java.awt.event.ActionEvent;
49 3035 fjp
import java.sql.Types;
50
import java.util.ArrayList;
51 1671 jmorell
52
import javax.swing.ButtonGroup;
53
import javax.swing.DefaultComboBoxModel;
54
import javax.swing.JPanel;
55
56
import com.iver.andami.PluginServices;
57 2610 fernando
import com.iver.cit.gvsig.ProjectExtension;
58 2183 fernando
import com.iver.cit.gvsig.fmap.DriverException;
59 1671 jmorell
import com.iver.cit.gvsig.fmap.core.FShape;
60
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
61
import com.iver.cit.gvsig.fmap.layers.FLayer;
62 4874 fjp
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
63 1671 jmorell
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
65
import com.iver.cit.gvsig.fmap.rendering.Legend;
66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
67 6118 jaume
import com.iver.cit.gvsig.gui.dialogs.FontChooser;
68 6117 jaume
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
69
70 3035 fjp
import javax.swing.JComboBox;
71
import javax.swing.JLabel;
72
import javax.swing.JCheckBox;
73 1671 jmorell
74
/**
75
 * @author fjp
76
 *
77
 */
78
public class FPanelLegendLabels extends JPanel implements ILegendPanel {
79
        private static final Font DEFAULT_FONT =
80
                  new Font("SansSerif", Font.PLAIN, 9);
81
82
83
        // private TOC m_TOC;
84
        private VectorialLegend m_Renderer;
85
        private ClassifiableVectorial m_lyr;
86
        private FSymbol m_FSymbol;
87
88
        private ColorChooserPanel m_colorChooser = new ColorChooserPanel();
89
90
91 2438 caballero
        //private javax.swing.JLabel jLabel = null;
92 1671 jmorell
        private javax.swing.JCheckBox jCheckBox = null;
93
        private javax.swing.JLabel jLabel1 = null;
94 3035 fjp
        private javax.swing.JComboBox jComboBoxTextField = null;
95 1671 jmorell
        private javax.swing.JLabel jLabel2 = null;
96 3035 fjp
        private javax.swing.JComboBox jComboBoxHeightField = null;
97 1671 jmorell
        private javax.swing.JPanel jPanel = null;
98
        private javax.swing.JTextField jTextField = null;
99
        private javax.swing.JRadioButton jRadioButton = null;
100
        private javax.swing.JRadioButton jRadioButton1 = null;
101
        private FPreviewSymbol fPreviewSymbol = null;
102
        private javax.swing.JLabel jLabel3 = null;
103
        private javax.swing.JButton jButton = null;
104
105
        private Font labelFont = DEFAULT_FONT;
106 2438 caballero
        //private JPanel parent;
107 1671 jmorell
        private javax.swing.JLabel jLabel4 = null;
108 3035 fjp
109
110
    private JComboBox jComboBoxRotationField = null;
111
112
113
    private JLabel jLabel = null;
114
115
116
    private JCheckBox jCheckBoxTextOnly = null;
117 1671 jmorell
        /**
118
         * This is the default constructor
119
         */
120
        public FPanelLegendLabels(JPanel parent) {
121
                super();
122 2438 caballero
                //this.parent = parent;
123 1671 jmorell
                initialize();
124
        }
125
        /**
126
         * This method initializes this
127
         *
128
         * @return void
129
         */
130
        private  void initialize() {
131 3035 fjp
                jLabel = new JLabel();
132
                jLabel.setBounds(30, 110, 138, 18);
133
                jLabel.setText("Campo de rotaci?n");
134 1671 jmorell
                this.setLayout(null);
135
                this.setSize(454, 230);
136 3035 fjp
                this.add(getJCheckBoxTextOnly(), null);
137
                this.add(jLabel, null);
138
                this.add(getJComboBoxRotationField(), null);
139 1671 jmorell
                this.add(getJCheckBox(), null);
140
                this.add(getJLabel1(), null);
141 3035 fjp
                this.add(getJComboBoxTextField(), null);
142 1671 jmorell
                this.add(getJLabel2(), null);
143 3035 fjp
                this.add(getJComboBoxHeightField(), null);
144 1671 jmorell
                this.add(getJPanel(), null);
145
                this.add(getFPreviewSymbol(), null);
146
                this.add(getJLabel3(), null);
147
                this.add(getJButton(), null);
148
149
                // m_colorChooser = new ColorChooserPanel();
150
                // m_colorChooser.setColor(Color.RED);
151
                m_colorChooser.setAlpha(255);
152 3035 fjp
                m_colorChooser.setBounds(312, 115, 99, 34);
153 1671 jmorell
                m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
154
                        public void actionPerformed(ActionEvent e) {
155
                                updateControls();
156
                        }
157
                });
158
                this.add(getJLabel4(), null);
159
                this.add(m_colorChooser);
160
161
        }
162
        public void setLayer(FLayer lyr, Legend r)
163
        {
164
                m_lyr = (ClassifiableVectorial) lyr;
165
                m_Renderer = (VectorialLegend)r;
166
167
                fillFieldNames();
168 3035 fjp
                getJComboBoxTextField().getModel().setSelectedItem(m_Renderer.getLabelField());
169
        getJComboBoxHeightField().getModel().setSelectedItem(m_Renderer.getLabelHeightField());
170
        getJComboBoxRotationField().getModel().setSelectedItem(m_Renderer.getLabelRotationField());
171 1671 jmorell
                setFSymbol(r.getDefaultSymbol());
172
173
                if (m_Renderer.getLabelField() != null)
174
                        getJCheckBox().setSelected(true);
175
                else
176
                        getJCheckBox().setSelected(false);
177
178
179
180
181
        }
182
        public void setFSymbol(FSymbol sym)
183
        {
184
                if (sym == null)
185
                {
186
                        m_FSymbol = new FSymbol(FShape.MULTI);
187
                }
188
                else
189
                        m_FSymbol = sym;
190
191
                if (m_FSymbol.getFontColor()!=null){
192
                        m_colorChooser.setColor(m_FSymbol.getFontColor());
193
                }
194
                fPreviewSymbol.setSymbol(m_FSymbol);
195
196
                getJRadioButton1().setSelected(!m_FSymbol.isFontSizeInPixels());
197 3035 fjp
        getJCheckBoxTextOnly().setSelected(!m_FSymbol.isShapeVisible());
198 1671 jmorell
                getJTextField().setText("" +
199
                                m_FSymbol.getFontSize());
200
201
202
        }
203
204
        private void updateControls() {
205 3035 fjp
                getJComboBoxTextField().setEnabled(getJCheckBox().isSelected());
206
                getJComboBoxHeightField().setEnabled(getJCheckBox().isSelected());
207
        getJComboBoxRotationField().setEnabled(getJCheckBox().isSelected());
208 1671 jmorell
                getJRadioButton().setEnabled(getJCheckBox().isSelected());
209
                getJRadioButton1().setEnabled(getJCheckBox().isSelected());
210
                getJTextField().setEnabled(getJCheckBox().isSelected());
211
                if (getJCheckBox().isSelected())
212
                {
213
                        FSymbol sym = m_FSymbol;
214
                        sym.setFont(labelFont);
215
                        sym.setFontColor(m_colorChooser.getColor());
216
                        fPreviewSymbol.setSymbol(sym);
217
                }
218
        }
219 2584 caballero
        public void updateValuesFromControls(VectorialLegend l) {
220 1671 jmorell
                if (getJCheckBox().isSelected())
221
                {
222 2741 fjp
            m_FSymbol = l.getDefaultSymbol();
223 2775 fjp
            m_FSymbol.setFont(labelFont);
224 3035 fjp
                        l.setLabelField((String) getJComboBoxTextField().getSelectedItem());
225
                        l.setLabelHeightField((String) getJComboBoxHeightField().getSelectedItem());
226
            l.setLabelRotationField((String) getJComboBoxRotationField().getSelectedItem());
227 1671 jmorell
                        m_FSymbol.setFontColor(m_colorChooser.getColor());
228 2584 caballero
                        //m_FSymbol.setSymbolType(m_Renderer.getShapeType());
229 1671 jmorell
                        if (!getJRadioButton().isSelected())
230
                        {
231
                                float sizeUnits = Float.parseFloat(getJTextField().getText());
232
                                m_FSymbol.setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
233
                                m_FSymbol.setFontSizeInPixels(false);
234
                        }
235
                        else
236
                        {
237
                                float sizePoints = Float.parseFloat(getJTextField().getText());
238
                                m_FSymbol.setFont(labelFont);
239
                                m_FSymbol.setFont(labelFont.deriveFont(sizePoints));
240
                                m_FSymbol.setFontSize(sizePoints);
241
                                m_FSymbol.setFontSizeInPixels(true);
242 3035 fjp
                        }
243
            m_FSymbol.setShapeVisible(true);
244
            if (getJCheckBoxTextOnly().isSelected())
245
                m_FSymbol.setShapeVisible(false);
246
247 2584 caballero
                        l.setDefaultSymbol(m_FSymbol);
248 2741 fjp
            // System.out.println("Color punto 3 " + m_FSymbol.getColor().toString());
249 1671 jmorell
                }
250
                else
251
                {
252
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
253
                        // ha de ser null
254 2584 caballero
                        l.setLabelField(null);
255 1671 jmorell
                }
256
        }
257
258
259
260
261
        private void fillFieldNames() {
262
263
                SelectableDataSource rs;
264
                try {
265 4874 fjp
                        // rs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr);
266
                        rs = ((FLyrVect)m_lyr).getRecordset();
267 2183 fernando
                        String[] nomFields;
268 3035 fjp
            ArrayList nomNumericFields = new ArrayList();
269 1671 jmorell
                        nomFields = new String[rs.getFieldCount()];
270 2183 fernando
                        for (int i = 0; i < rs.getFieldCount(); i++) {
271
                                nomFields[i] = rs.getFieldName(i).trim();
272 3035 fjp
                if ((rs.getFieldType(i) == Types.FLOAT)
273
                   || (rs.getFieldType(i) == Types.BIGINT)
274
                   || (rs.getFieldType(i) == Types.DOUBLE)
275
                   || (rs.getFieldType(i) == Types.INTEGER))
276
                    nomNumericFields.add(nomFields[i]);
277 2183 fernando
                        }
278 1671 jmorell
279 2183 fernando
                        DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
280 3035 fjp
                        getJComboBoxTextField().setModel(cM_labelField);
281
                        DefaultComboBoxModel cM_HeightField = new DefaultComboBoxModel(nomNumericFields.toArray(new String[0]));
282
                        getJComboBoxHeightField().setModel(cM_HeightField);
283
            DefaultComboBoxModel cM_RotationField = new DefaultComboBoxModel(nomNumericFields.toArray(new String[0]));
284
            getJComboBoxRotationField().setModel(cM_RotationField);
285 1671 jmorell
286 2183 fernando
                } catch (DriverException e) {
287
                        e.printStackTrace();
288
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
289
                        e.printStackTrace();
290
                }
291 1671 jmorell
        }
292
293
294
        /**
295

296
         * This method initializes jCheckBox
297

298
         *
299

300
         * @return javax.swing.JCheckBox
301

302
         */
303
        private javax.swing.JCheckBox getJCheckBox() {
304
                if (jCheckBox == null) {
305
                        jCheckBox = new javax.swing.JCheckBox();
306
                        jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado"));
307 2379 jmorell
                        jCheckBox.setBounds(28, 22, 152, 23);
308 1671 jmorell
                        jCheckBox.addItemListener(new java.awt.event.ItemListener() {
309
310
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
311
                                        updateControls();
312
313
                                }
314
                        });
315
316
                }
317
                return jCheckBox;
318
        }
319
320
        /**
321

322
         * This method initializes jLabel1
323

324
         *
325

326
         * @return javax.swing.JLabel
327

328
         */
329
        private javax.swing.JLabel getJLabel1() {
330
                if (jLabel1 == null) {
331
                        jLabel1 = new javax.swing.JLabel();
332
                        jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado"));
333 2379 jmorell
                        jLabel1.setBounds(29, 53, 139, 21);
334 1671 jmorell
                }
335
                return jLabel1;
336
        }
337
338
        /**
339

340
         * This method initializes jComboBox
341

342
         *
343

344
         * @return javax.swing.JComboBox
345

346
         */
347 3035 fjp
        private javax.swing.JComboBox getJComboBoxTextField() {
348
                if (jComboBoxTextField == null) {
349
                        jComboBoxTextField = new javax.swing.JComboBox();
350
                        jComboBoxTextField.setBounds(175, 52, 110, 19);
351
                        jComboBoxTextField.setEnabled(false);
352 1671 jmorell
                }
353 3035 fjp
                return jComboBoxTextField;
354 1671 jmorell
        }
355
356
        /**
357

358
         * This method initializes jLabel2
359

360
         *
361

362
         * @return javax.swing.JLabel
363

364
         */
365
        private javax.swing.JLabel getJLabel2() {
366
                if (jLabel2 == null) {
367
                        jLabel2 = new javax.swing.JLabel();
368 3035 fjp
                        jLabel2.setBounds(29, 81, 137, 21);
369 1671 jmorell
                        jLabel2.setText(PluginServices.getText(this,"campo_altura_texto"));
370 3035 fjp
                        jLabel2.setVisible(true);
371 1671 jmorell
                }
372
                return jLabel2;
373
        }
374
375
        /**
376

377
         * This method initializes jComboBox1
378

379
         *
380

381
         * @return javax.swing.JComboBox
382

383
         */
384 3035 fjp
        private javax.swing.JComboBox getJComboBoxHeightField() {
385
                if (jComboBoxHeightField == null) {
386
                        jComboBoxHeightField = new javax.swing.JComboBox();
387
                        jComboBoxHeightField.setBounds(175, 82, 110, 18);
388
                        jComboBoxHeightField.setEnabled(true);
389
                        jComboBoxHeightField.setVisible(true);
390 1671 jmorell
                }
391 3035 fjp
                return jComboBoxHeightField;
392 1671 jmorell
        }
393
394
        /**
395

396
         * This method initializes jPanel
397

398
         *
399

400
         * @return javax.swing.JPanel
401

402
         */
403
        private javax.swing.JPanel getJPanel() {
404
                if (jPanel == null) {
405
                        jPanel = new javax.swing.JPanel();
406
                        jPanel.setLayout(null);
407
                        jPanel.setBounds(29, 136, 258, 84);
408
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"Altura_fija_de_texto"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
409
                        ButtonGroup jButtonGroup = new ButtonGroup();
410
                        jButtonGroup.add(getJRadioButton1());
411
                        jButtonGroup.add(getJRadioButton());
412
                        jPanel.add(getJRadioButton1(), null);
413
                        jPanel.add(getJRadioButton(), null);
414
                        jPanel.add(getJTextField(), null);
415
                }
416
                return jPanel;
417
        }
418
419
        /**
420

421
         * This method initializes jTextField
422

423
         *
424

425
         * @return javax.swing.JTextField
426

427
         */
428
        private javax.swing.JTextField getJTextField() {
429
                if (jTextField == null) {
430
                        jTextField = new javax.swing.JTextField();
431
                        jTextField.setBounds(26, 32, 76, 21);
432
                        jTextField.setEnabled(false);
433
                        jTextField.setText("10");
434
                }
435
                return jTextField;
436
        }
437
438
/**
439

440
         * This method initializes jRadioButton
441

442
         *
443

444
         * @return javax.swing.JRadioButton
445

446
         */
447
        private javax.swing.JRadioButton getJRadioButton() {
448
                if (jRadioButton == null) {
449
                        jRadioButton = new javax.swing.JRadioButton();
450
                        jRadioButton.setText(PluginServices.getText(this,"En_pixels"));
451
                        jRadioButton.setBounds(145, 44, 100, 23);
452
                        jRadioButton.setEnabled(false);
453
                        jRadioButton.setSelected(true);
454
                }
455
                return jRadioButton;
456
        }
457
458
        /**
459

460
         * This method initializes jRadioButton1
461

462
         *
463

464
         * @return javax.swing.JRadioButton
465

466
         */
467
        private javax.swing.JRadioButton getJRadioButton1() {
468
                if (jRadioButton1 == null) {
469
                        jRadioButton1 = new javax.swing.JRadioButton();
470
                        jRadioButton1.setText(PluginServices.getText(this,"En_metros"));
471
                        jRadioButton1.setBounds(145, 16, 100, 23);
472
                        jRadioButton1.setEnabled(false);
473
                }
474
                return jRadioButton1;
475
        }
476
477
        /**
478

479
         * This method initializes fPreviewSymbol
480

481
         *
482

483
         * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol
484

485
         */
486
        public FPreviewSymbol getFPreviewSymbol() {
487
                if (fPreviewSymbol == null) {
488
                        fPreviewSymbol = new FPreviewSymbol();
489
                        fPreviewSymbol.setBounds(311, 53, 134, 77);
490
                }
491
                return fPreviewSymbol;
492
        }
493
494
        /**
495

496
         * This method initializes jLabel3
497

498
         *
499

500
         * @return javax.swing.JLabel
501

502
         */
503
        private javax.swing.JLabel getJLabel3() {
504
                if (jLabel3 == null) {
505
                        jLabel3 = new javax.swing.JLabel();
506
                        jLabel3.setBounds(312, 28, 100, 18);
507
                        jLabel3.setText(PluginServices.getText(this,"Previsualizacion"));
508 2204 vcaballero
                        jLabel3.setVisible(false);
509 1671 jmorell
                }
510
                return jLabel3;
511
        }
512
513
        /**
514

515
         * This method initializes jButton
516

517
         *
518

519
         * @return javax.swing.JButton
520

521
         */
522
        private javax.swing.JButton getJButton() {
523
                if (jButton == null) {
524
                        jButton = new javax.swing.JButton();
525 3035 fjp
                        jButton.setBounds(314, 54, 111, 29);
526 1671 jmorell
                        jButton.setText(PluginServices.getText(this,"fuente")+"...");
527
                        jButton.addActionListener(new java.awt.event.ActionListener() {
528
529
                                public void actionPerformed(java.awt.event.ActionEvent e) {
530 2438 caballero
                                        //JButton origen = (JButton) e.getSource();
531 1671 jmorell
                                        Font newFont;
532
533
                                        newFont = FontChooser.showDialog("Choose Font", labelFont);
534
535
                                if (newFont == null) {
536
                                    return;
537
                                }
538
539
                                labelFont = newFont;
540
                                updateControls();
541
542
543
                                }
544
                        });
545
546
                }
547
                return jButton;
548
        }
549
550
        /**
551

552
         * This method initializes jLabel4
553

554
         *
555

556
         * @return javax.swing.JLabel
557

558
         */
559
        private javax.swing.JLabel getJLabel4() {
560
                if (jLabel4 == null) {
561
                        jLabel4 = new javax.swing.JLabel();
562 3035 fjp
                        jLabel4.setBounds(311, 88, 133, 23);
563 1671 jmorell
                        jLabel4.setText(PluginServices.getText(this,"color_texto"));
564
                }
565
                return jLabel4;
566
        }
567
        /* (non-Javadoc)
568
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
569
         */
570
        public Legend getLegend() {
571 2584 caballero
                updateValuesFromControls(m_Renderer);
572 1671 jmorell
                return m_Renderer;
573
        }
574 3035 fjp
    /**
575
     * This method initializes jComboBox1
576
     *
577
     * @return javax.swing.JComboBox
578
     */
579
    private JComboBox getJComboBoxRotationField() {
580
            if (jComboBoxRotationField == null) {
581
                    jComboBoxRotationField = new JComboBox();
582
                    jComboBoxRotationField.setBounds(175, 111, 110, 19);
583
            }
584
            return jComboBoxRotationField;
585
    }
586
    /**
587
     * This method initializes jCheckBox1
588
     *
589
     * @return javax.swing.JCheckBox
590
     */
591
    private JCheckBox getJCheckBoxTextOnly() {
592
            if (jCheckBoxTextOnly == null) {
593
                    jCheckBoxTextOnly = new JCheckBox();
594
                    jCheckBoxTextOnly.setBounds(315, 171, 133, 22);
595
                    jCheckBoxTextOnly.setText("Dibujar solo el texto");
596
            }
597
            return jCheckBoxTextOnly;
598
    }
599 1671 jmorell
600
        }  //  @jve:visual-info  decl-index=0 visual-constraint="10,10"