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 @ 42264
History | View | Annotate | Download (8.25 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 |
import javax.swing.border.EmptyBorder; |
59 |
|
60 |
import org.gvsig.app.gui.JComboBoxUnits; |
61 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
62 |
import org.gvsig.app.gui.styling.JComboBoxUnitsReferenceSystem; |
63 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
64 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
65 |
import org.gvsig.gui.beans.swing.JComboBoxFonts; |
66 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
67 |
import org.gvsig.i18n.Messages; |
68 |
|
69 |
|
70 |
public class LabelTextStylePanel extends JPanel implements ActionListener{ |
71 |
private static final long serialVersionUID = 8351591938535233138L; |
72 |
private ITextSymbol symbol;
|
73 |
private JComboBoxFonts cmbFont;
|
74 |
private ColorChooserPanel colorFont;
|
75 |
private JRadioButton rdBtnTextHeight; |
76 |
private JRadioButton rdBtnFitOnTextArea; |
77 |
private JNumberSpinner incrTextSize;
|
78 |
private JComboBoxUnits units;
|
79 |
private JComboBoxUnitsReferenceSystem referenceSystem;
|
80 |
|
81 |
private JCheckBox chkWithHalo; |
82 |
private ColorChooserPanel colorHaloChooser;
|
83 |
private JNumberSpinner txtHaloWidth;
|
84 |
|
85 |
private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(); |
86 |
private boolean performAction = true; |
87 |
|
88 |
private JCheckBox getCheckHalo() { |
89 |
if (chkWithHalo == null) { |
90 |
chkWithHalo = new JCheckBox(Messages.getText("_Use_halo") + ": "); |
91 |
chkWithHalo.setSelected(false);
|
92 |
chkWithHalo.setName("CHECK_HALO");
|
93 |
} |
94 |
return chkWithHalo;
|
95 |
} |
96 |
private ColorChooserPanel getHaloColorChooser() {
|
97 |
if (colorHaloChooser == null){ |
98 |
colorHaloChooser = new ColorChooserPanel(true); |
99 |
colorHaloChooser.setColor(Color.WHITE);
|
100 |
} |
101 |
return colorHaloChooser;
|
102 |
} |
103 |
|
104 |
|
105 |
private JNumberSpinner getTxtHaloWidth() {
|
106 |
if (txtHaloWidth == null) { |
107 |
txtHaloWidth = new JNumberSpinner(3); |
108 |
} |
109 |
return txtHaloWidth;
|
110 |
} |
111 |
|
112 |
|
113 |
|
114 |
public LabelTextStylePanel() {
|
115 |
setLayout(new BorderLayout(5, 0)); |
116 |
setBorder(new EmptyBorder(5, 5, 5, 5)); |
117 |
JPanel aux = new JPanel(); |
118 |
aux.setLayout(new BoxLayout(aux,BoxLayout.Y_AXIS)); |
119 |
JPanel auxA = new JPanel(); |
120 |
aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("font"))); |
121 |
auxA.add(new JLabel(Messages.getText("font"))); |
122 |
auxA.add(cmbFont = new JComboBoxFonts(),BorderLayout.NORTH); |
123 |
JPanel auxB = new JPanel(); |
124 |
auxB.add(new JLabel(Messages.getText("color"))); |
125 |
auxB.add(colorFont = new ColorChooserPanel(true),BorderLayout.SOUTH); |
126 |
cmbFont.addActionListener(this);
|
127 |
colorFont.addActionListener(this);
|
128 |
aux.add(auxA); |
129 |
aux.add(auxB); |
130 |
add(aux, BorderLayout.WEST);
|
131 |
|
132 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2)); |
133 |
aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("format"))); |
134 |
rdBtnTextHeight = new JRadioButton(Messages.getText("fixed_text_size")); |
135 |
rdBtnFitOnTextArea = new JRadioButton(Messages.getText("fit_on_text_area")); |
136 |
rdBtnFitOnTextArea.addActionListener(this);
|
137 |
rdBtnTextHeight.addActionListener(this);
|
138 |
ButtonGroup g = new ButtonGroup(); |
139 |
g.add(rdBtnFitOnTextArea); |
140 |
g.add(rdBtnTextHeight); |
141 |
incrTextSize = new JNumberSpinner(
|
142 |
1,
|
143 |
7,
|
144 |
0,
|
145 |
Double.POSITIVE_INFINITY,
|
146 |
1);
|
147 |
incrTextSize.addActionListener(this);
|
148 |
units = new JComboBoxUnits();
|
149 |
referenceSystem = new JComboBoxUnitsReferenceSystem();
|
150 |
units.addActionListener(this);
|
151 |
referenceSystem.addActionListener(this);
|
152 |
|
153 |
GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
154 |
JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0)); |
155 |
aux3.add(rdBtnTextHeight); |
156 |
aux3.add(incrTextSize); |
157 |
|
158 |
aux3.add(units); |
159 |
aux3.add(referenceSystem); |
160 |
|
161 |
aux2.addComponent(aux3); |
162 |
GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
|
163 |
aux4.addComponent(rdBtnFitOnTextArea); |
164 |
|
165 |
// Para reflejar los cambios.
|
166 |
getCheckHalo().addActionListener(this);
|
167 |
getHaloColorChooser().addActionListener(this);
|
168 |
getTxtHaloWidth().addActionListener(this);
|
169 |
|
170 |
|
171 |
aux4.addComponent(getCheckHalo(), getHaloColorChooser()); |
172 |
aux4.addComponent(Messages.getText("_Halo_width") + ": ", getTxtHaloWidth()); |
173 |
|
174 |
|
175 |
aux2.addComponent(aux4); |
176 |
aux.add(aux2); |
177 |
|
178 |
add(aux, BorderLayout.CENTER);
|
179 |
} |
180 |
|
181 |
|
182 |
|
183 |
public void setModel(ITextSymbol textSymbol, int unit, int referenceSystem) { |
184 |
incrTextSize.setDouble(textSymbol.getFont().getSize()); |
185 |
rdBtnTextHeight.setSelected(!textSymbol.isAutoresizeEnabled()); |
186 |
rdBtnFitOnTextArea.setSelected(textSymbol.isAutoresizeEnabled()); |
187 |
getCheckHalo().setSelected(textSymbol.isDrawWithHalo()); |
188 |
if (textSymbol.isDrawWithHalo()) {
|
189 |
getHaloColorChooser().setColor(textSymbol.getHaloColor()); |
190 |
getTxtHaloWidth().setDouble(textSymbol.getHaloWidth()); |
191 |
} |
192 |
performAction = false;
|
193 |
cmbFont.setSelectedItem(textSymbol.getFont().getName()); |
194 |
colorFont.setColor(textSymbol.getTextColor()); |
195 |
this.units.setSelectedUnitIndex(unit);
|
196 |
this.referenceSystem.setSelectedIndex(referenceSystem);
|
197 |
boolean enableSize = rdBtnTextHeight.isSelected();
|
198 |
this.units.setEnabled(enableSize);
|
199 |
this.referenceSystem.setEnabled(enableSize);
|
200 |
this.incrTextSize.setEnabled(enableSize);
|
201 |
performAction = true;
|
202 |
this.symbol = textSymbol;
|
203 |
} |
204 |
|
205 |
public ITextSymbol getTextSymbol() {
|
206 |
symbol.setDrawWithHalo(chkWithHalo.isSelected()); |
207 |
if (symbol.isDrawWithHalo()) {
|
208 |
symbol.setHaloColor(colorHaloChooser.getColor()); |
209 |
symbol.setHaloWidth((float) txtHaloWidth.getDouble());
|
210 |
} |
211 |
|
212 |
return symbol;
|
213 |
} |
214 |
|
215 |
|
216 |
public void addActionListener(ActionListener l) { |
217 |
listeners.add(l); |
218 |
} |
219 |
|
220 |
public void actionPerformed(ActionEvent e) { |
221 |
if (performAction) {
|
222 |
boolean enableSize = rdBtnTextHeight.isSelected();
|
223 |
incrTextSize.setEnabled(enableSize); |
224 |
units.setEnabled(enableSize); |
225 |
referenceSystem.setEnabled(enableSize); |
226 |
|
227 |
if (symbol != null) { |
228 |
symbol.setAutoresizeEnabled(rdBtnFitOnTextArea.isSelected()); |
229 |
symbol.setFont( |
230 |
new Font( |
231 |
(String) cmbFont.getSelectedItem(),
|
232 |
Font.PLAIN,
|
233 |
(int) incrTextSize.getDouble()));
|
234 |
symbol.setTextColor(colorFont.getColor()); |
235 |
symbol.setFontSize(incrTextSize.getDouble()); |
236 |
|
237 |
/* -------------- Add to API?
|
238 |
symbol.setUnit(units.getSelectedUnitIndex());
|
239 |
symbol.setReferenceSystem(referenceSystem.getSelectedIndex());
|
240 |
*/
|
241 |
symbol.setDrawWithHalo(chkWithHalo.isSelected()); |
242 |
if (symbol.isDrawWithHalo()) {
|
243 |
symbol.setHaloColor(colorHaloChooser.getColor()); |
244 |
symbol.setHaloWidth((float) txtHaloWidth.getDouble());
|
245 |
} |
246 |
|
247 |
} |
248 |
for (ActionListener l : listeners) { |
249 |
l.actionPerformed(new ActionEvent(this, 0, null)); |
250 |
} |
251 |
} |
252 |
} |
253 |
|
254 |
public int getUnit() { |
255 |
return this.units.getSelectedUnitIndex(); |
256 |
} |
257 |
|
258 |
public int getReferenceSystem() { |
259 |
return this.referenceSystem.getSelectedIndex(); |
260 |
} |
261 |
} |