Statistics
| Revision:

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

History | View | Annotate | Download (6.97 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 10986 2007-03-30 09:39:45Z jaume $
45
* $Log$
46
* Revision 1.4  2007-03-30 09:39:45  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.3  2007/03/28 16:44:08  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2  2007/03/09 11:25:00  jaume
53
* Advanced symbology (start committing)
54
*
55
* Revision 1.1.2.4  2007/02/21 16:09:35  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1.2.3  2007/02/21 07:35:14  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
62
* some bug fixes in the editor and removed unnecessary imports
63
*
64
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1  2007/01/16 11:52:11  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.4  2006/11/13 09:15:23  jaume
71
* javadoc and some clean-up
72
*
73
* Revision 1.3  2006/11/06 16:06:52  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.2  2006/10/30 19:30:35  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1  2006/10/27 12:41:09  jaume
80
* GUI
81
*
82
*
83
*/
84
package com.iver.cit.gvsig.gui.styling;
85

    
86
import java.awt.Color;
87
import java.awt.Dimension;
88
import java.awt.FlowLayout;
89
import java.awt.event.ActionEvent;
90
import java.awt.event.ActionListener;
91
import java.util.ArrayList;
92

    
93
import javax.swing.JPanel;
94
import javax.swing.JSlider;
95
import javax.swing.event.ChangeEvent;
96
import javax.swing.event.ChangeListener;
97

    
98
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
99
import org.gvsig.gui.beans.swing.JBlank;
100

    
101
import com.iver.andami.PluginServices;
102
import com.iver.andami.messages.NotificationManager;
103
import com.iver.cit.gvsig.fmap.core.FShape;
104
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
105
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
106
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
107
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
108
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
109
import com.lowagie.tools.plugins.treeview.OutlinelistTreeNode;
110

    
111
import de.ios.framework.swing.JDecimalField;
112

    
113
public class SimpleFill extends AbstractTypeSymbolEditorPanel implements ActionListener, ChangeListener {
114
        private static final String NAME = PluginServices.
115
                getText(SimpleFill.class, "simple_fill");
116
        private ColorChooserPanel jccFillColor;
117
        private JDecimalField txtOutlineWidth;
118
        private ArrayList tabs = new ArrayList();
119
        private JSymbolPreviewButton btnOutline;
120
        private JSlider sldFillTransparency;
121
        private JSlider sldOutlineTransparency;
122
        private int outlineAlpha, fillAlpha;
123

    
124
        public SimpleFill(SymbolEditor owner) {
125
                super(owner);
126
                initialize();
127
        }
128

    
129
        public String getName() {
130
                return NAME;
131
        }
132

    
133
        public JPanel[] getTabs() {
134
                return (JPanel[]) tabs.toArray(new JPanel[0]);
135
        }
136

    
137
        private void initialize() {
138
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
139
                myTab.setName(PluginServices.getText(this, "simple_fill"));
140
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
141

    
142
                jccFillColor = new ColorChooserPanel();
143
                jccFillColor.setAlpha(255);
144
                sldFillTransparency = new JSlider();
145
                sldFillTransparency.setValue(100);
146
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
147
                aux.addComponent(PluginServices.getText(this, "fill_opacity"), sldFillTransparency);
148
                aux.addComponent(new JBlank(30, 30));
149

    
150
                btnOutline = new JSymbolPreviewButton(FShape.LINE);
151
                btnOutline.setPreferredSize(new Dimension(100, 35));
152
                sldOutlineTransparency = new JSlider();
153
                sldOutlineTransparency.setValue(100);
154
                aux.addComponent(PluginServices.getText(this, "outline")+":",
155
                                btnOutline        );
156
                aux.addComponent(PluginServices.getText(this, "transparency_opacity"), sldOutlineTransparency);
157
                txtOutlineWidth = new JDecimalField(25);
158
                // TODO restore previous outline width
159
                aux.addComponent(PluginServices.getText(this, "outline_width")+":",
160
                        txtOutlineWidth );
161
                aux.setPreferredSize(new Dimension(300, 300));
162
                myTab.add(aux);
163

    
164
                jccFillColor.addActionListener(this);
165
                sldFillTransparency.addChangeListener(this);
166
                btnOutline.addActionListener(this);
167
                txtOutlineWidth.addActionListener(this);
168
                sldOutlineTransparency.addChangeListener(this);
169
                tabs.add(myTab);
170
        }
171

    
172
        public ISymbol getLayer() {
173
                SimpleFillSymbol sfs = new SimpleFillSymbol();
174
                ILineSymbol outline =(ILineSymbol) btnOutline.getSymbol();
175

    
176
                if (outline!=null) {
177
                        outline.setAlpha(outlineAlpha);
178
                        sfs.setOutline(outline);
179
                }
180

    
181
                Color c = jccFillColor.getColor();
182
                c = new Color(c.getRed(), c.getGreen(), c.getBlue(), fillAlpha);
183
                sfs.setFillColor(c);
184
                return sfs;
185
        }
186

    
187
        public void refreshControls(ISymbol layer) {
188
                SimpleFillSymbol sym;
189
                try {
190
                        if (layer == null) {
191
                                // initialize defaults
192
                        } else {
193
                                sym = (SimpleFillSymbol) layer;
194
                                jccFillColor.setColor(sym.getFillColor());
195
                                int value = 100;
196
                                Color c = sym.getFillColor();
197
                                if (c!=null) {
198
                                        value = (c.getAlpha()/255)*100;
199
                                }
200
                                sldFillTransparency.setValue(value);
201
                                btnOutline.setSymbol(sym.getOutline());
202
                                ILineSymbol outline = sym.getOutline();
203
                                if (outline != null) {
204
                                        outlineAlpha = outline.getAlpha();
205
                                        sldOutlineTransparency.setValue((outlineAlpha/255)*100);
206
                                } else {
207
                                        sldOutlineTransparency.setValue(100);
208
                                }
209
                        }
210
                } catch (IndexOutOfBoundsException ioEx) {
211
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
212
                } catch (ClassCastException ccEx) {
213
                        NotificationManager.addWarning("Illegal casting from " +
214
                                        layer.getClassName() + " to " + getSymbolClass().
215
                                        getName() + ".", ccEx);
216

    
217
                }
218
        }
219

    
220
        public Class getSymbolClass() {
221
                return SimpleFillSymbol.class;
222
        }
223

    
224
        public void actionPerformed(ActionEvent e) {
225
                fireSymbolChangedEvent();
226
        }
227

    
228
        public void stateChanged(ChangeEvent e) {
229
                Object s = e.getSource();
230
                if (s.equals(sldFillTransparency)) {
231
                        fillAlpha = (int) (255*(sldFillTransparency.getValue()/100.0));
232
                } else if (s.equals(sldOutlineTransparency)) {
233
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
234
                }
235
                fireSymbolChangedEvent();
236
        }
237
}