Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SimpleFill.java @ 34291

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 30289 2009-07-31 11:10:41Z jpiera $
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 org.gvsig.app.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.andami.messages.NotificationManager;
139
import org.gvsig.app.gui.panels.ColorChooserPanel;
140
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
141
import org.gvsig.fmap.geom.Geometry;
142
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
143
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
144
import org.gvsig.gui.beans.swing.JBlank;
145
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
146
import org.gvsig.i18n.Messages;
147
//import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
148
import org.gvsig.symbology.SymbologyLocator;
149
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
150
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol;
151
//import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
152
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
153
import org.slf4j.Logger;
154
import org.slf4j.LoggerFactory;
155

    
156
/**
157
* <b>SimpleFill</b> allows to store and modify the properties that fills a
158
* polygon with a padding and an outline<p>
159
* <p>
160
* This functionality is carried out thanks to a tab (simple fill)which is included
161
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
162
* in AbstractTypeSymbolEditor.<p>
163
* <p>
164
* This tab permits the user to change the color of the padding
165
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
166
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
167
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
168
*
169
*
170
*@see AbstractTypeSymbolEditor
171
*@author jaume dominguez faus - jaume.dominguez@iver.es
172
*/
173
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener {
174

    
175
        private static final Logger LOG = LoggerFactory.getLogger(SimpleFill.class);
176

    
177
        private ColorChooserPanel jccFillColor;
178
        private JIncrementalNumberField txtOutlineWidth;
179
        private ArrayList tabs = new ArrayList();
180
        private JSymbolPreviewButton btnOutline;
181
        private JSlider sldOutlineTransparency;
182
        private int outlineAlpha;
183
        private ILineSymbol outline;
184
        private JCheckBox useBorder;
185

    
186
        public SimpleFill(SymbolEditor owner) {
187
                super(owner);
188
                initialize();
189
        }
190

    
191
        public String getName() {
192
                return Messages.getText("simple_fill_symbol");
193
        }
194

    
195
        public JPanel[] getTabs() {
196
                return (JPanel[]) tabs.toArray(new JPanel[0]);
197
        }
198

    
199
        /**
200
         * Initializes the parameters that allows the user to fill the padding of
201
         * a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
202
         * SymbolEditor panel with default values for the different attributes.
203
         */
204
        private void initialize() {
205
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
206
                myTab.setName(Messages.getText("simple_fill"));
207
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
208

    
209
                jccFillColor = new ColorChooserPanel(true,true);
210
                jccFillColor.setAlpha(255);
211
                aux.addComponent(Messages.getText("fill_color"), jccFillColor);
212

    
213
                JPanel aux2 = new JPanel();
214
                btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
215
                btnOutline.setPreferredSize(new Dimension(100, 35));
216
                aux2.add(btnOutline);
217

    
218
                aux.addComponent(new JBlank(10, 10));
219
                useBorder = new JCheckBox(Messages.getText("use_outline"));
220
                aux.addComponent(useBorder, aux2);
221
                aux.addComponent(new JBlank(10, 10));
222

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

    
232
                useBorder.addActionListener(this);
233
                jccFillColor.addActionListener(this);
234
                btnOutline.addActionListener(this);
235
                txtOutlineWidth.addActionListener(this);
236
                sldOutlineTransparency.addChangeListener(this);
237
                tabs.add(myTab);
238
        }
239

    
240
        public ISymbol getLayer() {
241
                IFillSymbol layer = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
242

    
243
                layer.setHasOutline(useBorder.isSelected());
244
                outline = (ILineSymbol) btnOutline.getSymbol();
245

    
246
                if (outline!=null) {
247
                        outline.setLineWidth(txtOutlineWidth.getDouble());
248
                        outline.setAlpha(outlineAlpha);
249
                }
250

    
251
                layer.setOutline(outline);
252

    
253
                layer.setHasFill(jccFillColor.getUseColorisSelected());
254
                Color c = jccFillColor.getColor();
255
                if (c != null)
256
                        c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
257
                layer.setFillColor(c);
258

    
259
                return layer;
260
        }
261

    
262
        public void refreshControls(ISymbol layer) {
263
                IFillSymbol sym;
264
                try {
265
                        if (layer == null) {
266
                                // initialize defaults
267
                                LOG.warn(getClass().getName()+":: should be unreachable code", new Exception());
268
                        } else {
269

    
270

    
271
                                //fill
272

    
273
                                sym = (IFillSymbol) layer;
274
                                jccFillColor.setUseColorIsSelected(sym.hasFill());
275
                                jccFillColor.setColor(sym.getFillColor());
276
                                //outline
277

    
278
                                sldOutlineTransparency.removeChangeListener(this);
279

    
280
                                outline=sym.getOutline();
281
                                btnOutline.setSymbol(outline);
282
                                useBorder.setSelected(sym.hasOutline());
283

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

    
292
                                sldOutlineTransparency.addChangeListener(this);
293

    
294
                        }
295
                } catch (IndexOutOfBoundsException ioEx) {
296
                        LOG.warn("Symbol layer index out of bounds", ioEx);
297
                } catch (ClassCastException ccEx) {
298
                        LOG.warn("Illegal casting from " +
299
                                        layer.getClass().getName() + " to IFillSymbol.", ccEx);
300

    
301
                }
302
        }
303

    
304
        public boolean canManageSymbol(ISymbol symbol){
305
                return symbol instanceof ISimpleFillSymbol;
306
        }
307
        
308
        public void actionPerformed(ActionEvent e) {
309
                Object s = e.getSource();
310

    
311
                if (s.equals(btnOutline)) {
312
                        ISymbol sym = btnOutline.getSymbol();
313
                        if (sym instanceof ILineSymbol) {
314
                                ILineSymbol outline = (ILineSymbol) sym;
315
                                if (outline != null)
316
                                        txtOutlineWidth.setDouble(outline.getLineWidth());
317
                        }
318

    
319
                }
320

    
321

    
322
                fireSymbolChangedEvent();
323
        }
324

    
325
        public void stateChanged(ChangeEvent e) {
326
                Object s = e.getSource();
327

    
328

    
329
                if (s.equals(sldOutlineTransparency)) {
330
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
331
                }
332

    
333
                outline = (ILineSymbol) btnOutline.getSymbol();
334

    
335
                fireSymbolChangedEvent();
336
        }
337

    
338
        public EditorTool[] getEditorTools() {
339
                return null;
340
        }
341

    
342

    
343

    
344

    
345
}