Statistics
| Revision:

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

History | View | Annotate | Download (11.1 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.iver.cit.gvsig.fmap.core.v02.FSymbol;
16
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
17
import com.iver.cit.gvsig.fmap.layers.FRecordset;
18
import com.iver.cit.gvsig.fmap.rendering.Legend;
19
import com.iver.cit.gvsig.gui.Dialogs.FontChooser;
20
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
21
import com.iver.mdiApp.Utilities;
22

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

    
102
                fillFieldNames();                
103
                getJComboBox().getModel().setSelectedItem(m_Renderer.getLabelField());
104
                getJComboBox1().getModel().setSelectedItem(m_Renderer.getHeightField());
105
                if (m_Renderer.getDefaultSymbol().m_FontColor!=null){
106
                        m_colorChooser.setColor(m_Renderer.getDefaultSymbol().m_FontColor);
107
                }
108
                fPreviewSymbol.setSymbol(m_Renderer.getDefaultSymbol());
109
                if (m_Renderer.getLabelField() != null)
110
                        getJCheckBox().setSelected(true);
111
                else
112
                        getJCheckBox().setSelected(false);
113

    
114
                
115
        }
116

    
117
        private void updateControls() {
118
                getJComboBox().setEnabled(getJCheckBox().isSelected());
119
                getJComboBox1().setEnabled(getJCheckBox().isSelected());
120
                getJRadioButton().setEnabled(getJCheckBox().isSelected());
121
                getJRadioButton1().setEnabled(getJCheckBox().isSelected());
122
                getJTextField().setEnabled(getJCheckBox().isSelected());
123
                if (getJCheckBox().isSelected())
124
                {
125
                        FSymbol sym = m_Renderer.getDefaultSymbol();
126
                        sym.m_Font = labelFont;
127
                        sym.m_FontColor = m_colorChooser.getColor();
128
                        fPreviewSymbol.setSymbol(sym);
129
                }
130
        }
131
        public void updateValuesFromControls() {
132
                if (getJCheckBox().isSelected())
133
                {
134
                        m_Renderer.setLabelField((String) getJComboBox().getSelectedItem());
135
                        m_Renderer.setLabelHeightField((String) getJComboBox1().getSelectedItem());
136
                        m_Renderer.getDefaultSymbol().m_FontColor = m_colorChooser.getColor();
137
                        if (getJRadioButton().isSelected())
138
                        {
139
                                float sizePoints = Float.parseFloat(getJTextField().getText());
140
                                System.out.println(Utilities.getMessage(this,"nuevo_tamano_fuente") + sizePoints);
141
                                m_Renderer.getDefaultSymbol().m_Font = labelFont.deriveFont(sizePoints);
142
                                m_Renderer.getDefaultSymbol().m_FontSize = sizePoints; // Para que se pueda crear correctamente al recuperar del proyecto
143
                                m_Renderer.getDefaultSymbol().m_bUseFontSize = false;
144
                        }
145
                        else
146
                        {
147
                                float sizeUnits = Float.parseFloat(getJTextField().getText());
148
                                m_Renderer.getDefaultSymbol().m_Font = labelFont;
149
                                m_Renderer.getDefaultSymbol().m_FontSize = sizeUnits;
150
                                m_Renderer.getDefaultSymbol().m_bUseFontSize = true;
151
                        }                        
152
                }
153
                else
154
                {
155
                        // Para que no se dibujen las etiquetas, el campo labelField del Renderer
156
                        // ha de ser null
157
                        m_Renderer.setLabelField(null);
158
                }
159
        }
160

    
161
        
162
        
163
        
164
        private void fillFieldNames() {
165

    
166
                FRecordset rs = m_lyr.getRecordset();
167
                String[] nomFields = new String[rs.getFieldsCount()];
168
                for (int i = 0; i < rs.getFieldsCount(); i++) {
169
                        nomFields[i] = rs.getFieldName(i).trim();
170
                }
171

    
172
                DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields);
173
                getJComboBox().setModel(cM_labelField);
174
                DefaultComboBoxModel cM_heightField = new DefaultComboBoxModel(nomFields);
175
                getJComboBox1().setModel(cM_heightField);
176

    
177
        }
178
                
179
        
180
        /**
181

182
         * This method initializes jCheckBox        
183

184
         *         
185

186
         * @return javax.swing.JCheckBox        
187

188
         */    
189
        private javax.swing.JCheckBox getJCheckBox() {
190
                if (jCheckBox == null) {
191
                        jCheckBox = new javax.swing.JCheckBox();
192
                        jCheckBox.setText(Utilities.getMessage(this,"Habilitar_etiquetado"));
193
                        jCheckBox.setBounds(28, 22, 117, 23);
194
                        jCheckBox.addItemListener(new java.awt.event.ItemListener() { 
195

    
196
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
197
                                        updateControls();                                        
198

    
199
                                }
200
                        });
201

    
202
                }
203
                return jCheckBox;
204
        }
205

    
206
        /**
207

208
         * This method initializes jLabel1        
209

210
         *         
211

212
         * @return javax.swing.JLabel        
213

214
         */    
215
        private javax.swing.JLabel getJLabel1() {
216
                if (jLabel1 == null) {
217
                        jLabel1 = new javax.swing.JLabel();
218
                        jLabel1.setText(Utilities.getMessage(this,"Campo_de_etiquetado"));
219
                        jLabel1.setBounds(29, 53, 116, 21);
220
                }
221
                return jLabel1;
222
        }
223

    
224
        /**
225

226
         * This method initializes jComboBox        
227

228
         *         
229

230
         * @return javax.swing.JComboBox        
231

232
         */    
233
        private javax.swing.JComboBox getJComboBox() {
234
                if (jComboBox == null) {
235
                        jComboBox = new javax.swing.JComboBox();
236
                        jComboBox.setBounds(175, 52, 110, 19);
237
                        jComboBox.setEnabled(false);
238
                }
239
                return jComboBox;
240
        }
241

    
242
        /**
243

244
         * This method initializes jLabel2        
245

246
         *         
247

248
         * @return javax.swing.JLabel        
249

250
         */    
251
        private javax.swing.JLabel getJLabel2() {
252
                if (jLabel2 == null) {
253
                        jLabel2 = new javax.swing.JLabel();
254
                        jLabel2.setBounds(29, 83, 137, 21);
255
                        jLabel2.setText(Utilities.getMessage(this,"campo_altura_texto"));
256
                        jLabel2.setVisible(false);
257
                }
258
                return jLabel2;
259
        }
260

    
261
        /**
262

263
         * This method initializes jComboBox1        
264

265
         *         
266

267
         * @return javax.swing.JComboBox        
268

269
         */    
270
        private javax.swing.JComboBox getJComboBox1() {
271
                if (jComboBox1 == null) {
272
                        jComboBox1 = new javax.swing.JComboBox();
273
                        jComboBox1.setBounds(175, 82, 110, 18);
274
                        jComboBox1.setEnabled(false);
275
                        jComboBox1.setVisible(false);
276
                }
277
                return jComboBox1;
278
        }
279

    
280
        /**
281

282
         * This method initializes jPanel        
283

284
         *         
285

286
         * @return javax.swing.JPanel        
287

288
         */    
289
        private javax.swing.JPanel getJPanel() {
290
                if (jPanel == null) {
291
                        jPanel = new javax.swing.JPanel();
292
                        jPanel.setLayout(null);
293
                        jPanel.setBounds(29, 136, 258, 84);
294
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Utilities.getMessage(this,"Altura_fija_de_texto"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
295
                        ButtonGroup jButtonGroup = new ButtonGroup();
296
                        jButtonGroup.add(getJRadioButton1());
297
                        jButtonGroup.add(getJRadioButton());
298
                        jPanel.add(getJRadioButton1(), null);
299
                        jPanel.add(getJRadioButton(), null);
300
                        jPanel.add(getJTextField(), null);
301
                }
302
                return jPanel;
303
        }
304

    
305
        /**
306

307
         * This method initializes jTextField        
308

309
         *         
310

311
         * @return javax.swing.JTextField        
312

313
         */    
314
        private javax.swing.JTextField getJTextField() {
315
                if (jTextField == null) {
316
                        jTextField = new javax.swing.JTextField();
317
                        jTextField.setBounds(26, 32, 76, 21);
318
                        jTextField.setEnabled(false);
319
                        jTextField.setText("10");
320
                }
321
                return jTextField;
322
        }
323

    
324
/**
325

326
         * This method initializes jRadioButton        
327

328
         *         
329

330
         * @return javax.swing.JRadioButton        
331

332
         */    
333
        private javax.swing.JRadioButton getJRadioButton() {
334
                if (jRadioButton == null) {
335
                        jRadioButton = new javax.swing.JRadioButton();
336
                        jRadioButton.setText(Utilities.getMessage(this,"En_pixels"));
337
                        jRadioButton.setBounds(145, 44, 100, 23);
338
                        jRadioButton.setEnabled(false);
339
                        jRadioButton.setSelected(true);
340
                }
341
                return jRadioButton;
342
        }
343

    
344
        /**
345

346
         * This method initializes jRadioButton1        
347

348
         *         
349

350
         * @return javax.swing.JRadioButton        
351

352
         */    
353
        private javax.swing.JRadioButton getJRadioButton1() {
354
                if (jRadioButton1 == null) {
355
                        jRadioButton1 = new javax.swing.JRadioButton();
356
                        jRadioButton1.setText(Utilities.getMessage(this,"En_metros"));
357
                        jRadioButton1.setBounds(145, 16, 100, 23);                        
358
                        jRadioButton1.setEnabled(false);
359
                }
360
                return jRadioButton1;
361
        }
362

    
363
        /**
364

365
         * This method initializes fPreviewSymbol        
366

367
         *         
368

369
         * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol        
370

371
         */    
372
        private com.iver.cit.gvsig.gui.Panels.FPreviewSymbol getFPreviewSymbol() {
373
                if (fPreviewSymbol == null) {
374
                        fPreviewSymbol = new com.iver.cit.gvsig.gui.Panels.FPreviewSymbol();
375
                        fPreviewSymbol.setBounds(311, 53, 134, 77);
376
                }
377
                return fPreviewSymbol;
378
        }
379

    
380
        /**
381

382
         * This method initializes jLabel3        
383

384
         *         
385

386
         * @return javax.swing.JLabel        
387

388
         */    
389
        private javax.swing.JLabel getJLabel3() {
390
                if (jLabel3 == null) {
391
                        jLabel3 = new javax.swing.JLabel();
392
                        jLabel3.setBounds(312, 28, 100, 18);
393
                        jLabel3.setText(Utilities.getMessage(this,"Previsualizacion"));
394
                }
395
                return jLabel3;
396
        }
397

    
398
        /**
399

400
         * This method initializes jButton        
401

402
         *         
403

404
         * @return javax.swing.JButton        
405

406
         */    
407
        private javax.swing.JButton getJButton() {
408
                if (jButton == null) {
409
                        jButton = new javax.swing.JButton();
410
                        jButton.setBounds(315, 139, 111, 29);
411
                        jButton.setText(Utilities.getMessage(this,"fuente")+"...");
412
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
413

    
414
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
415
                                        JButton origen = (JButton) e.getSource();
416
                                        Font newFont;
417
                                        
418
                                        newFont = FontChooser.showDialog("Choose Font", labelFont);                                                
419
                                        
420
                                if (newFont == null) {
421
                                    return;
422
                                }
423
                                
424
                                labelFont = newFont;
425
                                updateControls();
426

    
427

    
428
                                }
429
                        });
430

    
431
                }
432
                return jButton;
433
        }
434

    
435
        /**
436

437
         * This method initializes jLabel4        
438

439
         *         
440

441
         * @return javax.swing.JLabel        
442

443
         */    
444
        private javax.swing.JLabel getJLabel4() {
445
                if (jLabel4 == null) {
446
                        jLabel4 = new javax.swing.JLabel();
447
                        jLabel4.setBounds(29, 109, 133, 23);
448
                        jLabel4.setText(Utilities.getMessage(this,"color_texto"));
449
                }
450
                return jLabel4;
451
        }
452

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