Statistics
| Revision:

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

History | View | Annotate | Download (9.51 KB)

1 14736 jdominguez
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2 9745 jaume
 *
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 14736 jdominguez
 *   Av. Blasco Ib??ez, 50
24 9745 jaume
 *   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$
45
* $Log$
46 13826 jvidal
* 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 13100 jvidal
* javadoc updated
51
*
52
* Revision 1.15  2007/08/10 07:28:25  jaume
53 13011 jaume
* translations
54
*
55
* Revision 1.14  2007/08/08 11:49:15  jaume
56 12982 jaume
* refactored to avoid provide more than one EditorTool
57
*
58
* Revision 1.13  2007/08/08 10:16:53  jvidal
59 12970 jvidal
* javadoc
60
*
61
* Revision 1.12  2007/08/03 11:29:13  jaume
62 12911 jaume
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
63
*
64
* Revision 1.11  2007/07/23 07:01:13  jaume
65 12730 jaume
* outline setting bug fixed
66
*
67
* Revision 1.10  2007/07/12 10:43:55  jaume
68 12561 jaume
* *** empty log message ***
69
*
70
* Revision 1.9  2007/06/29 13:07:33  jaume
71 12427 jaume
* +PictureLineSymbol
72
*
73
* Revision 1.8  2007/05/21 10:38:27  jaume
74 11548 jaume
* *** empty log message ***
75
*
76 11734 jaume
* Revision 1.7  2007/05/09 16:08:14  jaume
77
* *** empty log message ***
78
*
79 11548 jaume
* Revision 1.6  2007/04/05 16:08:34  jaume
80 11073 jaume
* Styled labeling stuff
81
*
82
* Revision 1.5  2007/04/04 16:01:14  jaume
83 10959 jaume
* *** empty log message ***
84
*
85 11055 jaume
* Revision 1.4  2007/03/30 09:39:45  jaume
86
* *** empty log message ***
87
*
88 10986 jaume
* Revision 1.3  2007/03/28 16:44:08  jaume
89
* *** empty log message ***
90
*
91 10959 jaume
* Revision 1.2  2007/03/09 11:25:00  jaume
92 10679 jaume
* Advanced symbology (start committing)
93
*
94
* Revision 1.1.2.4  2007/02/21 16:09:35  jaume
95 9745 jaume
* *** empty log message ***
96
*
97 10679 jaume
* 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 9745 jaume
* 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 10679 jaume
import java.awt.Color;
126 9745 jaume
import java.awt.Dimension;
127
import java.awt.FlowLayout;
128 10679 jaume
import java.awt.event.ActionEvent;
129
import java.awt.event.ActionListener;
130 9745 jaume
import java.util.ArrayList;
131
132 13826 jvidal
import javax.swing.JCheckBox;
133 9745 jaume
import javax.swing.JPanel;
134 10679 jaume
import javax.swing.JSlider;
135
import javax.swing.event.ChangeEvent;
136
import javax.swing.event.ChangeListener;
137 9745 jaume
138 21299 vcaballero
import org.gvsig.fmap.geom.Geometry;
139 20994 jmvivo
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 9745 jaume
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
143 13826 jvidal
import org.gvsig.gui.beans.swing.JBlank;
144 11734 jaume
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
145 9745 jaume
146
import com.iver.andami.PluginServices;
147 10679 jaume
import com.iver.andami.messages.NotificationManager;
148 9745 jaume
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
149 10679 jaume
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
150 11055 jaume
/**
151 13100 jvidal
* <b>SimpleFill</b> allows to store and modify the properties that fills a
152 12970 jvidal
* polygon with a padding and an outline<p>
153
* <p>
154
* This functionality is carried out thanks to a tab (simple fill)which is included
155
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
156
* in AbstractTypeSymbolEditor.<p>
157
* <p>
158
* This tab permits the user to change the color of the padding
159
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
160
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
161
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
162 11055 jaume
*
163
*
164 12970 jvidal
*@see AbstractTypeSymbolEditor
165
*@author jaume dominguez faus - jaume.dominguez@iver.es
166 11055 jaume
*/
167 12911 jaume
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener {
168 9745 jaume
        private ColorChooserPanel jccFillColor;
169 11734 jaume
        private JIncrementalNumberField txtOutlineWidth;
170 9745 jaume
        private ArrayList tabs = new ArrayList();
171 10679 jaume
        private JSymbolPreviewButton btnOutline;
172
        private JSlider sldOutlineTransparency;
173 14736 jdominguez
        private int outlineAlpha;
174 13826 jvidal
        private ILineSymbol outline;
175
        private JCheckBox useBorder;
176 10959 jaume
177 9745 jaume
        public SimpleFill(SymbolEditor owner) {
178
                super(owner);
179
                initialize();
180
        }
181
182
        public String getName() {
183 13011 jaume
                return PluginServices.getText(SimpleFill.class, "simple_fill_symbol");
184 9745 jaume
        }
185
186
        public JPanel[] getTabs() {
187
                return (JPanel[]) tabs.toArray(new JPanel[0]);
188
        }
189
190 12970 jvidal
        /**
191
         * Initializes the parameters that allows the user to fill the padding of
192
         * a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
193
         * SymbolEditor panel with default values for the different attributes.
194
         */
195 9745 jaume
        private void initialize() {
196
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
197
                myTab.setName(PluginServices.getText(this, "simple_fill"));
198
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
199 10959 jaume
200 18623 jdominguez
                jccFillColor = new ColorChooserPanel(true,true);
201 9745 jaume
                jccFillColor.setAlpha(255);
202 10679 jaume
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
203 10959 jaume
204 11548 jaume
                JPanel aux2 = new JPanel();
205 21299 vcaballero
                btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
206 10679 jaume
                btnOutline.setPreferredSize(new Dimension(100, 35));
207 11548 jaume
                aux2.add(btnOutline);
208 13826 jvidal
209
                aux.addComponent(new JBlank(10, 10));
210
                useBorder = new JCheckBox(PluginServices.getText(this, "use_outline"));
211
                aux.addComponent(useBorder, aux2);
212
                aux.addComponent(new JBlank(10, 10));
213
214 10679 jaume
                sldOutlineTransparency = new JSlider();
215
                sldOutlineTransparency.setValue(100);
216
                aux.addComponent(PluginServices.getText(this, "outline")+":",
217 11548 jaume
                                aux2);
218
                aux.addComponent(PluginServices.getText(this, "outline_opacity"), sldOutlineTransparency);
219 11734 jaume
                txtOutlineWidth = new JIncrementalNumberField("", 25, 0, Double.MAX_VALUE, 1);
220 11548 jaume
                aux.addComponent(PluginServices.getText(this, "outline_width"), txtOutlineWidth);
221 9745 jaume
                myTab.add(aux);
222
223 13826 jvidal
                useBorder.addActionListener(this);
224 10679 jaume
                jccFillColor.addActionListener(this);
225
                btnOutline.addActionListener(this);
226
                txtOutlineWidth.addActionListener(this);
227
                sldOutlineTransparency.addChangeListener(this);
228 9745 jaume
                tabs.add(myTab);
229
        }
230
231 10679 jaume
        public ISymbol getLayer() {
232 12561 jaume
                SimpleFillSymbol layer = new SimpleFillSymbol();
233 21299 vcaballero
234 18623 jdominguez
                layer.setHasOutline(useBorder.isSelected());
235
                outline = (ILineSymbol) btnOutline.getSymbol();
236 10959 jaume
237 10679 jaume
                if (outline!=null) {
238 11548 jaume
                        outline.setLineWidth(txtOutlineWidth.getDouble());
239 10679 jaume
                        outline.setAlpha(outlineAlpha);
240
                }
241 10959 jaume
242 13826 jvidal
                layer.setOutline(outline);
243 21299 vcaballero
244 18623 jdominguez
                layer.setHasFill(jccFillColor.getUseColorisSelected());
245 10679 jaume
                Color c = jccFillColor.getColor();
246 18623 jdominguez
                if (c != null)
247
                        c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
248 12561 jaume
                layer.setFillColor(c);
249 21299 vcaballero
250 12561 jaume
                return layer;
251 9745 jaume
        }
252
253 10679 jaume
        public void refreshControls(ISymbol layer) {
254
                SimpleFillSymbol sym;
255
                try {
256
                        if (layer == null) {
257
                                // initialize defaults
258 12730 jaume
                                NotificationManager.addWarning(getClass().getName()+":: should be unreachable code", new Exception());
259 10679 jaume
                        } else {
260 13826 jvidal
261
262
                                //fill
263 14736 jdominguez
264 10679 jaume
                                sym = (SimpleFillSymbol) layer;
265 18623 jdominguez
                                jccFillColor.setUseColorIsSelected(sym.hasFill());
266 10679 jaume
                                jccFillColor.setColor(sym.getFillColor());
267 13826 jvidal
                                //outline
268
269
                                sldOutlineTransparency.removeChangeListener(this);
270
271
                                outline=sym.getOutline();
272
                                btnOutline.setSymbol(outline);
273 18623 jdominguez
                                useBorder.setSelected(sym.hasOutline());
274 21299 vcaballero
275 10679 jaume
                                if (outline != null) {
276 10959 jaume
                                        outlineAlpha = outline.getAlpha();
277 13826 jvidal
                                        sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100));
278 12730 jaume
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
279 10679 jaume
                                } else {
280
                                        sldOutlineTransparency.setValue(100);
281
                                }
282 11548 jaume
283 13826 jvidal
                                sldOutlineTransparency.addChangeListener(this);
284 12970 jvidal
285 10679 jaume
                        }
286
                } catch (IndexOutOfBoundsException ioEx) {
287
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
288
                } catch (ClassCastException ccEx) {
289
                        NotificationManager.addWarning("Illegal casting from " +
290
                                        layer.getClassName() + " to " + getSymbolClass().
291
                                        getName() + ".", ccEx);
292 9745 jaume
293 10679 jaume
                }
294 9745 jaume
        }
295
296
        public Class getSymbolClass() {
297 10679 jaume
                return SimpleFillSymbol.class;
298 9745 jaume
        }
299
300 10679 jaume
        public void actionPerformed(ActionEvent e) {
301 14736 jdominguez
                Object s = e.getSource();
302
303 18623 jdominguez
                if (s.equals(btnOutline)) {
304 16224 jdominguez
                        ISymbol sym = btnOutline.getSymbol();
305
                        if (sym instanceof ILineSymbol) {
306
                                ILineSymbol outline = (ILineSymbol) sym;
307
                                if (outline != null)
308 21299 vcaballero
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
309 16224 jdominguez
                        }
310 21299 vcaballero
311 14736 jdominguez
                }
312
313
314 10679 jaume
                fireSymbolChangedEvent();
315
        }
316
317
        public void stateChanged(ChangeEvent e) {
318
                Object s = e.getSource();
319 14736 jdominguez
320
321
                if (s.equals(sldOutlineTransparency)) {
322 10679 jaume
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
323
                }
324 13826 jvidal
325
                outline = (ILineSymbol) btnOutline.getSymbol();
326
327 10679 jaume
                fireSymbolChangedEvent();
328
        }
329 11073 jaume
330 12982 jaume
        public EditorTool[] getEditorTools() {
331 11073 jaume
                return null;
332
        }
333 13826 jvidal
334
335
336
337 12982 jaume
}