Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleFill.java @ 11055

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

    
89
import java.awt.Color;
90
import java.awt.Dimension;
91
import java.awt.FlowLayout;
92
import java.awt.event.ActionEvent;
93
import java.awt.event.ActionListener;
94
import java.util.ArrayList;
95

    
96
import javax.swing.JPanel;
97
import javax.swing.JSlider;
98
import javax.swing.event.ChangeEvent;
99
import javax.swing.event.ChangeListener;
100

    
101
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
102
import org.gvsig.gui.beans.swing.JBlank;
103

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

    
114
import de.ios.framework.swing.JDecimalField;
115
/**
116
*
117
* @author jaume dominguez faus - jaume.dominguez@iver.es
118
*
119
*/
120
public class SimpleFill extends AbstractTypeSymbolEditorPanel implements ActionListener, ChangeListener {
121
        private static final String NAME = PluginServices.
122
                getText(SimpleFill.class, "simple_fill");
123
        private ColorChooserPanel jccFillColor;
124
        private JDecimalField txtOutlineWidth;
125
        private ArrayList tabs = new ArrayList();
126
        private JSymbolPreviewButton btnOutline;
127
        private JSlider sldFillTransparency;
128
        private JSlider sldOutlineTransparency;
129
        private int outlineAlpha, fillAlpha;
130

    
131
        public SimpleFill(SymbolEditor owner) {
132
                super(owner);
133
                initialize();
134
        }
135

    
136
        public String getName() {
137
                return NAME;
138
        }
139

    
140
        public JPanel[] getTabs() {
141
                return (JPanel[]) tabs.toArray(new JPanel[0]);
142
        }
143

    
144
        private void initialize() {
145
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
146
                myTab.setName(PluginServices.getText(this, "simple_fill"));
147
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
148

    
149
                jccFillColor = new ColorChooserPanel();
150
                jccFillColor.setAlpha(255);
151
                sldFillTransparency = new JSlider();
152
                sldFillTransparency.setValue(100);
153
                aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor);
154
                aux.addComponent(PluginServices.getText(this, "fill_opacity"), sldFillTransparency);
155
                aux.addComponent(new JBlank(30, 30));
156

    
157
                btnOutline = new JSymbolPreviewButton(FShape.LINE);
158
                btnOutline.setPreferredSize(new Dimension(100, 35));
159
                sldOutlineTransparency = new JSlider();
160
                sldOutlineTransparency.setValue(100);
161
                aux.addComponent(PluginServices.getText(this, "outline")+":",
162
                                btnOutline        );
163
                aux.addComponent(PluginServices.getText(this, "transparency_opacity"), sldOutlineTransparency);
164
                txtOutlineWidth = new JDecimalField(25);
165
                // TODO restore previous outline width
166
                aux.addComponent(PluginServices.getText(this, "outline_width")+":",
167
                        txtOutlineWidth );
168
                aux.setPreferredSize(new Dimension(300, 300));
169
                myTab.add(aux);
170

    
171
                jccFillColor.addActionListener(this);
172
                sldFillTransparency.addChangeListener(this);
173
                btnOutline.addActionListener(this);
174
                txtOutlineWidth.addActionListener(this);
175
                sldOutlineTransparency.addChangeListener(this);
176
                tabs.add(myTab);
177
        }
178

    
179
        public ISymbol getLayer() {
180
                SimpleFillSymbol sfs = new SimpleFillSymbol();
181
                ILineSymbol outline =(ILineSymbol) btnOutline.getSymbol();
182

    
183
                if (outline!=null) {
184
                        outline.setAlpha(outlineAlpha);
185
                        sfs.setOutline(outline);
186
                }
187

    
188
                Color c = jccFillColor.getColor();
189
                c = new Color(c.getRed(), c.getGreen(), c.getBlue(), fillAlpha);
190
                sfs.setFillColor(c);
191
                return sfs;
192
        }
193

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

    
224
                }
225
        }
226

    
227
        public Class getSymbolClass() {
228
                return SimpleFillSymbol.class;
229
        }
230

    
231
        public void actionPerformed(ActionEvent e) {
232
                fireSymbolChangedEvent();
233
        }
234

    
235
        public void stateChanged(ChangeEvent e) {
236
                Object s = e.getSource();
237
                if (s.equals(sldFillTransparency)) {
238
                        fillAlpha = (int) (255*(sldFillTransparency.getValue()/100.0));
239
                } else if (s.equals(sldOutlineTransparency)) {
240
                        outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0));
241
                }
242
                fireSymbolChangedEvent();
243
        }
244
}