root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleFill.java @ 10679
History | View | Annotate | Download (6.76 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 10679 2007-03-09 11:25:01Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-03-09 11:25:00 jaume
|
47 |
* Advanced symbology (start committing)
|
48 |
*
|
49 |
* Revision 1.1.2.4 2007/02/21 16:09:35 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.3 2007/02/21 07:35:14 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
56 |
* some bug fixes in the editor and removed unnecessary imports
|
57 |
*
|
58 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.1 2007/01/16 11:52:11 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.4 2006/11/13 09:15:23 jaume
|
65 |
* javadoc and some clean-up
|
66 |
*
|
67 |
* Revision 1.3 2006/11/06 16:06:52 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.2 2006/10/30 19:30:35 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2006/10/27 12:41:09 jaume
|
74 |
* GUI
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
package com.iver.cit.gvsig.gui.styling; |
79 |
|
80 |
import java.awt.Color; |
81 |
import java.awt.Dimension; |
82 |
import java.awt.FlowLayout; |
83 |
import java.awt.event.ActionEvent; |
84 |
import java.awt.event.ActionListener; |
85 |
import java.util.ArrayList; |
86 |
|
87 |
import javax.swing.JPanel; |
88 |
import javax.swing.JSlider; |
89 |
import javax.swing.event.ChangeEvent; |
90 |
import javax.swing.event.ChangeListener; |
91 |
|
92 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
93 |
import org.gvsig.gui.beans.swing.JBlank; |
94 |
|
95 |
import com.iver.andami.PluginServices; |
96 |
import com.iver.andami.messages.NotificationManager; |
97 |
import com.iver.cit.gvsig.fmap.core.FShape; |
98 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
99 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
100 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
101 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
102 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton; |
103 |
import com.lowagie.tools.plugins.treeview.OutlinelistTreeNode; |
104 |
|
105 |
import de.ios.framework.swing.JDecimalField; |
106 |
|
107 |
public class SimpleFill extends AbstractTypeSymbolEditorPanel implements ActionListener, ChangeListener { |
108 |
private static final String NAME = PluginServices. |
109 |
getText(SimpleFill.class, "simple_fill");
|
110 |
private ColorChooserPanel jccFillColor;
|
111 |
private JDecimalField txtOutlineWidth;
|
112 |
private ArrayList tabs = new ArrayList(); |
113 |
private JSymbolPreviewButton btnOutline;
|
114 |
private JSlider sldFillTransparency; |
115 |
private JSlider sldOutlineTransparency; |
116 |
private int outlineAlpha, fillAlpha; |
117 |
|
118 |
public SimpleFill(SymbolEditor owner) {
|
119 |
super(owner);
|
120 |
initialize(); |
121 |
} |
122 |
|
123 |
public String getName() { |
124 |
return NAME;
|
125 |
} |
126 |
|
127 |
public JPanel[] getTabs() { |
128 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
129 |
} |
130 |
|
131 |
private void initialize() { |
132 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
133 |
myTab.setName(PluginServices.getText(this, "simple_fill")); |
134 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
135 |
|
136 |
jccFillColor = new ColorChooserPanel();
|
137 |
jccFillColor.setAlpha(255);
|
138 |
sldFillTransparency = new JSlider(); |
139 |
sldFillTransparency.setValue(100);
|
140 |
aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor); |
141 |
aux.addComponent(PluginServices.getText(this, "fill_opacity"), sldFillTransparency); |
142 |
aux.addComponent(new JBlank(30, 30)); |
143 |
|
144 |
btnOutline = new JSymbolPreviewButton(FShape.LINE);
|
145 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
146 |
sldOutlineTransparency = new JSlider(); |
147 |
sldOutlineTransparency.setValue(100);
|
148 |
aux.addComponent(PluginServices.getText(this, "outline")+":", |
149 |
btnOutline ); |
150 |
aux.addComponent(PluginServices.getText(this, "transparency_opacity"), sldOutlineTransparency); |
151 |
txtOutlineWidth = new JDecimalField(25); |
152 |
// TODO restore previous outline width
|
153 |
aux.addComponent(PluginServices.getText(this, "outline_width")+":", |
154 |
txtOutlineWidth ); |
155 |
aux.setPreferredSize(new Dimension(300, 300)); |
156 |
myTab.add(aux); |
157 |
|
158 |
jccFillColor.addActionListener(this);
|
159 |
sldFillTransparency.addChangeListener(this);
|
160 |
btnOutline.addActionListener(this);
|
161 |
txtOutlineWidth.addActionListener(this);
|
162 |
sldOutlineTransparency.addChangeListener(this);
|
163 |
tabs.add(myTab); |
164 |
} |
165 |
|
166 |
public ISymbol getLayer() {
|
167 |
SimpleFillSymbol sfs = new SimpleFillSymbol();
|
168 |
ILineSymbol outline =(ILineSymbol) btnOutline.getSymbol(); |
169 |
|
170 |
if (outline!=null) { |
171 |
outline.setAlpha(outlineAlpha); |
172 |
sfs.setOutline(outline); |
173 |
} |
174 |
|
175 |
Color c = jccFillColor.getColor();
|
176 |
c = new Color(c.getRed(), c.getBlue(), c.getGreen(), fillAlpha); |
177 |
sfs.setFillColor(c); |
178 |
return sfs;
|
179 |
} |
180 |
|
181 |
public void refreshControls(ISymbol layer) { |
182 |
SimpleFillSymbol sym; |
183 |
try {
|
184 |
if (layer == null) { |
185 |
// initialize defaults
|
186 |
} else {
|
187 |
sym = (SimpleFillSymbol) layer; |
188 |
jccFillColor.setColor(sym.getFillColor()); |
189 |
sldFillTransparency.setValue((sym.getFillColor().getAlpha()/255)*100); |
190 |
btnOutline.setSymbol(sym.getOutline()); |
191 |
ILineSymbol outline = sym.getOutline(); |
192 |
if (outline != null) { |
193 |
outlineAlpha = outline.getAlpha(); |
194 |
sldOutlineTransparency.setValue((outlineAlpha/255)*100); |
195 |
} else {
|
196 |
sldOutlineTransparency.setValue(100);
|
197 |
} |
198 |
} |
199 |
} catch (IndexOutOfBoundsException ioEx) { |
200 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
201 |
} catch (ClassCastException ccEx) { |
202 |
NotificationManager.addWarning("Illegal casting from " +
|
203 |
layer.getClassName() + " to " + getSymbolClass().
|
204 |
getName() + ".", ccEx);
|
205 |
|
206 |
} |
207 |
} |
208 |
|
209 |
public Class getSymbolClass() { |
210 |
return SimpleFillSymbol.class;
|
211 |
} |
212 |
|
213 |
public void actionPerformed(ActionEvent e) { |
214 |
fireSymbolChangedEvent(); |
215 |
} |
216 |
|
217 |
public void stateChanged(ChangeEvent e) { |
218 |
Object s = e.getSource();
|
219 |
if (s.equals(sldFillTransparency)) {
|
220 |
fillAlpha = (int) (255*(sldFillTransparency.getValue()/100.0)); |
221 |
} else if (s.equals(sldOutlineTransparency)) { |
222 |
outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0)); |
223 |
} |
224 |
fireSymbolChangedEvent(); |
225 |
} |
226 |
} |