Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / layerproperties / LabelTextStylePanel.java @ 40911

History | View | Annotate | Download (8.2 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.labeling.gui.layerproperties;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Color;
45
import java.awt.FlowLayout;
46
import java.awt.Font;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.util.ArrayList;
50

    
51
import javax.swing.BorderFactory;
52
import javax.swing.BoxLayout;
53
import javax.swing.ButtonGroup;
54
import javax.swing.JCheckBox;
55
import javax.swing.JLabel;
56
import javax.swing.JPanel;
57
import javax.swing.JRadioButton;
58

    
59
import org.gvsig.app.gui.JComboBoxUnits;
60
import org.gvsig.app.gui.panels.ColorChooserPanel;
61
import org.gvsig.app.gui.styling.JComboBoxUnitsReferenceSystem;
62
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
63
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
64
import org.gvsig.gui.beans.swing.JComboBoxFonts;
65
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
66
import org.gvsig.i18n.Messages;
67

    
68

    
69
public class LabelTextStylePanel extends JPanel implements ActionListener{
70
        private static final long serialVersionUID = 8351591938535233138L;
71
        private ITextSymbol symbol;
72
        private JComboBoxFonts cmbFont;
73
        private ColorChooserPanel colorFont;
74
        private JRadioButton rdBtnTextHeight;
75
        private JRadioButton rdBtnFitOnTextArea;
76
        private JIncrementalNumberField incrTextSize;
77
        private JComboBoxUnits units;
78
        private JComboBoxUnitsReferenceSystem referenceSystem;
79

    
80
        private JCheckBox chkWithHalo;
81
        private ColorChooserPanel colorHaloChooser;
82
        private JIncrementalNumberField txtHaloWidth;
83

    
84
        private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>();
85
        private boolean performAction = true;
86
        
87
        private JCheckBox getCheckHalo() {
88
                if (chkWithHalo == null) {
89
                        chkWithHalo = new JCheckBox(Messages.getText("_Use_halo") + ": ");
90
                        chkWithHalo.setSelected(false);
91
                        chkWithHalo.setName("CHECK_HALO");
92
                }
93
                return chkWithHalo;
94
        }
95
        private ColorChooserPanel getHaloColorChooser() {
96
                if (colorHaloChooser == null){
97
                        colorHaloChooser = new ColorChooserPanel(true);
98
                        colorHaloChooser.setColor(Color.WHITE);
99
                }
100
                return colorHaloChooser;
101
        }
102
        
103

    
104
        private JIncrementalNumberField getTxtHaloWidth() {
105
                if (txtHaloWidth == null) {
106
                        txtHaloWidth = new JIncrementalNumberField("3");
107
                }
108
                return txtHaloWidth;
109
        }
110

    
111

    
112

    
113
        public LabelTextStylePanel() {
114
                setLayout(new BorderLayout(10, 2));
115
                JPanel aux = new JPanel();
116
                aux.setLayout(new BoxLayout(aux,BoxLayout.Y_AXIS));
117
                JPanel auxA = new JPanel();
118
                aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("font")));
119
                auxA.add(new JLabel(Messages.getText("font")));
120
                auxA.add(cmbFont = new JComboBoxFonts(),BorderLayout.NORTH);
121
                JPanel auxB = new JPanel();
122
                auxB.add(new JLabel(Messages.getText("color")));
123
                auxB.add(colorFont = new ColorChooserPanel(true),BorderLayout.SOUTH);
124
                cmbFont.addActionListener(this);
125
                colorFont.addActionListener(this);
126
                aux.add(auxA);
127
                aux.add(auxB);
128
                add(aux, BorderLayout.WEST);
129

    
130
                aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2));
131
                aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("format")));
132
                rdBtnTextHeight = new JRadioButton(Messages.getText("fixed_text_size"));
133
                rdBtnFitOnTextArea = new JRadioButton(Messages.getText("fit_on_text_area"));
134
                rdBtnFitOnTextArea.addActionListener(this);
135
                rdBtnTextHeight.addActionListener(this);
136
                ButtonGroup g = new ButtonGroup();
137
                g.add(rdBtnFitOnTextArea);
138
                g.add(rdBtnTextHeight);
139
                incrTextSize = new JIncrementalNumberField(
140
                                "1",
141
                                7,
142
                                0,
143
                                Double.POSITIVE_INFINITY,
144
                                1);
145
                incrTextSize.addActionListener(this);
146
                units = new JComboBoxUnits();
147
                referenceSystem = new JComboBoxUnitsReferenceSystem();
148
                units.addActionListener(this);
149
                referenceSystem.addActionListener(this);
150

    
151
                GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
152
                JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0));
153
                aux3.add(rdBtnTextHeight);
154
                aux3.add(incrTextSize);
155

    
156
                aux3.add(units);
157
                aux3.add(referenceSystem);
158

    
159
                aux2.addComponent(aux3);
160
                GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
161
                aux4.addComponent(rdBtnFitOnTextArea);
162
                
163
                // Para reflejar los cambios.
164
                getCheckHalo().addActionListener(this);
165
                getHaloColorChooser().addActionListener(this);
166
                getTxtHaloWidth().addActionListener(this);
167

    
168
                
169
                aux4.addComponent(getCheckHalo(), getHaloColorChooser());
170
                aux4.addComponent(Messages.getText("_Halo_width") + ": ", getTxtHaloWidth());
171

    
172
        
173
                aux2.addComponent(aux4);
174
                aux.add(aux2);
175

    
176
                add(aux, BorderLayout.CENTER);
177
        }
178

    
179

    
180

    
181
        public void setModel(ITextSymbol textSymbol, int unit, int referenceSystem) {
182
                incrTextSize.setDouble(textSymbol.getFont().getSize());
183
                rdBtnTextHeight.setSelected(!textSymbol.isAutoresizeEnabled());
184
                rdBtnFitOnTextArea.setSelected(textSymbol.isAutoresizeEnabled());
185
                getCheckHalo().setSelected(textSymbol.isDrawWithHalo());
186
                if (textSymbol.isDrawWithHalo()) {
187
                        getHaloColorChooser().setColor(textSymbol.getHaloColor());
188
                        getTxtHaloWidth().setDouble(textSymbol.getHaloWidth());
189
                }
190
                performAction = false;
191
                cmbFont.setSelectedItem(textSymbol.getFont().getName());
192
                colorFont.setColor(textSymbol.getTextColor());
193
                this.units.setSelectedUnitIndex(unit);
194
                this.referenceSystem.setSelectedIndex(referenceSystem);
195
                boolean enableSize = rdBtnTextHeight.isSelected();
196
                this.units.setEnabled(enableSize);
197
                this.referenceSystem.setEnabled(enableSize);
198
                this.incrTextSize.setEnabled(enableSize);
199
                performAction = true;
200
                this.symbol = textSymbol;
201
        }
202

    
203
        public ITextSymbol getTextSymbol() {
204
                symbol.setDrawWithHalo(chkWithHalo.isSelected());
205
                if (symbol.isDrawWithHalo()) {
206
                        symbol.setHaloColor(colorHaloChooser.getColor());
207
                        symbol.setHaloWidth((float) txtHaloWidth.getDouble());
208
                }
209

    
210
                return symbol;
211
        }
212

    
213

    
214
        public void addActionListener(ActionListener l) {
215
                listeners.add(l);
216
        }
217

    
218
        public void actionPerformed(ActionEvent e) {
219
                if (performAction) {
220
                        boolean enableSize = rdBtnTextHeight.isSelected();
221
                        incrTextSize.setEnabled(enableSize);
222
                        units.setEnabled(enableSize);
223
                        referenceSystem.setEnabled(enableSize);
224

    
225
                        if (symbol != null) {
226
                                symbol.setAutoresizeEnabled(rdBtnFitOnTextArea.isSelected());
227
                                symbol.setFont(
228
                                                new Font(
229
                                                                (String) cmbFont.getSelectedItem(),
230
                                                                Font.PLAIN,
231
                                                                (int) incrTextSize.getDouble()));
232
                                symbol.setTextColor(colorFont.getColor());
233
                                symbol.setFontSize(incrTextSize.getDouble());
234

    
235
                                /* -------------- Add to API?
236
                                symbol.setUnit(units.getSelectedUnitIndex());
237
                                symbol.setReferenceSystem(referenceSystem.getSelectedIndex());
238
                                */
239
                                symbol.setDrawWithHalo(chkWithHalo.isSelected());
240
                                if (symbol.isDrawWithHalo()) {
241
                                        symbol.setHaloColor(colorHaloChooser.getColor());
242
                                        symbol.setHaloWidth((float) txtHaloWidth.getDouble());
243
                                }
244

    
245
                        }
246
                        for (ActionListener l : listeners) {
247
                                l.actionPerformed(new ActionEvent(this, 0, null));
248
                        }
249
                }
250
        }
251

    
252
        public int getUnit() {
253
                return this.units.getSelectedUnitIndex();
254
        }
255

    
256
        public int getReferenceSystem() {
257
                return this.referenceSystem.getSelectedIndex();
258
        }
259
}