svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / LabelTextStylePanel.java @ 25807
History | View | Annotate | Download (6.82 KB)
1 | 23419 | vcaballero | /* 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.symbology.gui.layerproperties; |
||
42 | |||
43 | import java.awt.BorderLayout; |
||
44 | import java.awt.FlowLayout; |
||
45 | import java.awt.Font; |
||
46 | import java.awt.event.ActionEvent; |
||
47 | import java.awt.event.ActionListener; |
||
48 | import java.util.ArrayList; |
||
49 | |||
50 | import javax.swing.BorderFactory; |
||
51 | 23819 | vcaballero | import javax.swing.BoxLayout; |
52 | 23419 | vcaballero | import javax.swing.ButtonGroup; |
53 | 23819 | vcaballero | import javax.swing.JColorChooser; |
54 | 23419 | vcaballero | import javax.swing.JLabel; |
55 | import javax.swing.JPanel; |
||
56 | import javax.swing.JRadioButton; |
||
57 | |||
58 | 24221 | vcaballero | import junit.runner.SimpleTestCollector; |
59 | |||
60 | 23419 | vcaballero | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
61 | import org.gvsig.gui.beans.swing.JComboBoxFonts; |
||
62 | import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
||
63 | |||
64 | import com.iver.andami.PluginServices; |
||
65 | import com.iver.cit.gvsig.fmap.MapContext; |
||
66 | 24221 | vcaballero | import com.iver.cit.gvsig.fmap.core.CartographicSupport; |
67 | 23419 | vcaballero | import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
68 | 24221 | vcaballero | import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
69 | 23884 | vcaballero | import com.iver.cit.gvsig.gui.JComboBoxUnits; |
70 | 23819 | vcaballero | import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
71 | 23419 | vcaballero | import com.iver.cit.gvsig.gui.styling.JComboBoxUnitsReferenceSystem; |
72 | |||
73 | public class LabelTextStylePanel extends JPanel implements ActionListener{ |
||
74 | private static final long serialVersionUID = 8351591938535233138L; |
||
75 | private ITextSymbol symbol;
|
||
76 | private JComboBoxFonts cmbFont;
|
||
77 | 23819 | vcaballero | private ColorChooserPanel colorFont;
|
78 | 23419 | vcaballero | private JRadioButton rdBtnTextHeight; |
79 | private JRadioButton rdBtnFitOnTextArea; |
||
80 | private JIncrementalNumberField incrTextSize;
|
||
81 | 23884 | vcaballero | private JComboBoxUnits units;
|
82 | private JComboBoxUnitsReferenceSystem referenceSystem;
|
||
83 | 23419 | vcaballero | private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(); |
84 | private boolean performAction = true; |
||
85 | |||
86 | public LabelTextStylePanel() {
|
||
87 | setLayout(new BorderLayout(10, 2)); |
||
88 | JPanel aux = new JPanel(); |
||
89 | 23819 | vcaballero | aux.setLayout(new BoxLayout(aux,BoxLayout.Y_AXIS)); |
90 | JPanel auxA = new JPanel(); |
||
91 | 23419 | vcaballero | aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "font"))); |
92 | 23819 | vcaballero | auxA.add(new JLabel(PluginServices.getText(this, "font"))); |
93 | auxA.add(cmbFont = new JComboBoxFonts(),BorderLayout.NORTH); |
||
94 | JPanel auxB = new JPanel(); |
||
95 | auxB.add(new JLabel(PluginServices.getText(this, "color"))); |
||
96 | auxB.add(colorFont = new ColorChooserPanel(true),BorderLayout.SOUTH); |
||
97 | 23419 | vcaballero | cmbFont.addActionListener(this);
|
98 | 23819 | vcaballero | colorFont.addActionListener(this);
|
99 | aux.add(auxA); |
||
100 | aux.add(auxB); |
||
101 | 23419 | vcaballero | add(aux, BorderLayout.WEST);
|
102 | |||
103 | aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2)); |
||
104 | aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "format"))); |
||
105 | rdBtnTextHeight = new JRadioButton(PluginServices.getText(this, "fixed_text_size")); |
||
106 | rdBtnFitOnTextArea = new JRadioButton(PluginServices.getText(this, "fit_on_text_area")); |
||
107 | rdBtnFitOnTextArea.addActionListener(this);
|
||
108 | rdBtnTextHeight.addActionListener(this);
|
||
109 | ButtonGroup g = new ButtonGroup(); |
||
110 | g.add(rdBtnFitOnTextArea); |
||
111 | g.add(rdBtnTextHeight); |
||
112 | incrTextSize = new JIncrementalNumberField(
|
||
113 | "1",
|
||
114 | 7,
|
||
115 | 0,
|
||
116 | Double.POSITIVE_INFINITY,
|
||
117 | 1);
|
||
118 | incrTextSize.addActionListener(this);
|
||
119 | 23884 | vcaballero | units = new JComboBoxUnits();
|
120 | referenceSystem = new JComboBoxUnitsReferenceSystem();
|
||
121 | 24221 | vcaballero | units.addActionListener(this);
|
122 | referenceSystem.addActionListener(this);
|
||
123 | 23884 | vcaballero | |
124 | 23419 | vcaballero | GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
125 | JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0)); |
||
126 | aux3.add(rdBtnTextHeight); |
||
127 | aux3.add(incrTextSize); |
||
128 | 24221 | vcaballero | |
129 | 23884 | vcaballero | aux3.add(units); |
130 | aux3.add(referenceSystem); |
||
131 | |||
132 | 23419 | vcaballero | aux2.addComponent(aux3); |
133 | aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0)); |
||
134 | aux3.add(rdBtnFitOnTextArea); |
||
135 | aux2.addComponent(aux3); |
||
136 | aux.add(aux2); |
||
137 | |||
138 | add(aux, BorderLayout.CENTER);
|
||
139 | } |
||
140 | |||
141 | |||
142 | |||
143 | public void setModel(ITextSymbol textSymbol, int unit, int referenceSystem) { |
||
144 | incrTextSize.setDouble(textSymbol.getFont().getSize()); |
||
145 | rdBtnTextHeight.setSelected(!textSymbol.isAutoresizeEnabled()); |
||
146 | rdBtnFitOnTextArea.setSelected(textSymbol.isAutoresizeEnabled()); |
||
147 | performAction = false;
|
||
148 | cmbFont.setSelectedItem(textSymbol.getFont().getName()); |
||
149 | 23819 | vcaballero | colorFont.setColor(textSymbol.getTextColor()); |
150 | 23884 | vcaballero | this.units.setSelectedUnitIndex(unit);
|
151 | this.referenceSystem.setSelectedIndex(referenceSystem);
|
||
152 | 24221 | vcaballero | boolean enableSize = rdBtnTextHeight.isSelected();
|
153 | this.units.setEnabled(enableSize);
|
||
154 | this.referenceSystem.setEnabled(enableSize);
|
||
155 | this.incrTextSize.setEnabled(enableSize);
|
||
156 | 23419 | vcaballero | performAction = true;
|
157 | this.symbol = textSymbol;
|
||
158 | } |
||
159 | |||
160 | public ITextSymbol getTextSymbol() {
|
||
161 | return symbol;
|
||
162 | } |
||
163 | |||
164 | |||
165 | public void addActionListener(ActionListener l) { |
||
166 | listeners.add(l); |
||
167 | } |
||
168 | |||
169 | public void actionPerformed(ActionEvent e) { |
||
170 | if (performAction) {
|
||
171 | boolean enableSize = rdBtnTextHeight.isSelected();
|
||
172 | incrTextSize.setEnabled(enableSize); |
||
173 | 23884 | vcaballero | units.setEnabled(enableSize); |
174 | referenceSystem.setEnabled(enableSize); |
||
175 | 23419 | vcaballero | |
176 | if (symbol != null) { |
||
177 | symbol.setAutoresizeEnabled(rdBtnFitOnTextArea.isSelected()); |
||
178 | symbol.setFont( |
||
179 | new Font( |
||
180 | (String) cmbFont.getSelectedItem(),
|
||
181 | Font.PLAIN,
|
||
182 | 24221 | vcaballero | (int) incrTextSize.getDouble()));
|
183 | 23819 | vcaballero | symbol.setTextColor(colorFont.getColor()); |
184 | 23419 | vcaballero | symbol.setFontSize(incrTextSize.getDouble()); |
185 | 24221 | vcaballero | if(symbol instanceof SimpleTextSymbol){ |
186 | SimpleTextSymbol myText = (SimpleTextSymbol) symbol; |
||
187 | myText.setUnit(units.getSelectedUnitIndex()); |
||
188 | myText.setReferenceSystem(referenceSystem.getSelectedIndex()); |
||
189 | } |
||
190 | 23419 | vcaballero | } |
191 | for (ActionListener l : listeners) { |
||
192 | l.actionPerformed(new ActionEvent(this, 0, null)); |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | 23884 | vcaballero | |
197 | public int getUnit() { |
||
198 | return this.units.getSelectedUnitIndex(); |
||
199 | } |
||
200 | |||
201 | public int getReferenceSystem() { |
||
202 | return this.referenceSystem.getSelectedIndex(); |
||
203 | } |
||
204 | 23419 | vcaballero | } |