Statistics
| Revision:

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

History | View | Annotate | Download (11.9 KB)

1
/*
2
 * Created on 01-jun-2004
3
 *
4
 */
5
package com.iver.cit.gvsig.gui.legendmanager.panels;
6

    
7
import java.awt.Font;
8
import java.awt.event.ActionEvent;
9

    
10
import javax.swing.ButtonGroup;
11
import javax.swing.DefaultComboBoxModel;
12
import javax.swing.JButton;
13
import javax.swing.JPanel;
14

    
15
import com.hardcode.driverManager.DriverLoadException;
16
import com.hardcode.gdbms.engine.data.DriverException;
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.Utilities;
19
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
20
import com.iver.cit.gvsig.fmap.layers.FLayer;
21
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
22
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
23
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
24
import com.iver.cit.gvsig.fmap.rendering.Legend;
25
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
26
import com.iver.cit.gvsig.gui.Dialogs.FontChooser;
27
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
28

    
29
/**
30
 * @author fjp
31
 *
32
 */
33
public class FPanelLegendLabels extends JPanel implements ILegendPanel {
34
        private static final Font DEFAULT_FONT = 
35
                  new Font("SansSerif", Font.PLAIN, 9);
36
        
37
        
38
        // private TOC m_TOC;
39
        private VectorialLegend m_Renderer;
40
        private ClassifiableVectorial m_lyr;
41
        
42
        private ColorChooserPanel m_colorChooser = new ColorChooserPanel();
43
        
44
        
45
        private javax.swing.JLabel jLabel = null;
46
        private javax.swing.JCheckBox jCheckBox = null;
47
        private javax.swing.JLabel jLabel1 = null;
48
        private javax.swing.JComboBox jComboBox = null;
49
        private javax.swing.JLabel jLabel2 = null;
50
        private javax.swing.JComboBox jComboBox1 = null;
51
        private javax.swing.JPanel jPanel = null;
52
        private javax.swing.JTextField jTextField = null;
53
        private javax.swing.JRadioButton jRadioButton = null;
54
        private javax.swing.JRadioButton jRadioButton1 = null;
55
        private FPreviewSymbol fPreviewSymbol = null;
56
        private javax.swing.JLabel jLabel3 = null;
57
        private javax.swing.JButton jButton = null;
58
        
59
        private Font labelFont = DEFAULT_FONT;
60
        private JPanel parent;
61
        private javax.swing.JLabel jLabel4 = null;
62
        /**
63
         * This is the default constructor
64
         */
65
        public FPanelLegendLabels(JPanel parent) {
66
                super();
67
                this.parent = parent;
68
                initialize();
69
        }
70
        /**
71
         * This method initializes this
72
         * 
73
         * @return void
74
         */
75
        private  void initialize() {
76
                this.setLayout(null);
77
                this.setSize(454, 230);
78
                this.add(getJCheckBox(), null);
79
                this.add(getJLabel1(), null);
80
                this.add(getJComboBox(), null);
81
                this.add(getJLabel2(), null);
82
                this.add(getJComboBox1(), null);
83
                this.add(getJPanel(), null);
84
                this.add(getFPreviewSymbol(), null);
85
                this.add(getJLabel3(), null);
86
                this.add(getJButton(), null);
87
                
88
                // m_colorChooser = new ColorChooserPanel();
89
                // m_colorChooser.setColor(Color.RED);
90
                m_colorChooser.setAlpha(255);
91
                m_colorChooser.setBounds(190, 103, 99, 34);
92
                m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
93
                        public void actionPerformed(ActionEvent e) {
94
                                updateControls();
95
                        }
96
                }); 
97
                this.add(getJLabel4(), null);
98
                this.add(m_colorChooser);
99
                
100
        }
101
        public void setLayer(FLayer lyr, Legend r)
102
        {
103
                // m_TOC = t;
104
                // m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
105
                m_lyr = (ClassifiableVectorial) lyr;
106
                m_Renderer = (VectorialLegend)r;                
107

    
108
                fillFieldNames();                
109
                getJComboBox().getModel().setSelectedItem(m_Renderer.getLabelField());
110
                ///getJComboBox1().getModel().setSelectedItem(m_Renderer.getHeightField());
111
                if (m_Renderer.getDefaultSymbol().getFontColor()!=null){
112
                        m_colorChooser.setColor(m_Renderer.getDefaultSymbol().getFontColor());
113
                }
114
                fPreviewSymbol.setSymbol(m_Renderer.getDefaultSymbol());
115
                if (m_Renderer.getLabelField() != null)
116
                        getJCheckBox().setSelected(true);
117
                else
118
                        getJCheckBox().setSelected(false);
119
                
120
                getJRadioButton1().setSelected(m_Renderer.getDefaultSymbol().isFontSizeInPixels());
121
                getJTextField().setText("" + 
122
                                 m_Renderer.getDefaultSymbol().getFontSize());
123

    
124
                
125
        }
126

    
127
        private void updateControls() {
128
                getJComboBox().setEnabled(getJCheckBox().isSelected());
129
                getJComboBox1().setEnabled(getJCheckBox().isSelected());
130
                getJRadioButton().setEnabled(getJCheckBox().isSelected());
131
                getJRadioButton1().setEnabled(getJCheckBox().isSelected());
132
                getJTextField().setEnabled(getJCheckBox().isSelected());
133
                if (getJCheckBox().isSelected())
134
                {
135
                        FSymbol sym = m_Renderer.getDefaultSymbol();
136
                        sym.setFont(labelFont);
137
                        sym.setFontColor(m_colorChooser.getColor());
138
                        fPreviewSymbol.setSymbol(sym);
139
                }
140
        }
141
        private void updateValuesFromControls() {
142
                if (getJCheckBox().isSelected())
143
                {
144
                        m_Renderer.setLabelField((String) getJComboBox().getSelectedItem());
145
                        ///m_Renderer.setLabelHeightField((String) getJComboBox1().getSelectedItem());
146
                        m_Renderer.getDefaultSymbol().setFontColor(m_colorChooser.getColor());
147
                        if (getJRadioButton().isSelected())
148
                        {
149
                                float sizeUnits = Float.parseFloat(getJTextField().getText());                                
150
                                m_Renderer.getDefaultSymbol().setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
151
                                m_Renderer.getDefaultSymbol().setFontSizeInPixels(false);
152
                        }
153
                        else
154
                        {                                
155
                                float sizePoints = Float.parseFloat(getJTextField().getText());
156
                                m_Renderer.getDefaultSymbol().setFont(labelFont);
157
                                m_Renderer.getDefaultSymbol().setFont(labelFont.deriveFont(sizePoints));
158
                                m_Renderer.getDefaultSymbol().setFontSize(sizePoints);
159
                                m_Renderer.getDefaultSymbol().setFontSizeInPixels(true);
160
                        }                        
161
                }
162
                else
163
                {
164
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
165
                        // ha de ser null
166
                        m_Renderer.setLabelField(null);
167
                }
168
        }
169

    
170
        
171
        
172
        
173
        private void fillFieldNames() {
174

    
175
                SelectableDataSource rs;
176
                try {
177
                        rs = ((AlphanumericData) m_lyr).getRecordset();
178
                String[] nomFields;
179
                        nomFields = new String[rs.getFieldCount()];
180
                for (int i = 0; i < rs.getFieldCount(); i++) {
181
                        nomFields[i] = rs.getFieldName(i).trim();
182
                }
183

    
184
                DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
185
                getJComboBox().setModel(cM_labelField);
186
                DefaultComboBoxModel cM_heightField = new DefaultComboBoxModel(nomFields);
187
                getJComboBox1().setModel(cM_heightField);
188
        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
189
                e1.printStackTrace();
190
        } catch (DriverException e) {
191
                e.printStackTrace();
192
        }
193
        
194
        }
195
                
196
        
197
        /**
198

199
         * This method initializes jCheckBox        
200

201
         *         
202

203
         * @return javax.swing.JCheckBox        
204

205
         */    
206
        private javax.swing.JCheckBox getJCheckBox() {
207
                if (jCheckBox == null) {
208
                        jCheckBox = new javax.swing.JCheckBox();
209
                        jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado"));
210
                        jCheckBox.setBounds(28, 22, 117, 23);
211
                        jCheckBox.addItemListener(new java.awt.event.ItemListener() { 
212

    
213
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
214
                                        updateControls();                                        
215

    
216
                                }
217
                        });
218

    
219
                }
220
                return jCheckBox;
221
        }
222

    
223
        /**
224

225
         * This method initializes jLabel1        
226

227
         *         
228

229
         * @return javax.swing.JLabel        
230

231
         */    
232
        private javax.swing.JLabel getJLabel1() {
233
                if (jLabel1 == null) {
234
                        jLabel1 = new javax.swing.JLabel();
235
                        jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado"));
236
                        jLabel1.setBounds(29, 53, 116, 21);
237
                }
238
                return jLabel1;
239
        }
240

    
241
        /**
242

243
         * This method initializes jComboBox        
244

245
         *         
246

247
         * @return javax.swing.JComboBox        
248

249
         */    
250
        private javax.swing.JComboBox getJComboBox() {
251
                if (jComboBox == null) {
252
                        jComboBox = new javax.swing.JComboBox();
253
                        jComboBox.setBounds(175, 52, 110, 19);
254
                        jComboBox.setEnabled(false);
255
                }
256
                return jComboBox;
257
        }
258

    
259
        /**
260

261
         * This method initializes jLabel2        
262

263
         *         
264

265
         * @return javax.swing.JLabel        
266

267
         */    
268
        private javax.swing.JLabel getJLabel2() {
269
                if (jLabel2 == null) {
270
                        jLabel2 = new javax.swing.JLabel();
271
                        jLabel2.setBounds(29, 83, 137, 21);
272
                        jLabel2.setText(PluginServices.getText(this,"campo_altura_texto"));
273
                        jLabel2.setVisible(false);
274
                }
275
                return jLabel2;
276
        }
277

    
278
        /**
279

280
         * This method initializes jComboBox1        
281

282
         *         
283

284
         * @return javax.swing.JComboBox        
285

286
         */    
287
        private javax.swing.JComboBox getJComboBox1() {
288
                if (jComboBox1 == null) {
289
                        jComboBox1 = new javax.swing.JComboBox();
290
                        jComboBox1.setBounds(175, 82, 110, 18);
291
                        jComboBox1.setEnabled(false);
292
                        jComboBox1.setVisible(false);
293
                }
294
                return jComboBox1;
295
        }
296

    
297
        /**
298

299
         * This method initializes jPanel        
300

301
         *         
302

303
         * @return javax.swing.JPanel        
304

305
         */    
306
        private javax.swing.JPanel getJPanel() {
307
                if (jPanel == null) {
308
                        jPanel = new javax.swing.JPanel();
309
                        jPanel.setLayout(null);
310
                        jPanel.setBounds(29, 136, 258, 84);
311
                        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));
312
                        ButtonGroup jButtonGroup = new ButtonGroup();
313
                        jButtonGroup.add(getJRadioButton1());
314
                        jButtonGroup.add(getJRadioButton());
315
                        jPanel.add(getJRadioButton1(), null);
316
                        jPanel.add(getJRadioButton(), null);
317
                        jPanel.add(getJTextField(), null);
318
                }
319
                return jPanel;
320
        }
321

    
322
        /**
323

324
         * This method initializes jTextField        
325

326
         *         
327

328
         * @return javax.swing.JTextField        
329

330
         */    
331
        private javax.swing.JTextField getJTextField() {
332
                if (jTextField == null) {
333
                        jTextField = new javax.swing.JTextField();
334
                        jTextField.setBounds(26, 32, 76, 21);
335
                        jTextField.setEnabled(false);
336
                        jTextField.setText("10");
337
                }
338
                return jTextField;
339
        }
340

    
341
/**
342

343
         * This method initializes jRadioButton        
344

345
         *         
346

347
         * @return javax.swing.JRadioButton        
348

349
         */    
350
        private javax.swing.JRadioButton getJRadioButton() {
351
                if (jRadioButton == null) {
352
                        jRadioButton = new javax.swing.JRadioButton();
353
                        jRadioButton.setText(PluginServices.getText(this,"En_pixels"));
354
                        jRadioButton.setBounds(145, 44, 100, 23);
355
                        jRadioButton.setEnabled(false);
356
                        jRadioButton.setSelected(true);
357
                }
358
                return jRadioButton;
359
        }
360

    
361
        /**
362

363
         * This method initializes jRadioButton1        
364

365
         *         
366

367
         * @return javax.swing.JRadioButton        
368

369
         */    
370
        private javax.swing.JRadioButton getJRadioButton1() {
371
                if (jRadioButton1 == null) {
372
                        jRadioButton1 = new javax.swing.JRadioButton();
373
                        jRadioButton1.setText(PluginServices.getText(this,"En_metros"));
374
                        jRadioButton1.setBounds(145, 16, 100, 23);                        
375
                        jRadioButton1.setEnabled(false);
376
                }
377
                return jRadioButton1;
378
        }
379

    
380
        /**
381

382
         * This method initializes fPreviewSymbol        
383

384
         *         
385

386
         * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol        
387

388
         */    
389
        private FPreviewSymbol getFPreviewSymbol() {
390
                if (fPreviewSymbol == null) {
391
                        fPreviewSymbol = new FPreviewSymbol();
392
                        fPreviewSymbol.setBounds(311, 53, 134, 77);
393
                }
394
                return fPreviewSymbol;
395
        }
396

    
397
        /**
398

399
         * This method initializes jLabel3        
400

401
         *         
402

403
         * @return javax.swing.JLabel        
404

405
         */    
406
        private javax.swing.JLabel getJLabel3() {
407
                if (jLabel3 == null) {
408
                        jLabel3 = new javax.swing.JLabel();
409
                        jLabel3.setBounds(312, 28, 100, 18);
410
                        jLabel3.setText(PluginServices.getText(this,"Previsualizacion"));
411
                }
412
                return jLabel3;
413
        }
414

    
415
        /**
416

417
         * This method initializes jButton        
418

419
         *         
420

421
         * @return javax.swing.JButton        
422

423
         */    
424
        private javax.swing.JButton getJButton() {
425
                if (jButton == null) {
426
                        jButton = new javax.swing.JButton();
427
                        jButton.setBounds(315, 139, 111, 29);
428
                        jButton.setText(PluginServices.getText(this,"fuente")+"...");
429
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
430

    
431
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
432
                                        JButton origen = (JButton) e.getSource();
433
                                        Font newFont;
434
                                        
435
                                        newFont = FontChooser.showDialog("Choose Font", labelFont);                                                
436
                                        
437
                                if (newFont == null) {
438
                                    return;
439
                                }
440
                                
441
                                labelFont = newFont;
442
                                updateControls();
443

    
444

    
445
                                }
446
                        });
447

    
448
                }
449
                return jButton;
450
        }
451

    
452
        /**
453

454
         * This method initializes jLabel4        
455

456
         *         
457

458
         * @return javax.swing.JLabel        
459

460
         */    
461
        private javax.swing.JLabel getJLabel4() {
462
                if (jLabel4 == null) {
463
                        jLabel4 = new javax.swing.JLabel();
464
                        jLabel4.setBounds(29, 109, 133, 23);
465
                        jLabel4.setText(PluginServices.getText(this,"color_texto"));
466
                }
467
                return jLabel4;
468
        }
469
        /* (non-Javadoc)
470
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
471
         */
472
        public Legend getLegend() {
473
                updateValuesFromControls();
474
                return m_Renderer;
475
        }
476

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