Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleFill.java @ 21299

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

    
42
/* CVS MESSAGES:
43
*
44
* $Id: SimpleFill.java 21299 2008-06-06 10:23:57Z vcaballero $
45
* $Log$
46
* Revision 1.17  2007-09-19 10:45:05  jvidal
47
* bug solved
48
*
49
* Revision 1.16  2007/08/16 06:54:35  jvidal
50
* javadoc updated
51
*
52
* Revision 1.15  2007/08/10 07:28:25  jaume
53
* translations
54
*
55
* Revision 1.14  2007/08/08 11:49:15  jaume
56
* refactored to avoid provide more than one EditorTool
57
*
58
* Revision 1.13  2007/08/08 10:16:53  jvidal
59
* javadoc
60
*
61
* Revision 1.12  2007/08/03 11:29:13  jaume
62
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
63
*
64
* Revision 1.11  2007/07/23 07:01:13  jaume
65
* outline setting bug fixed
66
*
67
* Revision 1.10  2007/07/12 10:43:55  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.9  2007/06/29 13:07:33  jaume
71
* +PictureLineSymbol
72
*
73
* Revision 1.8  2007/05/21 10:38:27  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.7  2007/05/09 16:08:14  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.6  2007/04/05 16:08:34  jaume
80
* Styled labeling stuff
81
*
82
* Revision 1.5  2007/04/04 16:01:14  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.4  2007/03/30 09:39:45  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.3  2007/03/28 16:44:08  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.2  2007/03/09 11:25:00  jaume
92
* Advanced symbology (start committing)
93
*
94
* Revision 1.1.2.4  2007/02/21 16:09:35  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.1.2.3  2007/02/21 07:35:14  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
101
* some bug fixes in the editor and removed unnecessary imports
102
*
103
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.1  2007/01/16 11:52:11  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.4  2006/11/13 09:15:23  jaume
110
* javadoc and some clean-up
111
*
112
* Revision 1.3  2006/11/06 16:06:52  jaume
113
* *** empty log message ***
114
*
115
* Revision 1.2  2006/10/30 19:30:35  jaume
116
* *** empty log message ***
117
*
118
* Revision 1.1  2006/10/27 12:41:09  jaume
119
* GUI
120
*
121
*
122
*/
123
package com.iver.cit.gvsig.gui.styling;
124

    
125
import java.awt.Color;
126
import java.awt.Dimension;
127
import java.awt.FlowLayout;
128
import java.awt.event.ActionEvent;
129
import java.awt.event.ActionListener;
130
import java.util.ArrayList;
131

    
132
import javax.swing.JCheckBox;
133
import javax.swing.JPanel;
134
import javax.swing.JSlider;
135
import javax.swing.event.ChangeEvent;
136
import javax.swing.event.ChangeListener;
137

    
138
import org.gvsig.fmap.geom.Geometry;
139
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol;
140
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
141
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleFillSymbol;
142
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
143
import org.gvsig.gui.beans.swing.JBlank;
144
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
145

    
146
import com.iver.andami.PluginServices;
147
import com.iver.andami.messages.NotificationManager;
148
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
149
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor;
150
import com.iver.cit.gvsig.gui.styling.EditorTool;
151
import com.iver.cit.gvsig.gui.styling.SymbolEditor;
152
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
153
/**
154
* <b>SimpleFill</b> allows to store and modify the properties that fills a
155
* polygon with a padding and an outline<p>
156
* <p>
157
* This functionality is carried out thanks to a tab (simple fill)which is included
158
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
159
* in AbstractTypeSymbolEditor.<p>
160
* <p>
161
* This tab permits the user to change the color of the padding
162
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
163
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
164
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
165
*
166
*
167
*@see AbstractTypeSymbolEditor
168
*@author jaume dominguez faus - jaume.dominguez@iver.es
169
*/
170
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener {
171
        private ColorChooserPanel jccFillColor;
172
        private JIncrementalNumberField txtOutlineWidth;
173
        private ArrayList tabs = new ArrayList();
174
        private JSymbolPreviewButton btnOutline;
175
        private JSlider sldOutlineTransparency;
176
        private int outlineAlpha;
177
        private ILineSymbol outline;
178
        private JCheckBox useBorder;
179

    
180
        public SimpleFill(SymbolEditor owner) {
181
                super(owner);
182
                initialize();
183
        }
184

    
185
        public String getName() {
186
                return PluginServices.getText(SimpleFill.class, "simple_fill_symbol");
187
        }
188

    
189
        public JPanel[] getTabs() {
190
                return (JPanel[]) tabs.toArray(new JPanel[0]);
191
        }
192

    
193
        /**
194
         * Initializes the parameters that allows the user to fill the padding of
195
         * a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
196
         * SymbolEditor panel with default values for the different attributes.
197
         */
198
        private void initialize() {
199
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
200
                myTab.setName(PluginServices.getText(this, "simple_fill"));
201
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
202

    
203
                jccFillColor = new ColorChooserPanel(true,true);
204
                jccFillColor.setAlpha(255);
205
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
206

    
207
                JPanel aux2 = new JPanel();
208
                btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
209
                btnOutline.setPreferredSize(new Dimension(100, 35));
210
                aux2.add(btnOutline);
211

    
212
                aux.addComponent(new JBlank(10, 10));
213
                useBorder = new JCheckBox(PluginServices.getText(this, "use_outline"));
214
                aux.addComponent(useBorder, aux2);
215
                aux.addComponent(new JBlank(10, 10));
216

    
217
                sldOutlineTransparency = new JSlider();
218
                sldOutlineTransparency.setValue(100);
219
                aux.addComponent(PluginServices.getText(this, "outline")+":",
220
                                aux2);
221
                aux.addComponent(PluginServices.getText(this, "outline_opacity"), sldOutlineTransparency);
222
                txtOutlineWidth = new JIncrementalNumberField("", 25, 0, Double.MAX_VALUE, 1);
223
                aux.addComponent(PluginServices.getText(this, "outline_width"), txtOutlineWidth);
224
                myTab.add(aux);
225

    
226
                useBorder.addActionListener(this);
227
                jccFillColor.addActionListener(this);
228
                btnOutline.addActionListener(this);
229
                txtOutlineWidth.addActionListener(this);
230
                sldOutlineTransparency.addChangeListener(this);
231
                tabs.add(myTab);
232
        }
233

    
234
        public ISymbol getLayer() {
235
                SimpleFillSymbol layer = new SimpleFillSymbol();
236

    
237
                layer.setHasOutline(useBorder.isSelected());
238
                outline = (ILineSymbol) btnOutline.getSymbol();
239

    
240
                if (outline!=null) {
241
                        outline.setLineWidth(txtOutlineWidth.getDouble());
242
                        outline.setAlpha(outlineAlpha);
243
                }
244

    
245
                layer.setOutline(outline);
246

    
247
                layer.setHasFill(jccFillColor.getUseColorisSelected());
248
                Color c = jccFillColor.getColor();
249
                if (c != null)
250
                        c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
251
                layer.setFillColor(c);
252

    
253
                return layer;
254
        }
255

    
256
        public void refreshControls(ISymbol layer) {
257
                SimpleFillSymbol sym;
258
                try {
259
                        if (layer == null) {
260
                                // initialize defaults
261
                                NotificationManager.addWarning(getClass().getName()+":: should be unreachable code", new Exception());
262
                        } else {
263

    
264

    
265
                                //fill
266

    
267
                                sym = (SimpleFillSymbol) layer;
268
                                jccFillColor.setUseColorIsSelected(sym.hasFill());
269
                                jccFillColor.setColor(sym.getFillColor());
270
                                //outline
271

    
272
                                sldOutlineTransparency.removeChangeListener(this);
273

    
274
                                outline=sym.getOutline();
275
                                btnOutline.setSymbol(outline);
276
                                useBorder.setSelected(sym.hasOutline());
277

    
278
                                if (outline != null) {
279
                                        outlineAlpha = outline.getAlpha();
280
                                        sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100));
281
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
282
                                } else {
283
                                        sldOutlineTransparency.setValue(100);
284
                                }
285

    
286
                                sldOutlineTransparency.addChangeListener(this);
287

    
288
                        }
289
                } catch (IndexOutOfBoundsException ioEx) {
290
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
291
                } catch (ClassCastException ccEx) {
292
                        NotificationManager.addWarning("Illegal casting from " +
293
                                        layer.getClassName() + " to " + getSymbolClass().
294
                                        getName() + ".", ccEx);
295

    
296
                }
297
        }
298

    
299
        public Class getSymbolClass() {
300
                return SimpleFillSymbol.class;
301
        }
302

    
303
        public void actionPerformed(ActionEvent e) {
304
                Object s = e.getSource();
305

    
306
                if (s.equals(btnOutline)) {
307
                        ISymbol sym = btnOutline.getSymbol();
308
                        if (sym instanceof ILineSymbol) {
309
                                ILineSymbol outline = (ILineSymbol) sym;
310
                                if (outline != null)
311
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
312
                        }
313

    
314
                }
315

    
316

    
317
                fireSymbolChangedEvent();
318
        }
319

    
320
        public void stateChanged(ChangeEvent e) {
321
                Object s = e.getSource();
322

    
323

    
324
                if (s.equals(sldOutlineTransparency)) {
325
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
326
                }
327

    
328
                outline = (ILineSymbol) btnOutline.getSymbol();
329

    
330
                fireSymbolChangedEvent();
331
        }
332

    
333
        public EditorTool[] getEditorTools() {
334
                return null;
335
        }
336

    
337

    
338

    
339

    
340
}