Statistics
| Revision:

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

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

    
92
import java.awt.Color;
93
import java.awt.Dimension;
94
import java.awt.FlowLayout;
95
import java.awt.event.ActionEvent;
96
import java.awt.event.ActionListener;
97
import java.util.ArrayList;
98

    
99
import javax.swing.JPanel;
100
import javax.swing.JSlider;
101
import javax.swing.event.ChangeEvent;
102
import javax.swing.event.ChangeListener;
103

    
104
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
105
import org.gvsig.gui.beans.swing.JBlank;
106

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

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

    
134
        public SimpleFill(SymbolEditor owner) {
135
                super(owner);
136
                initialize();
137
        }
138

    
139
        public String getName() {
140
                return NAME;
141
        }
142

    
143
        public JPanel[] getTabs() {
144
                return (JPanel[]) tabs.toArray(new JPanel[0]);
145
        }
146

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

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

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

    
174
                jccFillColor.addActionListener(this);
175
                sldFillTransparency.addChangeListener(this);
176
                btnOutline.addActionListener(this);
177
                txtOutlineWidth.addActionListener(this);
178
                sldOutlineTransparency.addChangeListener(this);
179
                tabs.add(myTab);
180
        }
181

    
182
        public ISymbol getLayer() {
183
                SimpleFillSymbol sfs = new SimpleFillSymbol();
184
                ILineSymbol outline =(ILineSymbol) btnOutline.getSymbol();
185

    
186
                if (outline!=null) {
187
                        outline.setAlpha(outlineAlpha);
188
                        sfs.setOutline(outline);
189
                }
190

    
191
                Color c = jccFillColor.getColor();
192
                c = new Color(c.getRed(), c.getGreen(), c.getBlue(), fillAlpha);
193
                sfs.setFillColor(c);
194
                return sfs;
195
        }
196

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

    
227
                }
228
        }
229

    
230
        public Class getSymbolClass() {
231
                return SimpleFillSymbol.class;
232
        }
233

    
234
        public void actionPerformed(ActionEvent e) {
235
                fireSymbolChangedEvent();
236
        }
237

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

    
248
        public EditorTool getEditorTool() {
249
                return null;
250
        }
251
}