svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SimpleFill.java @ 43303
History | View | Annotate | Download (9.6 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: SimpleFill.java 30289 2009-07-31 11:10:41Z jpiera $
|
||
27 | * $Log$
|
||
28 | * Revision 1.17 2007-09-19 10:45:05 jvidal
|
||
29 | * bug solved
|
||
30 | *
|
||
31 | * Revision 1.16 2007/08/16 06:54:35 jvidal
|
||
32 | * javadoc updated
|
||
33 | *
|
||
34 | * Revision 1.15 2007/08/10 07:28:25 jaume
|
||
35 | * translations
|
||
36 | *
|
||
37 | * Revision 1.14 2007/08/08 11:49:15 jaume
|
||
38 | * refactored to avoid provide more than one EditorTool
|
||
39 | *
|
||
40 | * Revision 1.13 2007/08/08 10:16:53 jvidal
|
||
41 | * javadoc
|
||
42 | *
|
||
43 | * Revision 1.12 2007/08/03 11:29:13 jaume
|
||
44 | * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
|
||
45 | *
|
||
46 | * Revision 1.11 2007/07/23 07:01:13 jaume
|
||
47 | * outline setting bug fixed
|
||
48 | *
|
||
49 | * Revision 1.10 2007/07/12 10:43:55 jaume
|
||
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | * Revision 1.9 2007/06/29 13:07:33 jaume
|
||
53 | * +PictureLineSymbol
|
||
54 | *
|
||
55 | * Revision 1.8 2007/05/21 10:38:27 jaume
|
||
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | * Revision 1.7 2007/05/09 16:08:14 jaume
|
||
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | * Revision 1.6 2007/04/05 16:08:34 jaume
|
||
62 | * Styled labeling stuff
|
||
63 | *
|
||
64 | * Revision 1.5 2007/04/04 16:01:14 jaume
|
||
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | * Revision 1.4 2007/03/30 09:39:45 jaume
|
||
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | * Revision 1.3 2007/03/28 16:44:08 jaume
|
||
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | * Revision 1.2 2007/03/09 11:25:00 jaume
|
||
74 | * Advanced symbology (start committing)
|
||
75 | *
|
||
76 | * Revision 1.1.2.4 2007/02/21 16:09:35 jaume
|
||
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | * Revision 1.1.2.3 2007/02/21 07:35:14 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
||
83 | * some bug fixes in the editor and removed unnecessary imports
|
||
84 | *
|
||
85 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.1 2007/01/16 11:52:11 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.4 2006/11/13 09:15:23 jaume
|
||
92 | * javadoc and some clean-up
|
||
93 | *
|
||
94 | * Revision 1.3 2006/11/06 16:06:52 jaume
|
||
95 | * *** empty log message ***
|
||
96 | *
|
||
97 | * Revision 1.2 2006/10/30 19:30:35 jaume
|
||
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | * Revision 1.1 2006/10/27 12:41:09 jaume
|
||
101 | * GUI
|
||
102 | *
|
||
103 | *
|
||
104 | */
|
||
105 | package org.gvsig.app.gui.styling; |
||
106 | |||
107 | import java.awt.Color; |
||
108 | import java.awt.Dimension; |
||
109 | import java.awt.FlowLayout; |
||
110 | import java.awt.event.ActionEvent; |
||
111 | import java.awt.event.ActionListener; |
||
112 | import java.util.ArrayList; |
||
113 | |||
114 | import javax.swing.JCheckBox; |
||
115 | import javax.swing.JPanel; |
||
116 | import javax.swing.JSlider; |
||
117 | import javax.swing.event.ChangeEvent; |
||
118 | import javax.swing.event.ChangeListener; |
||
119 | |||
120 | //import org.gvsig.andami.messages.NotificationManager;
|
||
121 | import org.gvsig.app.gui.panels.ColorChooserPanel; |
||
122 | import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
||
123 | import org.gvsig.fmap.geom.Geometry; |
||
124 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
125 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
126 | import org.gvsig.gui.beans.swing.JBlank; |
||
127 | 42026 | jjdelcerro | import org.gvsig.gui.beans.swing.JNumberSpinner; |
128 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
129 | //import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
|
||
130 | import org.gvsig.symbology.SymbologyLocator; |
||
131 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
||
132 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol; |
||
133 | //import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
|
||
134 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
||
135 | import org.slf4j.Logger; |
||
136 | import org.slf4j.LoggerFactory; |
||
137 | |||
138 | /**
|
||
139 | * <b>SimpleFill</b> allows to store and modify the properties that fills a
|
||
140 | * polygon with a padding and an outline<p>
|
||
141 | * <p>
|
||
142 | * This functionality is carried out thanks to a tab (simple fill)which is included
|
||
143 | * in the panel to edit the properities of a symbol (SymbolEditor)how is explained
|
||
144 | * in AbstractTypeSymbolEditor.<p>
|
||
145 | * <p>
|
||
146 | * This tab permits the user to change the color of the padding
|
||
147 | * (<b>jccFillColor</b>)and its outline (<b>btnOutline</b>).Also the user has the
|
||
148 | * options to modify the opacity (<b>sldFillTransparency,sldOutlineTransparency</b>)
|
||
149 | * for both attributes and the width <b>txtOutlineWidth</b> (only for the outline).
|
||
150 | *
|
||
151 | *
|
||
152 | *@see AbstractTypeSymbolEditor
|
||
153 | *@author jaume dominguez faus - jaume.dominguez@iver.es
|
||
154 | */
|
||
155 | public class SimpleFill extends AbstractTypeSymbolEditor implements ActionListener, ChangeListener { |
||
156 | |||
157 | private static final Logger LOG = LoggerFactory.getLogger(SimpleFill.class); |
||
158 | |||
159 | private ColorChooserPanel jccFillColor;
|
||
160 | 42026 | jjdelcerro | private JNumberSpinner txtOutlineWidth;
|
161 | 40435 | jjdelcerro | private ArrayList tabs = new ArrayList(); |
162 | private JSymbolPreviewButton btnOutline;
|
||
163 | private JSlider sldOutlineTransparency; |
||
164 | private int outlineAlpha; |
||
165 | private ILineSymbol outline;
|
||
166 | private JCheckBox useBorder; |
||
167 | |||
168 | public SimpleFill(SymbolEditor owner) {
|
||
169 | super(owner);
|
||
170 | initialize(); |
||
171 | } |
||
172 | |||
173 | public String getName() { |
||
174 | return Messages.getText("simple_fill_symbol"); |
||
175 | } |
||
176 | |||
177 | public JPanel[] getTabs() { |
||
178 | return (JPanel[]) tabs.toArray(new JPanel[0]); |
||
179 | } |
||
180 | |||
181 | /**
|
||
182 | * Initializes the parameters that allows the user to fill the padding of
|
||
183 | * a polygon with a simplefill style.To do it, a tab (simple fill) is created inside the
|
||
184 | * SymbolEditor panel with default values for the different attributes.
|
||
185 | */
|
||
186 | private void initialize() { |
||
187 | JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
||
188 | myTab.setName(Messages.getText("simple_fill"));
|
||
189 | GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
||
190 | |||
191 | jccFillColor = new ColorChooserPanel(true,true); |
||
192 | jccFillColor.setAlpha(255);
|
||
193 | aux.addComponent(Messages.getText("fill_color"), jccFillColor);
|
||
194 | |||
195 | JPanel aux2 = new JPanel(); |
||
196 | btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
|
||
197 | btnOutline.setPreferredSize(new Dimension(100, 35)); |
||
198 | aux2.add(btnOutline); |
||
199 | |||
200 | aux.addComponent(new JBlank(10, 10)); |
||
201 | useBorder = new JCheckBox(Messages.getText("use_outline")); |
||
202 | aux.addComponent(useBorder, aux2); |
||
203 | aux.addComponent(new JBlank(10, 10)); |
||
204 | |||
205 | sldOutlineTransparency = new JSlider(); |
||
206 | sldOutlineTransparency.setValue(100);
|
||
207 | aux.addComponent(Messages.getText("outline")+":", |
||
208 | aux2); |
||
209 | aux.addComponent(Messages.getText("outline_opacity"), sldOutlineTransparency);
|
||
210 | 42079 | fdiaz | txtOutlineWidth = new JNumberSpinner(0.0, 25, 0.0, Double.MAX_VALUE, 1.0, 2); |
211 | 40435 | jjdelcerro | aux.addComponent(Messages.getText("outline_width"), txtOutlineWidth);
|
212 | myTab.add(aux); |
||
213 | |||
214 | useBorder.addActionListener(this);
|
||
215 | jccFillColor.addActionListener(this);
|
||
216 | btnOutline.addActionListener(this);
|
||
217 | txtOutlineWidth.addActionListener(this);
|
||
218 | sldOutlineTransparency.addChangeListener(this);
|
||
219 | tabs.add(myTab); |
||
220 | } |
||
221 | |||
222 | public ISymbol getLayer() {
|
||
223 | IFillSymbol layer = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol(); |
||
224 | |||
225 | layer.setHasOutline(useBorder.isSelected()); |
||
226 | outline = (ILineSymbol) btnOutline.getSymbol(); |
||
227 | |||
228 | if (outline!=null) { |
||
229 | outline.setLineWidth(txtOutlineWidth.getDouble()); |
||
230 | outline.setAlpha(outlineAlpha); |
||
231 | } |
||
232 | |||
233 | layer.setOutline(outline); |
||
234 | |||
235 | layer.setHasFill(jccFillColor.getUseColorisSelected()); |
||
236 | Color c = jccFillColor.getColor();
|
||
237 | if (c != null) |
||
238 | c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); |
||
239 | layer.setFillColor(c); |
||
240 | |||
241 | return layer;
|
||
242 | } |
||
243 | |||
244 | public void refreshControls(ISymbol layer) { |
||
245 | IFillSymbol sym; |
||
246 | try {
|
||
247 | if (layer == null) { |
||
248 | // initialize defaults
|
||
249 | LOG.warn(getClass().getName()+":: should be unreachable code", new Exception()); |
||
250 | } else {
|
||
251 | |||
252 | |||
253 | //fill
|
||
254 | |||
255 | sym = (IFillSymbol) layer; |
||
256 | jccFillColor.setUseColorIsSelected(sym.hasFill()); |
||
257 | jccFillColor.setColor(sym.getFillColor()); |
||
258 | //outline
|
||
259 | |||
260 | sldOutlineTransparency.removeChangeListener(this);
|
||
261 | |||
262 | outline=sym.getOutline(); |
||
263 | btnOutline.setSymbol(outline); |
||
264 | useBorder.setSelected(sym.hasOutline()); |
||
265 | |||
266 | if (outline != null) { |
||
267 | outlineAlpha = outline.getAlpha(); |
||
268 | sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100)); |
||
269 | txtOutlineWidth.setDouble(outline.getLineWidth()); |
||
270 | } else {
|
||
271 | sldOutlineTransparency.setValue(100);
|
||
272 | } |
||
273 | |||
274 | sldOutlineTransparency.addChangeListener(this);
|
||
275 | |||
276 | } |
||
277 | } catch (IndexOutOfBoundsException ioEx) { |
||
278 | LOG.warn("Symbol layer index out of bounds", ioEx);
|
||
279 | } catch (ClassCastException ccEx) { |
||
280 | LOG.warn("Illegal casting from " +
|
||
281 | layer.getClass().getName() + " to IFillSymbol.", ccEx);
|
||
282 | |||
283 | } |
||
284 | } |
||
285 | |||
286 | public boolean canManageSymbol(ISymbol symbol){ |
||
287 | return symbol instanceof ISimpleFillSymbol; |
||
288 | } |
||
289 | 42079 | fdiaz | |
290 | 40435 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
291 | Object s = e.getSource();
|
||
292 | |||
293 | if (s.equals(btnOutline)) {
|
||
294 | ISymbol sym = btnOutline.getSymbol(); |
||
295 | if (sym instanceof ILineSymbol) { |
||
296 | ILineSymbol outline = (ILineSymbol) sym; |
||
297 | if (outline != null) |
||
298 | txtOutlineWidth.setDouble(outline.getLineWidth()); |
||
299 | } |
||
300 | |||
301 | } |
||
302 | |||
303 | |||
304 | fireSymbolChangedEvent(); |
||
305 | } |
||
306 | |||
307 | public void stateChanged(ChangeEvent e) { |
||
308 | Object s = e.getSource();
|
||
309 | |||
310 | |||
311 | if (s.equals(sldOutlineTransparency)) {
|
||
312 | outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0)); |
||
313 | } |
||
314 | |||
315 | outline = (ILineSymbol) btnOutline.getSymbol(); |
||
316 | |||
317 | fireSymbolChangedEvent(); |
||
318 | } |
||
319 | |||
320 | public EditorTool[] getEditorTools() { |
||
321 | return null; |
||
322 | } |
||
323 | |||
324 | |||
325 | |||
326 | |||
327 | } |