Statistics
| Revision:

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

History | View | Annotate | Download (13.3 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

    
50
import javax.swing.ButtonGroup;
51
import javax.swing.DefaultComboBoxModel;
52
import javax.swing.JPanel;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.cit.gvsig.ProjectExtension;
56
import com.iver.cit.gvsig.fmap.DriverException;
57
import com.iver.cit.gvsig.fmap.core.FShape;
58
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
61
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
63
import com.iver.cit.gvsig.fmap.rendering.Legend;
64
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
65
import com.iver.cit.gvsig.gui.Dialogs.FontChooser;
66
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
67

    
68
/**
69
 * @author fjp
70
 *
71
 */
72
public class FPanelLegendLabels extends JPanel implements ILegendPanel {
73
        private static final Font DEFAULT_FONT = 
74
                  new Font("SansSerif", Font.PLAIN, 9);
75
        
76
        
77
        // private TOC m_TOC;
78
        private VectorialLegend m_Renderer;
79
        private ClassifiableVectorial m_lyr;
80
        private FSymbol m_FSymbol;
81
        
82
        private ColorChooserPanel m_colorChooser = new ColorChooserPanel();
83
        
84
        
85
        //private javax.swing.JLabel jLabel = null;
86
        private javax.swing.JCheckBox jCheckBox = null;
87
        private javax.swing.JLabel jLabel1 = null;
88
        private javax.swing.JComboBox jComboBox = null;
89
        private javax.swing.JLabel jLabel2 = null;
90
        private javax.swing.JComboBox jComboBox1 = null;
91
        private javax.swing.JPanel jPanel = null;
92
        private javax.swing.JTextField jTextField = null;
93
        private javax.swing.JRadioButton jRadioButton = null;
94
        private javax.swing.JRadioButton jRadioButton1 = null;
95
        private FPreviewSymbol fPreviewSymbol = null;
96
        private javax.swing.JLabel jLabel3 = null;
97
        private javax.swing.JButton jButton = null;
98
        
99
        private Font labelFont = DEFAULT_FONT;
100
        //private JPanel parent;
101
        private javax.swing.JLabel jLabel4 = null;
102
        /**
103
         * This is the default constructor
104
         */
105
        public FPanelLegendLabels(JPanel parent) {
106
                super();
107
                //this.parent = parent;
108
                initialize();
109
        }
110
        /**
111
         * This method initializes this
112
         * 
113
         * @return void
114
         */
115
        private  void initialize() {
116
                this.setLayout(null);
117
                this.setSize(454, 230);
118
                this.add(getJCheckBox(), null);
119
                this.add(getJLabel1(), null);
120
                this.add(getJComboBox(), null);
121
                this.add(getJLabel2(), null);
122
                this.add(getJComboBox1(), null);
123
                this.add(getJPanel(), null);
124
                this.add(getFPreviewSymbol(), null);
125
                this.add(getJLabel3(), null);
126
                this.add(getJButton(), null);
127
                
128
                // m_colorChooser = new ColorChooserPanel();
129
                // m_colorChooser.setColor(Color.RED);
130
                m_colorChooser.setAlpha(255);
131
                m_colorChooser.setBounds(190, 103, 99, 34);
132
                m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
133
                        public void actionPerformed(ActionEvent e) {
134
                                updateControls();
135
                        }
136
                }); 
137
                this.add(getJLabel4(), null);
138
                this.add(m_colorChooser);
139
                
140
        }
141
        public void setLayer(FLayer lyr, Legend r)
142
        {
143
                m_lyr = (ClassifiableVectorial) lyr;
144
                m_Renderer = (VectorialLegend)r;                
145

    
146
                fillFieldNames();                
147
                getJComboBox().getModel().setSelectedItem(m_Renderer.getLabelField());
148
                setFSymbol(r.getDefaultSymbol());
149
                
150
                if (m_Renderer.getLabelField() != null)
151
                        getJCheckBox().setSelected(true);
152
                else
153
                        getJCheckBox().setSelected(false);
154

    
155
                
156
                
157
                
158
        }
159
        public void setFSymbol(FSymbol sym)
160
        {
161
                if (sym == null)
162
                {
163
                        m_FSymbol = new FSymbol(FShape.MULTI);
164
                }
165
                else
166
                        m_FSymbol = sym;
167
                
168
                if (m_FSymbol.getFontColor()!=null){
169
                        m_colorChooser.setColor(m_FSymbol.getFontColor());
170
                }
171
                fPreviewSymbol.setSymbol(m_FSymbol);
172
                
173
                getJRadioButton1().setSelected(!m_FSymbol.isFontSizeInPixels());
174
                getJTextField().setText("" + 
175
                                m_FSymbol.getFontSize());
176

    
177
                
178
        }
179

    
180
        private void updateControls() {
181
                getJComboBox().setEnabled(getJCheckBox().isSelected());
182
                getJComboBox1().setEnabled(getJCheckBox().isSelected());
183
                getJRadioButton().setEnabled(getJCheckBox().isSelected());
184
                getJRadioButton1().setEnabled(getJCheckBox().isSelected());
185
                getJTextField().setEnabled(getJCheckBox().isSelected());
186
                if (getJCheckBox().isSelected())
187
                {
188
                        FSymbol sym = m_FSymbol;
189
                        sym.setFont(labelFont);
190
                        sym.setFontColor(m_colorChooser.getColor());
191
                        fPreviewSymbol.setSymbol(sym);
192
                }
193
        }
194
        public void updateValuesFromControls(VectorialLegend l) {
195
                if (getJCheckBox().isSelected())
196
                {
197
            m_FSymbol = l.getDefaultSymbol();
198
            m_FSymbol.setFont(labelFont);
199
                        l.setLabelField((String) getJComboBox().getSelectedItem());
200
                        ///m_Renderer.setLabelHeightField((String) getJComboBox1().getSelectedItem());
201
                        m_FSymbol.setFontColor(m_colorChooser.getColor());
202
                        //m_FSymbol.setSymbolType(m_Renderer.getShapeType());
203
                        if (!getJRadioButton().isSelected())
204
                        {
205
                                float sizeUnits = Float.parseFloat(getJTextField().getText());                                
206
                                m_FSymbol.setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
207
                                m_FSymbol.setFontSizeInPixels(false);
208
                        }
209
                        else
210
                        {                                
211
                                float sizePoints = Float.parseFloat(getJTextField().getText());
212
                                m_FSymbol.setFont(labelFont);
213
                                m_FSymbol.setFont(labelFont.deriveFont(sizePoints));
214
                                m_FSymbol.setFontSize(sizePoints);
215
                                m_FSymbol.setFontSizeInPixels(true);
216
                        }                
217
                        l.setDefaultSymbol(m_FSymbol);
218
            // System.out.println("Color punto 3 " + m_FSymbol.getColor().toString());
219
                }
220
                else
221
                {
222
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
223
                        // ha de ser null
224
                        l.setLabelField(null);
225
                }
226
        }
227

    
228
        
229
        
230
        
231
        private void fillFieldNames() {
232

    
233
                SelectableDataSource rs;
234
                try {
235
                        rs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr);
236
                        String[] nomFields;
237
                        nomFields = new String[rs.getFieldCount()];
238
                        for (int i = 0; i < rs.getFieldCount(); i++) {
239
                                nomFields[i] = rs.getFieldName(i).trim();
240
                        }
241

    
242
                        DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
243
                        getJComboBox().setModel(cM_labelField);
244
                        DefaultComboBoxModel cM_heightField = new DefaultComboBoxModel(nomFields);
245
                        getJComboBox1().setModel(cM_heightField);
246
        
247
                } catch (DriverException e) {
248
                        e.printStackTrace();
249
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
250
                        e.printStackTrace();
251
                }
252
        }
253
                
254
        
255
        /**
256

257
         * This method initializes jCheckBox        
258

259
         *         
260

261
         * @return javax.swing.JCheckBox        
262

263
         */    
264
        private javax.swing.JCheckBox getJCheckBox() {
265
                if (jCheckBox == null) {
266
                        jCheckBox = new javax.swing.JCheckBox();
267
                        jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado"));
268
                        jCheckBox.setBounds(28, 22, 152, 23);
269
                        jCheckBox.addItemListener(new java.awt.event.ItemListener() { 
270

    
271
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
272
                                        updateControls();                                        
273

    
274
                                }
275
                        });
276

    
277
                }
278
                return jCheckBox;
279
        }
280

    
281
        /**
282

283
         * This method initializes jLabel1        
284

285
         *         
286

287
         * @return javax.swing.JLabel        
288

289
         */    
290
        private javax.swing.JLabel getJLabel1() {
291
                if (jLabel1 == null) {
292
                        jLabel1 = new javax.swing.JLabel();
293
                        jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado"));
294
                        jLabel1.setBounds(29, 53, 139, 21);
295
                }
296
                return jLabel1;
297
        }
298

    
299
        /**
300

301
         * This method initializes jComboBox        
302

303
         *         
304

305
         * @return javax.swing.JComboBox        
306

307
         */    
308
        private javax.swing.JComboBox getJComboBox() {
309
                if (jComboBox == null) {
310
                        jComboBox = new javax.swing.JComboBox();
311
                        jComboBox.setBounds(175, 52, 110, 19);
312
                        jComboBox.setEnabled(false);
313
                }
314
                return jComboBox;
315
        }
316

    
317
        /**
318

319
         * This method initializes jLabel2        
320

321
         *         
322

323
         * @return javax.swing.JLabel        
324

325
         */    
326
        private javax.swing.JLabel getJLabel2() {
327
                if (jLabel2 == null) {
328
                        jLabel2 = new javax.swing.JLabel();
329
                        jLabel2.setBounds(298, 190, 137, 21);
330
                        jLabel2.setText(PluginServices.getText(this,"campo_altura_texto"));
331
                        jLabel2.setVisible(false);
332
                }
333
                return jLabel2;
334
        }
335

    
336
        /**
337

338
         * This method initializes jComboBox1        
339

340
         *         
341

342
         * @return javax.swing.JComboBox        
343

344
         */    
345
        private javax.swing.JComboBox getJComboBox1() {
346
                if (jComboBox1 == null) {
347
                        jComboBox1 = new javax.swing.JComboBox();
348
                        jComboBox1.setBounds(175, 82, 110, 18);
349
                        jComboBox1.setEnabled(false);
350
                        jComboBox1.setVisible(false);
351
                }
352
                return jComboBox1;
353
        }
354

    
355
        /**
356

357
         * This method initializes jPanel        
358

359
         *         
360

361
         * @return javax.swing.JPanel        
362

363
         */    
364
        private javax.swing.JPanel getJPanel() {
365
                if (jPanel == null) {
366
                        jPanel = new javax.swing.JPanel();
367
                        jPanel.setLayout(null);
368
                        jPanel.setBounds(29, 136, 258, 84);
369
                        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));
370
                        ButtonGroup jButtonGroup = new ButtonGroup();
371
                        jButtonGroup.add(getJRadioButton1());
372
                        jButtonGroup.add(getJRadioButton());
373
                        jPanel.add(getJRadioButton1(), null);
374
                        jPanel.add(getJRadioButton(), null);
375
                        jPanel.add(getJTextField(), null);
376
                }
377
                return jPanel;
378
        }
379

    
380
        /**
381

382
         * This method initializes jTextField        
383

384
         *         
385

386
         * @return javax.swing.JTextField        
387

388
         */    
389
        private javax.swing.JTextField getJTextField() {
390
                if (jTextField == null) {
391
                        jTextField = new javax.swing.JTextField();
392
                        jTextField.setBounds(26, 32, 76, 21);
393
                        jTextField.setEnabled(false);
394
                        jTextField.setText("10");
395
                }
396
                return jTextField;
397
        }
398

    
399
/**
400

401
         * This method initializes jRadioButton        
402

403
         *         
404

405
         * @return javax.swing.JRadioButton        
406

407
         */    
408
        private javax.swing.JRadioButton getJRadioButton() {
409
                if (jRadioButton == null) {
410
                        jRadioButton = new javax.swing.JRadioButton();
411
                        jRadioButton.setText(PluginServices.getText(this,"En_pixels"));
412
                        jRadioButton.setBounds(145, 44, 100, 23);
413
                        jRadioButton.setEnabled(false);
414
                        jRadioButton.setSelected(true);
415
                }
416
                return jRadioButton;
417
        }
418

    
419
        /**
420

421
         * This method initializes jRadioButton1        
422

423
         *         
424

425
         * @return javax.swing.JRadioButton        
426

427
         */    
428
        private javax.swing.JRadioButton getJRadioButton1() {
429
                if (jRadioButton1 == null) {
430
                        jRadioButton1 = new javax.swing.JRadioButton();
431
                        jRadioButton1.setText(PluginServices.getText(this,"En_metros"));
432
                        jRadioButton1.setBounds(145, 16, 100, 23);                        
433
                        jRadioButton1.setEnabled(false);
434
                }
435
                return jRadioButton1;
436
        }
437

    
438
        /**
439

440
         * This method initializes fPreviewSymbol        
441

442
         *         
443

444
         * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol        
445

446
         */    
447
        public FPreviewSymbol getFPreviewSymbol() {
448
                if (fPreviewSymbol == null) {
449
                        fPreviewSymbol = new FPreviewSymbol();
450
                        fPreviewSymbol.setBounds(311, 53, 134, 77);
451
                }
452
                return fPreviewSymbol;
453
        }
454

    
455
        /**
456

457
         * This method initializes jLabel3        
458

459
         *         
460

461
         * @return javax.swing.JLabel        
462

463
         */    
464
        private javax.swing.JLabel getJLabel3() {
465
                if (jLabel3 == null) {
466
                        jLabel3 = new javax.swing.JLabel();
467
                        jLabel3.setBounds(312, 28, 100, 18);
468
                        jLabel3.setText(PluginServices.getText(this,"Previsualizacion"));
469
                        jLabel3.setVisible(false);
470
                }
471
                return jLabel3;
472
        }
473

    
474
        /**
475

476
         * This method initializes jButton        
477

478
         *         
479

480
         * @return javax.swing.JButton        
481

482
         */    
483
        private javax.swing.JButton getJButton() {
484
                if (jButton == null) {
485
                        jButton = new javax.swing.JButton();
486
                        jButton.setBounds(29, 77, 111, 29);
487
                        jButton.setText(PluginServices.getText(this,"fuente")+"...");
488
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
489

    
490
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
491
                                        //JButton origen = (JButton) e.getSource();
492
                                        Font newFont;
493
                                        
494
                                        newFont = FontChooser.showDialog("Choose Font", labelFont);                                                
495
                                        
496
                                if (newFont == null) {
497
                                    return;
498
                                }
499
                                
500
                                labelFont = newFont;
501
                                updateControls();
502

    
503

    
504
                                }
505
                        });
506

    
507
                }
508
                return jButton;
509
        }
510

    
511
        /**
512

513
         * This method initializes jLabel4        
514

515
         *         
516

517
         * @return javax.swing.JLabel        
518

519
         */    
520
        private javax.swing.JLabel getJLabel4() {
521
                if (jLabel4 == null) {
522
                        jLabel4 = new javax.swing.JLabel();
523
                        jLabel4.setBounds(29, 109, 133, 23);
524
                        jLabel4.setText(PluginServices.getText(this,"color_texto"));
525
                }
526
                return jLabel4;
527
        }
528
        /* (non-Javadoc)
529
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
530
         */
531
        public Legend getLegend() {
532
                updateValuesFromControls(m_Renderer);
533
                return m_Renderer;
534
        }
535

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