root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleFill.java @ 24962
History | View | Annotate | Download (9.51 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 24962 2008-11-11 17:55:35Z vcaballero $
|
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 com.iver.cit.gvsig.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.fmap.geom.Geometry; |
139 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
140 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
141 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleFillSymbol; |
142 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
143 |
import org.gvsig.gui.beans.swing.JBlank; |
144 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
145 |
|
146 |
import com.iver.andami.PluginServices; |
147 |
import com.iver.andami.messages.NotificationManager; |
148 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
149 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton; |
150 |
/**
|
151 |
* <b>SimpleFill</b> allows to store and modify the properties that fills a
|
152 |
* polygon with a padding and an outline<p>
|
153 |
* <p>
|
154 |
* This functionality is carried out thanks to a tab (simple fill)which is included
|
155 |
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
|
156 |
* in AbstractTypeSymbolEditor.<p>
|
157 |
* <p>
|
158 |
* This tab permits the user to change the color of the padding
|
159 |
* (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
|
160 |
* options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
|
161 |
* for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
|
162 |
*
|
163 |
*
|
164 |
*@see AbstractTypeSymbolEditor
|
165 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
166 |
*/
|
167 |
public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener { |
168 |
private ColorChooserPanel jccFillColor;
|
169 |
private JIncrementalNumberField txtOutlineWidth;
|
170 |
private ArrayList tabs = new ArrayList(); |
171 |
private JSymbolPreviewButton btnOutline;
|
172 |
private JSlider sldOutlineTransparency; |
173 |
private int outlineAlpha; |
174 |
private ILineSymbol outline;
|
175 |
private JCheckBox useBorder; |
176 |
|
177 |
public SimpleFill(SymbolEditor owner) {
|
178 |
super(owner);
|
179 |
initialize(); |
180 |
} |
181 |
|
182 |
public String getName() { |
183 |
return PluginServices.getText(SimpleFill.class, "simple_fill_symbol"); |
184 |
} |
185 |
|
186 |
public JPanel[] getTabs() { |
187 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Initializes the parameters that allows the user to fill the padding of
|
192 |
* a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
|
193 |
* SymbolEditor panel with default values for the different attributes.
|
194 |
*/
|
195 |
private void initialize() { |
196 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
197 |
myTab.setName(PluginServices.getText(this, "simple_fill")); |
198 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
199 |
|
200 |
jccFillColor = new ColorChooserPanel(true,true); |
201 |
jccFillColor.setAlpha(255);
|
202 |
aux.addComponent(PluginServices.getText(this, "fill_color"), jccFillColor); |
203 |
|
204 |
JPanel aux2 = new JPanel(); |
205 |
btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
|
206 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
207 |
aux2.add(btnOutline); |
208 |
|
209 |
aux.addComponent(new JBlank(10, 10)); |
210 |
useBorder = new JCheckBox(PluginServices.getText(this, "use_outline")); |
211 |
aux.addComponent(useBorder, aux2); |
212 |
aux.addComponent(new JBlank(10, 10)); |
213 |
|
214 |
sldOutlineTransparency = new JSlider(); |
215 |
sldOutlineTransparency.setValue(100);
|
216 |
aux.addComponent(PluginServices.getText(this, "outline")+":", |
217 |
aux2); |
218 |
aux.addComponent(PluginServices.getText(this, "outline_opacity"), sldOutlineTransparency); |
219 |
txtOutlineWidth = new JIncrementalNumberField("", 25, 0, Double.MAX_VALUE, 1); |
220 |
aux.addComponent(PluginServices.getText(this, "outline_width"), txtOutlineWidth); |
221 |
myTab.add(aux); |
222 |
|
223 |
useBorder.addActionListener(this);
|
224 |
jccFillColor.addActionListener(this);
|
225 |
btnOutline.addActionListener(this);
|
226 |
txtOutlineWidth.addActionListener(this);
|
227 |
sldOutlineTransparency.addChangeListener(this);
|
228 |
tabs.add(myTab); |
229 |
} |
230 |
|
231 |
public ISymbol getLayer() {
|
232 |
SimpleFillSymbol layer = new SimpleFillSymbol();
|
233 |
|
234 |
layer.setHasOutline(useBorder.isSelected()); |
235 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
236 |
|
237 |
if (outline!=null) { |
238 |
outline.setLineWidth(txtOutlineWidth.getDouble()); |
239 |
outline.setAlpha(outlineAlpha); |
240 |
} |
241 |
|
242 |
layer.setOutline(outline); |
243 |
|
244 |
layer.setHasFill(jccFillColor.getUseColorisSelected()); |
245 |
Color c = jccFillColor.getColor();
|
246 |
if (c != null) |
247 |
c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); |
248 |
layer.setFillColor(c); |
249 |
|
250 |
return layer;
|
251 |
} |
252 |
|
253 |
public void refreshControls(ISymbol layer) { |
254 |
SimpleFillSymbol sym; |
255 |
try {
|
256 |
if (layer == null) { |
257 |
// initialize defaults
|
258 |
NotificationManager.addWarning(getClass().getName()+":: should be unreachable code", new Exception()); |
259 |
} else {
|
260 |
|
261 |
|
262 |
//fill
|
263 |
|
264 |
sym = (SimpleFillSymbol) layer; |
265 |
jccFillColor.setUseColorIsSelected(sym.hasFill()); |
266 |
jccFillColor.setColor(sym.getFillColor()); |
267 |
//outline
|
268 |
|
269 |
sldOutlineTransparency.removeChangeListener(this);
|
270 |
|
271 |
outline=sym.getOutline(); |
272 |
btnOutline.setSymbol(outline); |
273 |
useBorder.setSelected(sym.hasOutline()); |
274 |
|
275 |
if (outline != null) { |
276 |
outlineAlpha = outline.getAlpha(); |
277 |
sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100)); |
278 |
txtOutlineWidth.setDouble(outline.getLineWidth()); |
279 |
} else {
|
280 |
sldOutlineTransparency.setValue(100);
|
281 |
} |
282 |
|
283 |
sldOutlineTransparency.addChangeListener(this);
|
284 |
|
285 |
} |
286 |
} catch (IndexOutOfBoundsException ioEx) { |
287 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
288 |
} catch (ClassCastException ccEx) { |
289 |
NotificationManager.addWarning("Illegal casting from " +
|
290 |
layer.getClassName() + " to " + getSymbolClass().
|
291 |
getName() + ".", ccEx);
|
292 |
|
293 |
} |
294 |
} |
295 |
|
296 |
public Class getSymbolClass() { |
297 |
return SimpleFillSymbol.class;
|
298 |
} |
299 |
|
300 |
public void actionPerformed(ActionEvent e) { |
301 |
Object s = e.getSource();
|
302 |
|
303 |
if (s.equals(btnOutline)) {
|
304 |
ISymbol sym = btnOutline.getSymbol(); |
305 |
if (sym instanceof ILineSymbol) { |
306 |
ILineSymbol outline = (ILineSymbol) sym; |
307 |
if (outline != null) |
308 |
txtOutlineWidth.setDouble(outline.getLineWidth()); |
309 |
} |
310 |
|
311 |
} |
312 |
|
313 |
|
314 |
fireSymbolChangedEvent(); |
315 |
} |
316 |
|
317 |
public void stateChanged(ChangeEvent e) { |
318 |
Object s = e.getSource();
|
319 |
|
320 |
|
321 |
if (s.equals(sldOutlineTransparency)) {
|
322 |
outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0)); |
323 |
} |
324 |
|
325 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
326 |
|
327 |
fireSymbolChangedEvent(); |
328 |
} |
329 |
|
330 |
public EditorTool[] getEditorTools() { |
331 |
return null; |
332 |
} |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
} |