root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / GradientFill.java @ 20768
History | View | Annotate | Download (9.17 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.styling; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.FlowLayout; |
45 |
import java.awt.GridLayout; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.JCheckBox; |
51 |
import javax.swing.JComponent; |
52 |
import javax.swing.JPanel; |
53 |
|
54 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
55 |
import org.gvsig.gui.beans.swing.JBlank; |
56 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
57 |
import org.gvsig.gui.beans.swing.ValidatingTextField; |
58 |
import org.gvsig.raster.datastruct.ColorItem; |
59 |
import org.gvsig.symbology.fmap.symbols.GradientFillSymbol; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
63 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
64 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
65 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
66 |
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor; |
67 |
import com.iver.cit.gvsig.gui.styling.EditorTool; |
68 |
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme; |
69 |
import com.iver.cit.gvsig.gui.styling.SymbolEditor; |
70 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton; |
71 |
import com.iver.utiles.swing.JComboBox; |
72 |
|
73 |
/**
|
74 |
* <b>GradientFill</b> allows to store and modify the properties that fills a
|
75 |
* polygon with a padding with a gradient<p>
|
76 |
* <p>
|
77 |
* This functionality is carried out thanks to a tab (gradient fill)which is included
|
78 |
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
|
79 |
* in AbstractTypeSymbolEditor.<p>
|
80 |
* <p>
|
81 |
* This tab permits the user to change the different properties of the gradient such
|
82 |
* as its style <b>gradientStyle</b>, angle of rotation <b>gradientAngle</b>,
|
83 |
* percentage <b>gradientPercentage</b>, intervals <b>gradientIntervals</b> and the outline <b>outline</b> of the polygon.Also the
|
84 |
* user can select the colors for the gradient <b>gradientColor</b>.
|
85 |
*
|
86 |
*
|
87 |
*
|
88 |
*@see AbstractTypeSymbolEditor
|
89 |
*@author pepe vidal salvador - jose.vidal.salvador@iver.es
|
90 |
*/
|
91 |
public class GradientFill extends AbstractTypeSymbolEditor implements ActionListener { |
92 |
|
93 |
private JIncrementalNumberField gradientIntervals;
|
94 |
private JIncrementalNumberField gradientPercentage;
|
95 |
private JIncrementalNumberField gradientAngle;
|
96 |
private JComboBoxColorScheme gradientColor;
|
97 |
private JComboBox gradientStyle; |
98 |
private JSymbolPreviewButton btnOutline;
|
99 |
private ILineSymbol outline;
|
100 |
private ArrayList<JPanel> tabs = new ArrayList<JPanel>(); |
101 |
private JCheckBox useBorder; |
102 |
|
103 |
/**
|
104 |
* Constructor method
|
105 |
* @param owner
|
106 |
*/
|
107 |
public GradientFill(SymbolEditor owner) {
|
108 |
super(owner);
|
109 |
initialize(); |
110 |
} |
111 |
/**
|
112 |
* This method initializes this
|
113 |
*
|
114 |
*/
|
115 |
private void initialize() { |
116 |
|
117 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
118 |
myTab.setName(PluginServices.getText(this, "gradient_fill")); |
119 |
|
120 |
JPanel aux = new JPanel(new GridLayout(1, 2, 20, 5)); |
121 |
|
122 |
GridBagLayoutPanel aux2; |
123 |
|
124 |
aux2= new GridBagLayoutPanel();
|
125 |
|
126 |
aux2.addComponent(new JBlank(5,20)); |
127 |
gradientIntervals = new JIncrementalNumberField("", |
128 |
10,
|
129 |
ValidatingTextField.INTEGER_VALIDATOR, |
130 |
ValidatingTextField.NUMBER_CLEANER, |
131 |
1,
|
132 |
100,
|
133 |
1);
|
134 |
aux2.addComponent(PluginServices.getText(this, "intervals"), gradientIntervals); |
135 |
aux2.addComponent(new JBlank(5,5)); |
136 |
|
137 |
gradientPercentage = new JIncrementalNumberField("",10,0,100,1); |
138 |
aux2.addComponent(PluginServices.getText(this,"percentage"),gradientPercentage); |
139 |
gradientPercentage.setDouble(100);
|
140 |
aux2.addComponent(new JBlank(5,5)); |
141 |
|
142 |
gradientAngle = new JIncrementalNumberField("",10,0,360,1); |
143 |
aux2.addComponent(PluginServices.getText(this,"angle"),gradientAngle); |
144 |
|
145 |
aux.add(aux2); |
146 |
|
147 |
aux2 = new GridBagLayoutPanel();
|
148 |
|
149 |
aux2.addComponent(new JBlank(5,20)); |
150 |
gradientStyle = getCmbgradientStyle(); |
151 |
aux2.addComponent(PluginServices.getText(this,"style"),gradientStyle); |
152 |
|
153 |
|
154 |
aux2.addComponent(new JBlank(5,5)); |
155 |
useBorder = new JCheckBox(PluginServices.getText(this, "use_outline")); |
156 |
aux2.addComponent(useBorder); |
157 |
aux2.addComponent(PluginServices.getText(this, "outline")+":", |
158 |
btnOutline = new JSymbolPreviewButton(FShape.LINE));
|
159 |
aux2.addComponent(new JBlank(5,5)); |
160 |
|
161 |
|
162 |
|
163 |
JPanel aux3 = new JPanel(new GridLayout(1, 2, 20, 5)); |
164 |
|
165 |
GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
|
166 |
|
167 |
|
168 |
aux4.addComponent(new JBlank(5,5)); |
169 |
aux4.addComponent(PluginServices.getText(this, "gradient_color")+":", |
170 |
gradientColor = new JComboBoxColorScheme(false)); |
171 |
|
172 |
|
173 |
int colorCount = gradientColor.getSelectedColors().length;
|
174 |
gradientIntervals.setMaxValue(colorCount); |
175 |
|
176 |
|
177 |
aux3.add(aux4); |
178 |
aux.add(aux2); |
179 |
myTab.add(aux); |
180 |
myTab.add(aux3); |
181 |
|
182 |
|
183 |
|
184 |
gradientIntervals.addActionListener(this);
|
185 |
gradientPercentage.addActionListener(this);
|
186 |
gradientAngle.addActionListener(this);
|
187 |
gradientColor.addActionListener(this);
|
188 |
gradientStyle.addActionListener(this);
|
189 |
btnOutline.addActionListener(this);
|
190 |
useBorder.addActionListener(this);
|
191 |
|
192 |
|
193 |
|
194 |
tabs.add(myTab); |
195 |
} |
196 |
|
197 |
public EditorTool[] getEditorTools() { |
198 |
return null; |
199 |
} |
200 |
|
201 |
public ISymbol getLayer() {
|
202 |
|
203 |
GradientFillSymbol layer=new GradientFillSymbol();
|
204 |
|
205 |
layer.setHasOutline(useBorder.isSelected()); |
206 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
207 |
layer.setOutline(outline); |
208 |
|
209 |
layer.setStyle(gradientStyle.getSelectedIndex()); |
210 |
layer.setIntervals(gradientIntervals.getInteger()); |
211 |
|
212 |
if(gradientStyle.getSelectedIndex()==2) { |
213 |
gradientAngle.setEnabled(false);
|
214 |
} |
215 |
layer.setAngle(gradientAngle.getDouble()*FConstant.DEGREE_TO_RADIANS); |
216 |
layer.setPercentage(gradientPercentage.getDouble()); |
217 |
|
218 |
|
219 |
ColorItem[] array=new ColorItem [gradientColor.getSelectedColors().length]; |
220 |
array=gradientColor.getSelectedColors(); |
221 |
Color[] selcolors = new Color [gradientColor.getSelectedColors().length];; |
222 |
|
223 |
for(int i=0;i<array.length;i++) { |
224 |
selcolors[i]=array[i].getColor(); |
225 |
} |
226 |
|
227 |
layer.setGradientColor(selcolors); |
228 |
|
229 |
layer.setindexgradientcolor(gradientColor.getSelectedIndex()); |
230 |
|
231 |
return layer;
|
232 |
} |
233 |
|
234 |
public String getName() { |
235 |
return PluginServices.getText(GradientFill.class, "gradient_fill_symbol"); |
236 |
} |
237 |
|
238 |
public Class getSymbolClass() { |
239 |
return GradientFillSymbol.class;
|
240 |
} |
241 |
|
242 |
public JPanel[] getTabs() { |
243 |
return (JPanel[]) tabs.toArray(new JPanel[tabs.size()]); |
244 |
} |
245 |
|
246 |
public void refreshControls(ISymbol layer) { |
247 |
|
248 |
gradientStyle.removeActionListener(this);
|
249 |
GradientFillSymbol sym = (GradientFillSymbol) layer; |
250 |
gradientStyle.setSelectedIndex(sym.getStyle()); |
251 |
|
252 |
outline=sym.getOutline(); |
253 |
btnOutline.setSymbol(outline); |
254 |
useBorder.setSelected(sym.hasOutline()); |
255 |
|
256 |
int colorCount = (sym.getGradientColor().length);
|
257 |
gradientIntervals.setMaxValue(colorCount); |
258 |
gradientIntervals.setInteger(sym.getIntervals()); |
259 |
gradientAngle.setDouble(sym.getAngle()/FConstant.DEGREE_TO_RADIANS); |
260 |
gradientPercentage.setDouble(sym.getPercentage()); |
261 |
gradientColor.setSelectedIndex(sym.getindexgradientcolor()); |
262 |
|
263 |
gradientStyle.addActionListener(this);
|
264 |
} |
265 |
|
266 |
public void actionPerformed(ActionEvent e) { |
267 |
JComponent c = (JComponent) e.getSource(); |
268 |
if (c.equals(gradientColor)) {
|
269 |
|
270 |
gradientIntervals.setMaxValue(gradientColor.getSelectedColors().length); |
271 |
|
272 |
if (gradientIntervals.getInteger() > gradientColor.getSelectedColors().length)
|
273 |
gradientIntervals.setInteger(gradientColor.getSelectedColors().length); |
274 |
else
|
275 |
gradientIntervals.setInteger(gradientIntervals.getInteger()); |
276 |
|
277 |
} |
278 |
if (c.equals(gradientStyle)) {
|
279 |
|
280 |
if(gradientStyle.getSelectedIndex()==2) { |
281 |
gradientAngle.setInteger(0);
|
282 |
gradientAngle.setEnabled(false);
|
283 |
} |
284 |
else gradientAngle.setEnabled(true); |
285 |
} |
286 |
|
287 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
288 |
fireSymbolChangedEvent(); |
289 |
} |
290 |
|
291 |
/**
|
292 |
* Establishes the values for the JCombobox where the user can select the
|
293 |
* different styles for the gradient
|
294 |
* @return
|
295 |
*/
|
296 |
private JComboBox getCmbgradientStyle() { |
297 |
if (gradientStyle == null) { |
298 |
gradientStyle = new JComboBox(new String[] { |
299 |
PluginServices.getText(this, "buffered"), |
300 |
PluginServices.getText(this, "lineal"), |
301 |
PluginServices.getText(this, "circular"), |
302 |
PluginServices.getText(this, "rectangular") |
303 |
}); |
304 |
|
305 |
} |
306 |
|
307 |
return gradientStyle;
|
308 |
} |
309 |
|
310 |
} |