Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleFill.java @ 12970

History | View | Annotate | Download (8.76 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 12970 2007-08-08 10:19:40Z jvidal $
45
* $Log$
46
* Revision 1.13  2007-08-08 10:16:53  jvidal
47
* javadoc
48
*
49
* Revision 1.12  2007/08/03 11:29:13  jaume
50
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
51
*
52
* Revision 1.11  2007/07/23 07:01:13  jaume
53
* outline setting bug fixed
54
*
55
* Revision 1.10  2007/07/12 10:43:55  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.9  2007/06/29 13:07:33  jaume
59
* +PictureLineSymbol
60
*
61
* Revision 1.8  2007/05/21 10:38:27  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.7  2007/05/09 16:08:14  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.6  2007/04/05 16:08:34  jaume
68
* Styled labeling stuff
69
*
70
* Revision 1.5  2007/04/04 16:01:14  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.4  2007/03/30 09:39:45  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.3  2007/03/28 16:44:08  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.2  2007/03/09 11:25:00  jaume
80
* Advanced symbology (start committing)
81
*
82
* Revision 1.1.2.4  2007/02/21 16:09:35  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.1.2.3  2007/02/21 07:35:14  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
89
* some bug fixes in the editor and removed unnecessary imports
90
*
91
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1  2007/01/16 11:52:11  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.4  2006/11/13 09:15:23  jaume
98
* javadoc and some clean-up
99
*
100
* Revision 1.3  2006/11/06 16:06:52  jaume
101
* *** empty log message ***
102
*
103
* Revision 1.2  2006/10/30 19:30:35  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.1  2006/10/27 12:41:09  jaume
107
* GUI
108
*
109
*
110
*/
111
package com.iver.cit.gvsig.gui.styling;
112

    
113
import java.awt.Color;
114
import java.awt.Dimension;
115
import java.awt.FlowLayout;
116
import java.awt.event.ActionEvent;
117
import java.awt.event.ActionListener;
118
import java.util.ArrayList;
119

    
120
import javax.swing.JPanel;
121
import javax.swing.JSlider;
122
import javax.swing.event.ChangeEvent;
123
import javax.swing.event.ChangeListener;
124

    
125
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
126
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
127

    
128
import com.iver.andami.PluginServices;
129
import com.iver.andami.messages.NotificationManager;
130
import com.iver.cit.gvsig.fmap.core.FShape;
131
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
132
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
133
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
134
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
135
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
136
/**
137
* <b>SimpleFill</b> allows the user to store and modify the properties that fills a
138
* polygon with a padding and an outline<p>
139
* <p>
140
* This functionality is carried out thanks to a tab (simple fill)which is included
141
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
142
* in AbstractTypeSymbolEditor.<p>
143
* <p>
144
* This tab permits the user to change the color of the padding
145
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
146
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
147
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
148
*
149
*
150
*@see AbstractTypeSymbolEditor
151
*@author jaume dominguez faus - jaume.dominguez@iver.es
152
*/
153
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener {
154
        private static final String NAME = PluginServices.
155
                getText(SimpleFill.class, "simple_fill");
156
        private ColorChooserPanel jccFillColor;
157
        private JIncrementalNumberField txtOutlineWidth;
158
        private ArrayList tabs = new ArrayList();
159
        private JSymbolPreviewButton btnOutline;
160
        private JSlider sldFillTransparency;
161
        private JSlider sldOutlineTransparency;
162
        private int outlineAlpha, fillAlpha;
163

    
164
        public SimpleFill(SymbolEditor owner) {
165
                super(owner);
166
                initialize();
167
        }
168

    
169
        public String getName() {
170
                return NAME;
171
        }
172

    
173
        public JPanel[] getTabs() {
174
                return (JPanel[]) tabs.toArray(new JPanel[0]);
175
        }
176

    
177
        /**
178
         * Initializes the parameters that allows the user to fill the padding of
179
         * a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
180
         * SymbolEditor panel with default values for the different attributes.
181
         */
182
        private void initialize() {
183
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
184
                myTab.setName(PluginServices.getText(this, "simple_fill"));
185
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
186

    
187
                jccFillColor = new ColorChooserPanel();
188
                jccFillColor.setAlpha(255);
189
                sldFillTransparency = new JSlider();
190
                sldFillTransparency.setValue(100);
191
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
192
                aux.addComponent(PluginServices.getText(this, "fill_opacity"), sldFillTransparency);
193

    
194
                JPanel aux2 = new JPanel();
195
                btnOutline = new JSymbolPreviewButton(FShape.LINE);
196
                btnOutline.setPreferredSize(new Dimension(100, 35));
197
                aux2.add(btnOutline);
198
                sldOutlineTransparency = new JSlider();
199
                sldOutlineTransparency.setValue(100);
200
                aux.addComponent(PluginServices.getText(this, "outline")+":",
201
                                aux2);
202
                aux.addComponent(PluginServices.getText(this, "outline_opacity"), sldOutlineTransparency);
203
                txtOutlineWidth = new JIncrementalNumberField("", 25, 0, Double.MAX_VALUE, 1);
204
                aux.addComponent(PluginServices.getText(this, "outline_width"), txtOutlineWidth);
205
                myTab.add(aux);
206

    
207
                jccFillColor.addActionListener(this);
208
                sldFillTransparency.addChangeListener(this);
209
                btnOutline.addActionListener(this);
210
                txtOutlineWidth.addActionListener(this);
211
                sldOutlineTransparency.addChangeListener(this);
212
                tabs.add(myTab);
213
        }
214

    
215
        public ISymbol getLayer() {
216
                SimpleFillSymbol layer = new SimpleFillSymbol();
217
                ILineSymbol outline =(ILineSymbol) btnOutline.getSymbol();
218

    
219
                if (outline!=null) {
220
                        outline.setLineWidth(txtOutlineWidth.getDouble());
221
                        outline.setAlpha(outlineAlpha);
222
                        layer.setOutline(outline);
223
                }
224

    
225
                Color c = jccFillColor.getColor();
226
                c = new Color(c.getRed(), c.getGreen(), c.getBlue(), fillAlpha);
227
                layer.setFillColor(c);
228
                return layer;
229
        }
230

    
231
        public void refreshControls(ISymbol layer) {
232
                SimpleFillSymbol sym;
233
                try {
234
                        if (layer == null) {
235
                                // initialize defaults
236
                                NotificationManager.addWarning(getClass().getName()+":: should be unreachable code", new Exception());
237
                        } else {
238
                                sym = (SimpleFillSymbol) layer;
239
                                jccFillColor.setColor(sym.getFillColor());
240
                                int value = 100;
241
                                Color c = sym.getFillColor();
242
                                if (c!=null) {
243
                                        value = (c.getAlpha()/255)*100;
244
                                }
245
                                sldFillTransparency.setValue(value);
246
                                btnOutline.setSymbol(sym.getOutline());
247
                                ILineSymbol outline = sym.getOutline();
248
                                if (outline != null) {
249
                                        outlineAlpha = outline.getAlpha();
250
                                        sldOutlineTransparency.setValue((outlineAlpha/255)*100);
251
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
252
                                } else {
253
                                        sldOutlineTransparency.setValue(100);
254
                                }
255

    
256

    
257

    
258
                        }
259
                } catch (IndexOutOfBoundsException ioEx) {
260
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
261
                } catch (ClassCastException ccEx) {
262
                        NotificationManager.addWarning("Illegal casting from " +
263
                                        layer.getClassName() + " to " + getSymbolClass().
264
                                        getName() + ".", ccEx);
265

    
266
                }
267
        }
268

    
269
        public Class getSymbolClass() {
270
                return SimpleFillSymbol.class;
271
        }
272

    
273
        public void actionPerformed(ActionEvent e) {
274
                fireSymbolChangedEvent();
275
        }
276

    
277
        public void stateChanged(ChangeEvent e) {
278
                Object s = e.getSource();
279
                if (s.equals(sldFillTransparency)) {
280
                        fillAlpha = (int) (255*(sldFillTransparency.getValue()/100.0));
281
                } else if (s.equals(sldOutlineTransparency)) {
282
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
283
                }
284
                fireSymbolChangedEvent();
285
        }
286

    
287
        public EditorTool getEditorTool() {
288
                return null;
289
        }
290
}