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
/*
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.FLyrVect;
63
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
import com.iver.cit.gvsig.gui.dialogs.FontChooser;
68
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
69

    
70
import javax.swing.JComboBox;
71
import javax.swing.JLabel;
72
import javax.swing.JCheckBox;
73

    
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
        //private javax.swing.JLabel jLabel = null;
92
        private javax.swing.JCheckBox jCheckBox = null;
93
        private javax.swing.JLabel jLabel1 = null;
94
        private javax.swing.JComboBox jComboBoxTextField = null;
95
        private javax.swing.JLabel jLabel2 = null;
96
        private javax.swing.JComboBox jComboBoxHeightField = null;
97
        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
        //private JPanel parent;
107
        private javax.swing.JLabel jLabel4 = null;
108

    
109

    
110
    private JComboBox jComboBoxRotationField = null;
111

    
112

    
113
    private JLabel jLabel = null;
114

    
115

    
116
    private JCheckBox jCheckBoxTextOnly = null;
117
        /**
118
         * This is the default constructor
119
         */
120
        public FPanelLegendLabels(JPanel parent) {
121
                super();
122
                //this.parent = parent;
123
                initialize();
124
        }
125
        /**
126
         * This method initializes this
127
         * 
128
         * @return void
129
         */
130
        private  void initialize() {
131
                jLabel = new JLabel();
132
                jLabel.setBounds(30, 110, 138, 18);
133
                jLabel.setText("Campo de rotaci?n");
134
                this.setLayout(null);
135
                this.setSize(454, 230);
136
                this.add(getJCheckBoxTextOnly(), null);
137
                this.add(jLabel, null);
138
                this.add(getJComboBoxRotationField(), null);
139
                this.add(getJCheckBox(), null);
140
                this.add(getJLabel1(), null);
141
                this.add(getJComboBoxTextField(), null);
142
                this.add(getJLabel2(), null);
143
                this.add(getJComboBoxHeightField(), null);
144
                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
                m_colorChooser.setBounds(312, 115, 99, 34);
153
                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
                getJComboBoxTextField().getModel().setSelectedItem(m_Renderer.getLabelField());
169
        getJComboBoxHeightField().getModel().setSelectedItem(m_Renderer.getLabelHeightField());
170
        getJComboBoxRotationField().getModel().setSelectedItem(m_Renderer.getLabelRotationField());
171
                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
        getJCheckBoxTextOnly().setSelected(!m_FSymbol.isShapeVisible());
198
                getJTextField().setText("" + 
199
                                m_FSymbol.getFontSize());
200

    
201
                
202
        }
203

    
204
        private void updateControls() {
205
                getJComboBoxTextField().setEnabled(getJCheckBox().isSelected());
206
                getJComboBoxHeightField().setEnabled(getJCheckBox().isSelected());
207
        getJComboBoxRotationField().setEnabled(getJCheckBox().isSelected());
208
                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
        public void updateValuesFromControls(VectorialLegend l) {
220
                if (getJCheckBox().isSelected())
221
                {
222
            m_FSymbol = l.getDefaultSymbol();
223
            m_FSymbol.setFont(labelFont);
224
                        l.setLabelField((String) getJComboBoxTextField().getSelectedItem());
225
                        l.setLabelHeightField((String) getJComboBoxHeightField().getSelectedItem());
226
            l.setLabelRotationField((String) getJComboBoxRotationField().getSelectedItem());
227
                        m_FSymbol.setFontColor(m_colorChooser.getColor());
228
                        //m_FSymbol.setSymbolType(m_Renderer.getShapeType());
229
                        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
                        }
243
            m_FSymbol.setShapeVisible(true);
244
            if (getJCheckBoxTextOnly().isSelected())
245
                m_FSymbol.setShapeVisible(false);
246
            
247
                        l.setDefaultSymbol(m_FSymbol);
248
            // System.out.println("Color punto 3 " + m_FSymbol.getColor().toString());
249
                }
250
                else
251
                {
252
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
253
                        // ha de ser null
254
                        l.setLabelField(null);
255
                }
256
        }
257

    
258
        
259
        
260
        
261
        private void fillFieldNames() {
262

    
263
                SelectableDataSource rs;
264
                try {
265
                        // rs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr);
266
                        rs = ((FLyrVect)m_lyr).getRecordset();
267
                        String[] nomFields;
268
            ArrayList nomNumericFields = new ArrayList();
269
                        nomFields = new String[rs.getFieldCount()];
270
                        for (int i = 0; i < rs.getFieldCount(); i++) {
271
                                nomFields[i] = rs.getFieldName(i).trim();
272
                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
                        }
278

    
279
                        DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
280
                        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
        
286
                } catch (DriverException e) {
287
                        e.printStackTrace();
288
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
289
                        e.printStackTrace();
290
                }
291
        }
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
                        jCheckBox.setBounds(28, 22, 152, 23);
308
                        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
                        jLabel1.setBounds(29, 53, 139, 21);
334
                }
335
                return jLabel1;
336
        }
337

    
338
        /**
339

340
         * This method initializes jComboBox        
341

342
         *         
343

344
         * @return javax.swing.JComboBox        
345

346
         */    
347
        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
                }
353
                return jComboBoxTextField;
354
        }
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
                        jLabel2.setBounds(29, 81, 137, 21);
369
                        jLabel2.setText(PluginServices.getText(this,"campo_altura_texto"));
370
                        jLabel2.setVisible(true);
371
                }
372
                return jLabel2;
373
        }
374

    
375
        /**
376

377
         * This method initializes jComboBox1        
378

379
         *         
380

381
         * @return javax.swing.JComboBox        
382

383
         */    
384
        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
                }
391
                return jComboBoxHeightField;
392
        }
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
                        jLabel3.setVisible(false);
509
                }
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
                        jButton.setBounds(314, 54, 111, 29);
526
                        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
                                        //JButton origen = (JButton) e.getSource();
531
                                        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
                        jLabel4.setBounds(311, 88, 133, 23);
563
                        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
                updateValuesFromControls(m_Renderer);
572
                return m_Renderer;
573
        }
574
    /**
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

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