Revision 13665

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/GradientFill.java
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 com.iver.cit.gvsig.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.JComponent;
51
import javax.swing.JPanel;
52

  
53
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
54
import org.gvsig.gui.beans.swing.JBlank;
55
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
56
import org.gvsig.gui.beans.swing.ValidatingTextField;
57
import org.gvsig.raster.datastruct.ColorItem;
58
import org.gvsig.raster.datastruct.ColorTable;
59

  
60
import com.iver.andami.PluginServices;
61
import com.iver.cit.gvsig.fmap.core.FShape;
62
import com.iver.cit.gvsig.fmap.core.symbols.GradientFillSymbol;
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.project.documents.view.legend.gui.JSymbolPreviewButton;
67
import com.iver.utiles.swing.JComboBox;
68

  
69
/**
70
* <b>GradientFill</b> allows to store and modify the properties that fills a
71
* polygon with a padding with a gradient<p>
72
* <p>
73
* This functionality is carried out thanks to a tab (gradient fill)which is included
74
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
75
* in AbstractTypeSymbolEditor.<p>
76
* <p>
77
* This tab permits the user to change the different properties of the gradient such
78
* as its style <b>gradientStyle</b>, angle of rotation <b>gradientAngle</b>,
79
* percentage <b>gradientPercentage</b>, intervals <b>gradientIntervals</b> and the outline <b>outline</b> of the polygon.Also the
80
* user can select the colors for the gradient <b>gradientColor</b>.
81
*
82
*
83
*
84
*@see AbstractTypeSymbolEditor
85
*@author pepe vidal salvador - jose.vidal.salvador@iver.es
86
*/
87
public class GradientFill extends AbstractTypeSymbolEditor implements ActionListener {
88

  
89
	private JIncrementalNumberField gradientIntervals;
90
	private JIncrementalNumberField gradientPercentage;
91
	private JIncrementalNumberField gradientAngle;
92
	private JComboBoxColorScheme gradientColor;
93
	private JComboBox gradientStyle;
94
	private JSymbolPreviewButton btnOutline;
95
	private ILineSymbol outline;
96
	private ArrayList tabs = new ArrayList();
97
	/**
98
	 * Constructor method
99
	 * @param owner
100
	 */
101
	public GradientFill(SymbolEditor owner) {
102
		super(owner);
103
		initialize();
104
	}
105
	/**
106
	 * This method initializes this
107
	 *
108
	 */
109
	private void initialize() {
110

  
111
		JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
112
		myTab.setName(PluginServices.getText(this, "gradient_fill"));
113

  
114
		JPanel aux = new JPanel(new GridLayout(1, 2, 20, 5));
115

  
116
		GridBagLayoutPanel aux2;
117

  
118
		aux2= new GridBagLayoutPanel();
119

  
120
		aux2.addComponent(new JBlank(5,20));
121
		gradientIntervals = new JIncrementalNumberField("",
122
														10,
123
														ValidatingTextField.INTEGER_VALIDATOR,
124
														ValidatingTextField.NUMBER_CLEANER,
125
														1,
126
														100,
127
														1);
128
		aux2.addComponent(PluginServices.getText(this, "intervals"), gradientIntervals);
129

  
130
		aux2.addComponent(new JBlank(5,5));
131

  
132
		gradientPercentage = new JIncrementalNumberField("",10,0,100,1);
133
		aux2.addComponent(PluginServices.getText(this,"percentage"),gradientPercentage);
134

  
135
		aux2.addComponent(new JBlank(5,5));
136

  
137
		gradientAngle = new JIncrementalNumberField("",10,0,360,1);
138
		aux2.addComponent(PluginServices.getText(this,"angle"),gradientAngle);
139

  
140
		aux.add(aux2);
141

  
142
		aux2 = new GridBagLayoutPanel();
143

  
144
		aux2.addComponent(new JBlank(5,20));
145
		gradientStyle = getCmbgradientStyle();
146
		aux2.addComponent(PluginServices.getText(this,"style"),gradientStyle);
147

  
148

  
149
		aux2.addComponent(new JBlank(5,5));
150
		aux2.addComponent(PluginServices.getText(this, "outline")+":",
151
				btnOutline = new JSymbolPreviewButton(FShape.LINE));
152
		aux2.addComponent(new JBlank(5,5));
153

  
154

  
155

  
156
		JPanel aux3 = new JPanel(new GridLayout(1, 2, 20, 5));
157

  
158
		GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
159

  
160

  
161
		aux4.addComponent(new JBlank(5,5));
162
		aux4.addComponent(PluginServices.getText(this, "gradient_color")+":",
163
				gradientColor = new JComboBoxColorScheme(false));
164

  
165

  
166
		int colorCount = gradientColor.getSelectedColors().length;
167
		gradientIntervals.setMaxValue(colorCount);
168

  
169

  
170
		aux3.add(aux4);
171
		aux.add(aux2);
172
		myTab.add(aux);
173
		myTab.add(aux3);
174

  
175

  
176
		gradientIntervals.addActionListener(this);
177
		gradientPercentage.addActionListener(this);
178
		gradientAngle.addActionListener(this);
179
		gradientColor.addActionListener(this);
180
		gradientStyle.addActionListener(this);
181
		btnOutline.addActionListener(this);
182

  
183

  
184
		tabs.add(myTab);
185
	}
186

  
187
	public EditorTool[] getEditorTools() {
188
		return null;
189
	}
190

  
191
	public ISymbol getLayer() {
192

  
193
		GradientFillSymbol layer=new GradientFillSymbol();
194
		layer.setOutline(outline);
195
		layer.setStyle(gradientStyle.getSelectedIndex());
196
		layer.setIntervals(gradientIntervals.getInteger());
197

  
198
		layer.setAngle(gradientAngle.getDouble()*FConstant.DEGREE_TO_RADIANS);
199
		layer.setPercentage(gradientPercentage.getDouble());
200

  
201

  
202
		ColorItem[] array=new ColorItem [gradientColor.getSelectedColors().length];
203
		array=gradientColor.getSelectedColors();
204
		Color[] selcolors = new Color [gradientColor.getSelectedColors().length];;
205

  
206
		for(int i=0;i<array.length;i++) {
207
			selcolors[i]=array[i].getColor();
208
		}
209

  
210
		layer.setGradientColor(selcolors);
211

  
212
		layer.setindexgradientcolor(gradientColor.getSelectedIndex());
213

  
214
		return layer;
215
	}
216

  
217
	public String getName() {
218
		return PluginServices.getText(GradientFill.class, "gradient_fill_symbol");
219
	}
220

  
221
	public Class getSymbolClass() {
222
		return GradientFillSymbol.class;
223
	}
224

  
225
	public JPanel[] getTabs() {
226
		return (JPanel[]) tabs.toArray(new JPanel[tabs.size()]);
227
	}
228

  
229
	public void refreshControls(ISymbol layer) {
230

  
231
		gradientStyle.removeActionListener(this);
232
		GradientFillSymbol sym = (GradientFillSymbol) layer;
233
		gradientStyle.setSelectedIndex(sym.getStyle());
234
		outline = sym.getOutline();
235
		btnOutline.setSymbol(outline);
236

  
237
		int colorCount = (sym.getGradientColor().length);
238
		gradientIntervals.setMaxValue(colorCount);
239
		gradientIntervals.setInteger(sym.getIntervals());
240
		gradientAngle.setDouble(sym.getAngle()/FConstant.DEGREE_TO_RADIANS);
241
		gradientPercentage.setDouble(sym.getPercentage());
242
		gradientColor.setSelectedIndex(sym.getindexgradientcolor());
243
		gradientStyle.addActionListener(this);
244

  
245

  
246

  
247

  
248
	}
249

  
250
	public void actionPerformed(ActionEvent e) {
251
		JComponent c = (JComponent) e.getSource();
252
		if (c.equals(gradientColor)) {
253

  
254
			gradientIntervals.setMaxValue(gradientColor.getSelectedColors().length);
255

  
256
			if (gradientIntervals.getInteger() > gradientColor.getSelectedColors().length)
257
				gradientIntervals.setInteger(gradientColor.getSelectedColors().length);
258
			else
259
				gradientIntervals.setInteger(gradientIntervals.getInteger());
260

  
261
		}
262

  
263
		outline = (ILineSymbol) btnOutline.getSymbol();
264
		fireSymbolChangedEvent();
265
	}
266

  
267
	/**
268
	 * Establishes the values for the JCombobox where the user can select the
269
	 * different styles for the gradient
270
	 * @return
271
	 */
272
	private JComboBox getCmbgradientStyle() {
273
		if (gradientStyle == null) {
274
			gradientStyle = new JComboBox(new String[] {
275
					PluginServices.getText(this, "buffered"),
276
					PluginServices.getText(this, "lineal"),
277
					PluginServices.getText(this, "circular"),
278
					PluginServices.getText(this, "rectangular")
279
			});
280

  
281
		}
282

  
283
		return gradientStyle;
284
	}
285

  
286
}
0 287

  

Also available in: Unified diff