Statistics
| Revision:

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

History | View | Annotate | Download (9.87 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 13826 2007-09-19 10:45:05Z jvidal $
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.gui.beans.swing.GridBagLayoutPanel;
139
import org.gvsig.gui.beans.swing.JBlank;
140
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
141

    
142
import com.iver.andami.PluginServices;
143
import com.iver.andami.messages.NotificationManager;
144
import com.iver.cit.gvsig.fmap.core.FShape;
145
import com.iver.cit.gvsig.fmap.core.styles.ArrowDecoratorStyle;
146
import com.iver.cit.gvsig.fmap.core.symbols.ArrowMarkerSymbol;
147
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
148
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
149
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
150
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
151
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
152
/**
153
* <b>SimpleFill</b> allows to store and modify the properties that fills a
154
* polygon with a padding and an outline<p>
155
* <p>
156
* This functionality is carried out thanks to a tab (simple fill)which is included
157
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
158
* in AbstractTypeSymbolEditor.<p>
159
* <p>
160
* This tab permits the user to change the color of the padding
161
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
162
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
163
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
164
*
165
*
166
*@see AbstractTypeSymbolEditor
167
*@author jaume dominguez faus - jaume.dominguez@iver.es
168
*/
169
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener {
170
        private ColorChooserPanel jccFillColor;
171
        private JIncrementalNumberField txtOutlineWidth;
172
        private ArrayList tabs = new ArrayList();
173
        private JSymbolPreviewButton btnOutline;
174
        private JSlider sldFillTransparency;
175
        private JSlider sldOutlineTransparency;
176
        private int outlineAlpha, fillAlpha;
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();
204
                jccFillColor.setAlpha(255);
205
                sldFillTransparency = new JSlider();
206
                sldFillTransparency.setValue(100);
207
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
208
                aux.addComponent(PluginServices.getText(this, "fill_opacity"), sldFillTransparency);
209

    
210
                JPanel aux2 = new JPanel();
211
                btnOutline = new JSymbolPreviewButton(FShape.LINE);
212
                btnOutline.setPreferredSize(new Dimension(100, 35));
213
                aux2.add(btnOutline);
214

    
215
                aux.addComponent(new JBlank(10, 10));
216
                useBorder = new JCheckBox(PluginServices.getText(this, "use_outline"));
217
                aux.addComponent(useBorder, aux2);
218
                aux.addComponent(new JBlank(10, 10));
219

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

    
229
                useBorder.addActionListener(this);
230
                jccFillColor.addActionListener(this);
231
                sldFillTransparency.addChangeListener(this);
232
                btnOutline.addActionListener(this);
233
                txtOutlineWidth.addActionListener(this);
234
                sldOutlineTransparency.addChangeListener(this);
235
                tabs.add(myTab);
236
        }
237

    
238
        public ISymbol getLayer() {
239
                SimpleFillSymbol layer = new SimpleFillSymbol();
240
                outline = useBorder.isSelected() ? (ILineSymbol) btnOutline.getSymbol() : null;
241

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

    
247
                layer.setOutline(outline);
248
                Color c = jccFillColor.getColor();
249
                c = new Color(c.getRed(), c.getGreen(), c.getBlue(), fillAlpha);
250
                layer.setFillColor(c);
251
                return layer;
252
        }
253

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

    
262

    
263
                                //fill
264
                                sldFillTransparency.removeChangeListener(this);
265
                                sym = (SimpleFillSymbol) layer;
266
                                jccFillColor.setColor(sym.getFillColor());
267
                                int value = 100;
268
                                Color c = sym.getFillColor();
269
                                if (c!=null) {
270
                                        value = (int) ((c.getAlpha()/255D)*100);
271
                                }
272
                                sldFillTransparency.setValue(value);
273
                                sldFillTransparency.addChangeListener(this);
274

    
275

    
276
                                //outline
277

    
278
                                sldOutlineTransparency.removeChangeListener(this);
279

    
280
                                useBorder.setSelected(outline!=null);
281

    
282
                                outline=sym.getOutline();
283
                                btnOutline.setSymbol(outline);
284

    
285
                                if (outline != null) {
286
                                        outlineAlpha = outline.getAlpha();
287
                                        sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100));
288
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
289
                                } else {
290
                                        sldOutlineTransparency.setValue(100);
291
                                }
292

    
293
                                sldOutlineTransparency.addChangeListener(this);
294

    
295

    
296

    
297
                        }
298
                } catch (IndexOutOfBoundsException ioEx) {
299
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
300
                } catch (ClassCastException ccEx) {
301
                        NotificationManager.addWarning("Illegal casting from " +
302
                                        layer.getClassName() + " to " + getSymbolClass().
303
                                        getName() + ".", ccEx);
304

    
305
                }
306
        }
307

    
308
        public Class getSymbolClass() {
309
                return SimpleFillSymbol.class;
310
        }
311

    
312
        public void actionPerformed(ActionEvent e) {
313
                outline = (ILineSymbol) btnOutline.getSymbol();
314
                fireSymbolChangedEvent();
315
        }
316

    
317
        public void stateChanged(ChangeEvent e) {
318
                Object s = e.getSource();
319
                if (s.equals(sldFillTransparency)) {
320
                        fillAlpha = (int) (255*(sldFillTransparency.getValue()/100.0));
321
                } else if (s.equals(sldOutlineTransparency)) {
322
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
323
                }
324

    
325
                outline = (ILineSymbol) btnOutline.getSymbol();
326

    
327
                fireSymbolChangedEvent();
328
        }
329

    
330
        public EditorTool[] getEditorTools() {
331
                return null;
332
        }
333

    
334

    
335

    
336

    
337
}