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 @ 40665
History | View | Annotate | Download (8.27 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.JColorChooser; |
56 |
import javax.swing.JLabel; |
57 |
import javax.swing.JPanel; |
58 |
import javax.swing.JRadioButton; |
59 |
|
60 |
import junit.runner.SimpleTestCollector; |
61 |
|
62 |
import org.gvsig.app.gui.JComboBoxUnits; |
63 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
64 |
import org.gvsig.app.gui.styling.JComboBoxUnitsReferenceSystem; |
65 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
66 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
67 |
import org.gvsig.gui.beans.swing.JComboBoxFonts; |
68 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
69 |
import org.gvsig.i18n.Messages; |
70 |
|
71 |
|
72 |
public class LabelTextStylePanel extends JPanel implements ActionListener{ |
73 |
private static final long serialVersionUID = 8351591938535233138L; |
74 |
private ITextSymbol symbol;
|
75 |
private JComboBoxFonts cmbFont;
|
76 |
private ColorChooserPanel colorFont;
|
77 |
private JRadioButton rdBtnTextHeight; |
78 |
private JRadioButton rdBtnFitOnTextArea; |
79 |
private JIncrementalNumberField incrTextSize;
|
80 |
private JComboBoxUnits units;
|
81 |
private JComboBoxUnitsReferenceSystem referenceSystem;
|
82 |
|
83 |
private JCheckBox chkWithHalo; |
84 |
private ColorChooserPanel colorHaloChooser;
|
85 |
private JIncrementalNumberField txtHaloWidth;
|
86 |
|
87 |
private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(); |
88 |
private boolean performAction = true; |
89 |
|
90 |
private JCheckBox getCheckHalo() { |
91 |
if (chkWithHalo == null) { |
92 |
chkWithHalo = new JCheckBox(Messages.getText("chk_halo") + ":"); |
93 |
chkWithHalo.setSelected(false);
|
94 |
chkWithHalo.setName("CHECK_HALO");
|
95 |
} |
96 |
return chkWithHalo;
|
97 |
} |
98 |
private ColorChooserPanel getHaloColorChooser() {
|
99 |
if (colorHaloChooser == null){ |
100 |
colorHaloChooser = new ColorChooserPanel(true); |
101 |
colorHaloChooser.setColor(Color.WHITE);
|
102 |
} |
103 |
return colorHaloChooser;
|
104 |
} |
105 |
|
106 |
|
107 |
private JIncrementalNumberField getTxtHaloWidth() {
|
108 |
if (txtHaloWidth == null) { |
109 |
txtHaloWidth = new JIncrementalNumberField("3"); |
110 |
} |
111 |
return txtHaloWidth;
|
112 |
} |
113 |
|
114 |
|
115 |
|
116 |
public LabelTextStylePanel() {
|
117 |
setLayout(new BorderLayout(10, 2)); |
118 |
JPanel aux = new JPanel(); |
119 |
aux.setLayout(new BoxLayout(aux,BoxLayout.Y_AXIS)); |
120 |
JPanel auxA = new JPanel(); |
121 |
aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("font"))); |
122 |
auxA.add(new JLabel(Messages.getText("font"))); |
123 |
auxA.add(cmbFont = new JComboBoxFonts(),BorderLayout.NORTH); |
124 |
JPanel auxB = new JPanel(); |
125 |
auxB.add(new JLabel(Messages.getText("color"))); |
126 |
auxB.add(colorFont = new ColorChooserPanel(true),BorderLayout.SOUTH); |
127 |
cmbFont.addActionListener(this);
|
128 |
colorFont.addActionListener(this);
|
129 |
aux.add(auxA); |
130 |
aux.add(auxB); |
131 |
add(aux, BorderLayout.WEST);
|
132 |
|
133 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2)); |
134 |
aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("format"))); |
135 |
rdBtnTextHeight = new JRadioButton(Messages.getText("fixed_text_size")); |
136 |
rdBtnFitOnTextArea = new JRadioButton(Messages.getText("fit_on_text_area")); |
137 |
rdBtnFitOnTextArea.addActionListener(this);
|
138 |
rdBtnTextHeight.addActionListener(this);
|
139 |
ButtonGroup g = new ButtonGroup(); |
140 |
g.add(rdBtnFitOnTextArea); |
141 |
g.add(rdBtnTextHeight); |
142 |
incrTextSize = new JIncrementalNumberField(
|
143 |
"1",
|
144 |
7,
|
145 |
0,
|
146 |
Double.POSITIVE_INFINITY,
|
147 |
1);
|
148 |
incrTextSize.addActionListener(this);
|
149 |
units = new JComboBoxUnits();
|
150 |
referenceSystem = new JComboBoxUnitsReferenceSystem();
|
151 |
units.addActionListener(this);
|
152 |
referenceSystem.addActionListener(this);
|
153 |
|
154 |
GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
155 |
JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0)); |
156 |
aux3.add(rdBtnTextHeight); |
157 |
aux3.add(incrTextSize); |
158 |
|
159 |
aux3.add(units); |
160 |
aux3.add(referenceSystem); |
161 |
|
162 |
aux2.addComponent(aux3); |
163 |
GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
|
164 |
aux4.addComponent(rdBtnFitOnTextArea); |
165 |
|
166 |
// Para reflejar los cambios.
|
167 |
getCheckHalo().addActionListener(this);
|
168 |
getHaloColorChooser().addActionListener(this);
|
169 |
getTxtHaloWidth().addActionListener(this);
|
170 |
aux4.addComponent(getCheckHalo(), getHaloColorChooser()); |
171 |
aux4.addComponent(Messages.getText("HaloWidth") + ":", getTxtHaloWidth()); |
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 |
} |