Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / GradientFill.java @ 13950

History | View | Annotate | Download (8.48 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 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

    
59
import com.iver.andami.PluginServices;
60
import com.iver.cit.gvsig.fmap.core.FShape;
61
import com.iver.cit.gvsig.fmap.core.symbols.GradientFillSymbol;
62
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
63
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
64
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
65
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
66
import com.iver.utiles.swing.JComboBox;
67

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

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

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

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

    
115
                GridBagLayoutPanel aux2;
116

    
117
                aux2= new GridBagLayoutPanel();
118

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

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

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

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

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

    
139
                aux.add(aux2);
140

    
141
                aux2 = new GridBagLayoutPanel();
142

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

    
147

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

    
153

    
154

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

    
157
                GridBagLayoutPanel aux4 = new GridBagLayoutPanel();
158

    
159

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

    
164

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

    
168

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

    
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

    
185
                tabs.add(myTab);
186
        }
187

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

    
192
        public ISymbol getLayer() {
193

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

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

    
202

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

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

    
211
                layer.setGradientColor(selcolors);
212

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

    
215
                return layer;
216
        }
217

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

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

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

    
230
        public void refreshControls(ISymbol layer) {
231

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

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

    
245
                gradientStyle.addActionListener(this);
246

    
247

    
248

    
249

    
250
        }
251

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

    
256
                        gradientIntervals.setMaxValue(gradientColor.getSelectedColors().length);
257

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

    
263
                }
264
                if (c.equals(gradientStyle)) {
265

    
266
                        if(gradientStyle.getSelectedIndex()==2) {
267
                                gradientAngle.setInteger(0);
268
                                gradientAngle.setEnabled(false);
269
                        }
270
                        else gradientAngle.setEnabled(true);
271
                }
272

    
273
                outline = (ILineSymbol) btnOutline.getSymbol();
274
                fireSymbolChangedEvent();
275
        }
276

    
277
        /**
278
         * Establishes the values for the JCombobox where the user can select the
279
         * different styles for the gradient
280
         * @return
281
         */
282
        private JComboBox getCmbgradientStyle() {
283
                if (gradientStyle == null) {
284
                        gradientStyle = new JComboBox(new String[] {
285
                                        PluginServices.getText(this, "buffered"),
286
                                        PluginServices.getText(this, "lineal"),
287
                                        PluginServices.getText(this, "circular"),
288
                                        PluginServices.getText(this, "rectangular")
289
                        });
290

    
291
                }
292

    
293
                return gradientStyle;
294
        }
295

    
296
}