Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FPanelLegendLabels.java @ 3035

History | View | Annotate | Download (15.8 KB)

1
/*
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
import java.sql.Types;
50
import java.util.ArrayList;
51

    
52
import javax.swing.ButtonGroup;
53
import javax.swing.DefaultComboBoxModel;
54
import javax.swing.JPanel;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.ProjectExtension;
58
import com.iver.cit.gvsig.fmap.DriverException;
59
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
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
64
import com.iver.cit.gvsig.fmap.rendering.Legend;
65
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
66
import com.iver.cit.gvsig.gui.Dialogs.FontChooser;
67
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
68
import javax.swing.JComboBox;
69
import javax.swing.JLabel;
70
import javax.swing.JCheckBox;
71

    
72
/**
73
 * @author fjp
74
 *
75
 */
76
public class FPanelLegendLabels extends JPanel implements ILegendPanel {
77
        private static final Font DEFAULT_FONT = 
78
                  new Font("SansSerif", Font.PLAIN, 9);
79
        
80
        
81
        // private TOC m_TOC;
82
        private VectorialLegend m_Renderer;
83
        private ClassifiableVectorial m_lyr;
84
        private FSymbol m_FSymbol;
85
        
86
        private ColorChooserPanel m_colorChooser = new ColorChooserPanel();
87
        
88
        
89
        //private javax.swing.JLabel jLabel = null;
90
        private javax.swing.JCheckBox jCheckBox = null;
91
        private javax.swing.JLabel jLabel1 = null;
92
        private javax.swing.JComboBox jComboBoxTextField = null;
93
        private javax.swing.JLabel jLabel2 = null;
94
        private javax.swing.JComboBox jComboBoxHeightField = null;
95
        private javax.swing.JPanel jPanel = null;
96
        private javax.swing.JTextField jTextField = null;
97
        private javax.swing.JRadioButton jRadioButton = null;
98
        private javax.swing.JRadioButton jRadioButton1 = null;
99
        private FPreviewSymbol fPreviewSymbol = null;
100
        private javax.swing.JLabel jLabel3 = null;
101
        private javax.swing.JButton jButton = null;
102
        
103
        private Font labelFont = DEFAULT_FONT;
104
        //private JPanel parent;
105
        private javax.swing.JLabel jLabel4 = null;
106

    
107

    
108
    private JComboBox jComboBoxRotationField = null;
109

    
110

    
111
    private JLabel jLabel = null;
112

    
113

    
114
    private JCheckBox jCheckBoxTextOnly = null;
115
        /**
116
         * This is the default constructor
117
         */
118
        public FPanelLegendLabels(JPanel parent) {
119
                super();
120
                //this.parent = parent;
121
                initialize();
122
        }
123
        /**
124
         * This method initializes this
125
         * 
126
         * @return void
127
         */
128
        private  void initialize() {
129
                jLabel = new JLabel();
130
                jLabel.setBounds(30, 110, 138, 18);
131
                jLabel.setText("Campo de rotaci?n");
132
                this.setLayout(null);
133
                this.setSize(454, 230);
134
                this.add(getJCheckBoxTextOnly(), null);
135
                this.add(jLabel, null);
136
                this.add(getJComboBoxRotationField(), null);
137
                this.add(getJCheckBox(), null);
138
                this.add(getJLabel1(), null);
139
                this.add(getJComboBoxTextField(), null);
140
                this.add(getJLabel2(), null);
141
                this.add(getJComboBoxHeightField(), null);
142
                this.add(getJPanel(), null);
143
                this.add(getFPreviewSymbol(), null);
144
                this.add(getJLabel3(), null);
145
                this.add(getJButton(), null);
146
                
147
                // m_colorChooser = new ColorChooserPanel();
148
                // m_colorChooser.setColor(Color.RED);
149
                m_colorChooser.setAlpha(255);
150
                m_colorChooser.setBounds(312, 115, 99, 34);
151
                m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
152
                        public void actionPerformed(ActionEvent e) {
153
                                updateControls();
154
                        }
155
                }); 
156
                this.add(getJLabel4(), null);
157
                this.add(m_colorChooser);
158
                
159
        }
160
        public void setLayer(FLayer lyr, Legend r)
161
        {
162
                m_lyr = (ClassifiableVectorial) lyr;
163
                m_Renderer = (VectorialLegend)r;                
164

    
165
                fillFieldNames();                
166
                getJComboBoxTextField().getModel().setSelectedItem(m_Renderer.getLabelField());
167
        getJComboBoxHeightField().getModel().setSelectedItem(m_Renderer.getLabelHeightField());
168
        getJComboBoxRotationField().getModel().setSelectedItem(m_Renderer.getLabelRotationField());
169
                setFSymbol(r.getDefaultSymbol());
170
                
171
                if (m_Renderer.getLabelField() != null)
172
                        getJCheckBox().setSelected(true);
173
                else
174
                        getJCheckBox().setSelected(false);
175

    
176
                
177
                
178
                
179
        }
180
        public void setFSymbol(FSymbol sym)
181
        {
182
                if (sym == null)
183
                {
184
                        m_FSymbol = new FSymbol(FShape.MULTI);
185
                }
186
                else
187
                        m_FSymbol = sym;
188
                
189
                if (m_FSymbol.getFontColor()!=null){
190
                        m_colorChooser.setColor(m_FSymbol.getFontColor());
191
                }
192
                fPreviewSymbol.setSymbol(m_FSymbol);
193
                
194
                getJRadioButton1().setSelected(!m_FSymbol.isFontSizeInPixels());
195
        getJCheckBoxTextOnly().setSelected(!m_FSymbol.isShapeVisible());
196
                getJTextField().setText("" + 
197
                                m_FSymbol.getFontSize());
198

    
199
                
200
        }
201

    
202
        private void updateControls() {
203
                getJComboBoxTextField().setEnabled(getJCheckBox().isSelected());
204
                getJComboBoxHeightField().setEnabled(getJCheckBox().isSelected());
205
        getJComboBoxRotationField().setEnabled(getJCheckBox().isSelected());
206
                getJRadioButton().setEnabled(getJCheckBox().isSelected());
207
                getJRadioButton1().setEnabled(getJCheckBox().isSelected());
208
                getJTextField().setEnabled(getJCheckBox().isSelected());
209
                if (getJCheckBox().isSelected())
210
                {
211
                        FSymbol sym = m_FSymbol;
212
                        sym.setFont(labelFont);
213
                        sym.setFontColor(m_colorChooser.getColor());
214
                        fPreviewSymbol.setSymbol(sym);
215
                }
216
        }
217
        public void updateValuesFromControls(VectorialLegend l) {
218
                if (getJCheckBox().isSelected())
219
                {
220
            m_FSymbol = l.getDefaultSymbol();
221
            m_FSymbol.setFont(labelFont);
222
                        l.setLabelField((String) getJComboBoxTextField().getSelectedItem());
223
                        l.setLabelHeightField((String) getJComboBoxHeightField().getSelectedItem());
224
            l.setLabelRotationField((String) getJComboBoxRotationField().getSelectedItem());
225
                        m_FSymbol.setFontColor(m_colorChooser.getColor());
226
                        //m_FSymbol.setSymbolType(m_Renderer.getShapeType());
227
                        if (!getJRadioButton().isSelected())
228
                        {
229
                                float sizeUnits = Float.parseFloat(getJTextField().getText());                                
230
                                m_FSymbol.setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
231
                                m_FSymbol.setFontSizeInPixels(false);
232
                        }
233
                        else
234
                        {                                
235
                                float sizePoints = Float.parseFloat(getJTextField().getText());
236
                                m_FSymbol.setFont(labelFont);
237
                                m_FSymbol.setFont(labelFont.deriveFont(sizePoints));
238
                                m_FSymbol.setFontSize(sizePoints);
239
                                m_FSymbol.setFontSizeInPixels(true);
240
                        }
241
            m_FSymbol.setShapeVisible(true);
242
            if (getJCheckBoxTextOnly().isSelected())
243
                m_FSymbol.setShapeVisible(false);
244
            
245
                        l.setDefaultSymbol(m_FSymbol);
246
            // System.out.println("Color punto 3 " + m_FSymbol.getColor().toString());
247
                }
248
                else
249
                {
250
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
251
                        // ha de ser null
252
                        l.setLabelField(null);
253
                }
254
        }
255

    
256
        
257
        
258
        
259
        private void fillFieldNames() {
260

    
261
                SelectableDataSource rs;
262
                try {
263
                        rs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr);
264
                        String[] nomFields;
265
            ArrayList nomNumericFields = new ArrayList();
266
                        nomFields = new String[rs.getFieldCount()];
267
                        for (int i = 0; i < rs.getFieldCount(); i++) {
268
                                nomFields[i] = rs.getFieldName(i).trim();
269
                if ((rs.getFieldType(i) == Types.FLOAT)
270
                   || (rs.getFieldType(i) == Types.BIGINT)
271
                   || (rs.getFieldType(i) == Types.DOUBLE)
272
                   || (rs.getFieldType(i) == Types.INTEGER))
273
                    nomNumericFields.add(nomFields[i]);
274
                        }
275

    
276
                        DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
277
                        getJComboBoxTextField().setModel(cM_labelField);
278
                        DefaultComboBoxModel cM_HeightField = new DefaultComboBoxModel(nomNumericFields.toArray(new String[0]));
279
                        getJComboBoxHeightField().setModel(cM_HeightField);
280
            DefaultComboBoxModel cM_RotationField = new DefaultComboBoxModel(nomNumericFields.toArray(new String[0]));
281
            getJComboBoxRotationField().setModel(cM_RotationField);
282
        
283
                } catch (DriverException e) {
284
                        e.printStackTrace();
285
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
286
                        e.printStackTrace();
287
                }
288
        }
289
                
290
        
291
        /**
292

293
         * This method initializes jCheckBox        
294

295
         *         
296

297
         * @return javax.swing.JCheckBox        
298

299
         */    
300
        private javax.swing.JCheckBox getJCheckBox() {
301
                if (jCheckBox == null) {
302
                        jCheckBox = new javax.swing.JCheckBox();
303
                        jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado"));
304
                        jCheckBox.setBounds(28, 22, 152, 23);
305
                        jCheckBox.addItemListener(new java.awt.event.ItemListener() { 
306

    
307
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
308
                                        updateControls();                                        
309

    
310
                                }
311
                        });
312

    
313
                }
314
                return jCheckBox;
315
        }
316

    
317
        /**
318

319
         * This method initializes jLabel1        
320

321
         *         
322

323
         * @return javax.swing.JLabel        
324

325
         */    
326
        private javax.swing.JLabel getJLabel1() {
327
                if (jLabel1 == null) {
328
                        jLabel1 = new javax.swing.JLabel();
329
                        jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado"));
330
                        jLabel1.setBounds(29, 53, 139, 21);
331
                }
332
                return jLabel1;
333
        }
334

    
335
        /**
336

337
         * This method initializes jComboBox        
338

339
         *         
340

341
         * @return javax.swing.JComboBox        
342

343
         */    
344
        private javax.swing.JComboBox getJComboBoxTextField() {
345
                if (jComboBoxTextField == null) {
346
                        jComboBoxTextField = new javax.swing.JComboBox();
347
                        jComboBoxTextField.setBounds(175, 52, 110, 19);
348
                        jComboBoxTextField.setEnabled(false);
349
                }
350
                return jComboBoxTextField;
351
        }
352

    
353
        /**
354

355
         * This method initializes jLabel2        
356

357
         *         
358

359
         * @return javax.swing.JLabel        
360

361
         */    
362
        private javax.swing.JLabel getJLabel2() {
363
                if (jLabel2 == null) {
364
                        jLabel2 = new javax.swing.JLabel();
365
                        jLabel2.setBounds(29, 81, 137, 21);
366
                        jLabel2.setText(PluginServices.getText(this,"campo_altura_texto"));
367
                        jLabel2.setVisible(true);
368
                }
369
                return jLabel2;
370
        }
371

    
372
        /**
373

374
         * This method initializes jComboBox1        
375

376
         *         
377

378
         * @return javax.swing.JComboBox        
379

380
         */    
381
        private javax.swing.JComboBox getJComboBoxHeightField() {
382
                if (jComboBoxHeightField == null) {
383
                        jComboBoxHeightField = new javax.swing.JComboBox();
384
                        jComboBoxHeightField.setBounds(175, 82, 110, 18);
385
                        jComboBoxHeightField.setEnabled(true);
386
                        jComboBoxHeightField.setVisible(true);
387
                }
388
                return jComboBoxHeightField;
389
        }
390

    
391
        /**
392

393
         * This method initializes jPanel        
394

395
         *         
396

397
         * @return javax.swing.JPanel        
398

399
         */    
400
        private javax.swing.JPanel getJPanel() {
401
                if (jPanel == null) {
402
                        jPanel = new javax.swing.JPanel();
403
                        jPanel.setLayout(null);
404
                        jPanel.setBounds(29, 136, 258, 84);
405
                        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));
406
                        ButtonGroup jButtonGroup = new ButtonGroup();
407
                        jButtonGroup.add(getJRadioButton1());
408
                        jButtonGroup.add(getJRadioButton());
409
                        jPanel.add(getJRadioButton1(), null);
410
                        jPanel.add(getJRadioButton(), null);
411
                        jPanel.add(getJTextField(), null);
412
                }
413
                return jPanel;
414
        }
415

    
416
        /**
417

418
         * This method initializes jTextField        
419

420
         *         
421

422
         * @return javax.swing.JTextField        
423

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

    
435
/**
436

437
         * This method initializes jRadioButton        
438

439
         *         
440

441
         * @return javax.swing.JRadioButton        
442

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

    
455
        /**
456

457
         * This method initializes jRadioButton1        
458

459
         *         
460

461
         * @return javax.swing.JRadioButton        
462

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

    
474
        /**
475

476
         * This method initializes fPreviewSymbol        
477

478
         *         
479

480
         * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol        
481

482
         */    
483
        public FPreviewSymbol getFPreviewSymbol() {
484
                if (fPreviewSymbol == null) {
485
                        fPreviewSymbol = new FPreviewSymbol();
486
                        fPreviewSymbol.setBounds(311, 53, 134, 77);
487
                }
488
                return fPreviewSymbol;
489
        }
490

    
491
        /**
492

493
         * This method initializes jLabel3        
494

495
         *         
496

497
         * @return javax.swing.JLabel        
498

499
         */    
500
        private javax.swing.JLabel getJLabel3() {
501
                if (jLabel3 == null) {
502
                        jLabel3 = new javax.swing.JLabel();
503
                        jLabel3.setBounds(312, 28, 100, 18);
504
                        jLabel3.setText(PluginServices.getText(this,"Previsualizacion"));
505
                        jLabel3.setVisible(false);
506
                }
507
                return jLabel3;
508
        }
509

    
510
        /**
511

512
         * This method initializes jButton        
513

514
         *         
515

516
         * @return javax.swing.JButton        
517

518
         */    
519
        private javax.swing.JButton getJButton() {
520
                if (jButton == null) {
521
                        jButton = new javax.swing.JButton();
522
                        jButton.setBounds(314, 54, 111, 29);
523
                        jButton.setText(PluginServices.getText(this,"fuente")+"...");
524
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
525

    
526
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
527
                                        //JButton origen = (JButton) e.getSource();
528
                                        Font newFont;
529
                                        
530
                                        newFont = FontChooser.showDialog("Choose Font", labelFont);                                                
531
                                        
532
                                if (newFont == null) {
533
                                    return;
534
                                }
535
                                
536
                                labelFont = newFont;
537
                                updateControls();
538

    
539

    
540
                                }
541
                        });
542

    
543
                }
544
                return jButton;
545
        }
546

    
547
        /**
548

549
         * This method initializes jLabel4        
550

551
         *         
552

553
         * @return javax.swing.JLabel        
554

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

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