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 / MarkerFill.java @ 40560
History | View | Annotate | Download (12.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 3
|
9 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id: MarkerFill.java 14735 2007-10-18 16:01:39Z jdominguez $
|
27 |
* $Log$
|
28 |
* Revision 1.20 2007-09-17 09:21:45 jaume
|
29 |
* refactored SymboSelector (added support for multishapedsymbol)
|
30 |
*
|
31 |
* Revision 1.19 2007/08/10 07:28:25 jaume
|
32 |
* translations
|
33 |
*
|
34 |
* Revision 1.18 2007/08/09 10:39:04 jaume
|
35 |
* first round of found bugs fixed
|
36 |
*
|
37 |
* Revision 1.17 2007/08/08 11:49:15 jaume
|
38 |
* refactored to avoid provide more than one EditorTool
|
39 |
*
|
40 |
* Revision 1.15 2007/08/03 11:29:13 jaume
|
41 |
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
|
42 |
*
|
43 |
* Revision 1.14 2007/08/03 09:20:46 jaume
|
44 |
* refactored class names
|
45 |
*
|
46 |
* Revision 1.13 2007/08/01 13:02:08 jaume
|
47 |
* renamed methods
|
48 |
*
|
49 |
* Revision 1.12 2007/07/30 12:56:04 jaume
|
50 |
* organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
|
51 |
*
|
52 |
* Revision 1.11 2007/06/29 13:07:33 jaume
|
53 |
* +PictureLineSymbol
|
54 |
*
|
55 |
* Revision 1.10 2007/05/28 13:34:28 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.9 2007/05/08 15:44:07 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.8 2007/04/27 12:10:17 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.7 2007/04/05 16:08:34 jaume
|
65 |
* Styled labeling stuff
|
66 |
*
|
67 |
* Revision 1.6 2007/04/04 16:01:14 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.5 2007/03/28 16:44:08 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.4 2007/03/13 16:57:35 jaume
|
74 |
* Added MultiVariable legend
|
75 |
*
|
76 |
* Revision 1.3 2007/03/09 11:25:00 jaume
|
77 |
* Advanced symbology (start committing)
|
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.8 2007/01/10 17:05:05 jaume
|
92 |
* moved to FMap and gvSIG
|
93 |
*
|
94 |
* Revision 1.7 2006/11/13 09:15:23 jaume
|
95 |
* javadoc and some clean-up
|
96 |
*
|
97 |
* Revision 1.6 2006/11/06 16:06:52 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.5 2006/11/02 17:19:28 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.4 2006/10/31 16:16:34 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.3 2006/10/30 19:30:35 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.2 2006/10/29 23:53:49 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.1 2006/10/27 12:41:09 jaume
|
113 |
* GUI
|
114 |
*
|
115 |
*
|
116 |
*/
|
117 |
package org.gvsig.app.gui.styling; |
118 |
|
119 |
import java.awt.Color; |
120 |
import java.awt.Dimension; |
121 |
import java.awt.FlowLayout; |
122 |
import java.awt.event.ActionEvent; |
123 |
import java.awt.event.ActionListener; |
124 |
import java.util.ArrayList; |
125 |
|
126 |
import javax.swing.ButtonGroup; |
127 |
import javax.swing.JCheckBox; |
128 |
import javax.swing.JComponent; |
129 |
import javax.swing.JPanel; |
130 |
import javax.swing.JRadioButton; |
131 |
import javax.swing.JSlider; |
132 |
import javax.swing.event.ChangeEvent; |
133 |
import javax.swing.event.ChangeListener; |
134 |
|
135 |
import org.gvsig.andami.PluginServices; |
136 |
import org.gvsig.andami.messages.NotificationManager; |
137 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
138 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
139 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
140 |
import org.gvsig.fmap.geom.Geometry; |
141 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
142 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
143 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
144 |
import org.gvsig.gui.beans.swing.JBlank; |
145 |
import org.gvsig.gui.beans.swing.JButton; |
146 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
147 |
import org.gvsig.i18n.Messages; |
148 |
import org.gvsig.symbology.SymbologyLocator; |
149 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMarkerFillSymbol; |
150 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
151 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
152 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
153 |
/**
|
154 |
* <b>MarkerFill</b> allows the user to store and modify the properties that fills a
|
155 |
* polygon with a padding made of markers and an outline<p>
|
156 |
* <p>
|
157 |
* This functionality is carried out thanks to two tabs (marker fill and MarkerFillProperties)
|
158 |
* which are included in the panel to edit the properities of a symbol (SymbolEditor)
|
159 |
* how is explained in AbstractTypeSymbolEditor.<p>
|
160 |
* <p>
|
161 |
* The first tab (marker fill)permits the user to select the marker for the padding and
|
162 |
* other options such as the color for the fill (<b>btnChooseMarker</b>),to select the
|
163 |
* ouline (<b>btnOutline</b>)and the distribution (grid or random) of the marker inside
|
164 |
* the padding (<b>rdGrid,rdRandom</b>).
|
165 |
* <p>
|
166 |
* The second tab is implementes as a MarkerFillProperties class and offers the possibilities
|
167 |
* to change the separtion and the offset.
|
168 |
*
|
169 |
*
|
170 |
*@see MarkerFillProperties
|
171 |
*@see AbstractTypeSymbolEditor
|
172 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
173 |
*/
|
174 |
public class MarkerFill extends AbstractTypeSymbolEditor implements ActionListener,ChangeListener { |
175 |
private ArrayList<JPanel> tabs = new ArrayList<JPanel>(); |
176 |
private ColorChooserPanel markerCC;
|
177 |
private JButton btnChooseMarker; |
178 |
private MarkerFillProperties panelStyle = new MarkerFillProperties(); |
179 |
private JRadioButton rdGrid; |
180 |
private JRadioButton rdRandom; |
181 |
private IMarkerSymbol marker = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol();
|
182 |
|
183 |
private JIncrementalNumberField txtOutlineWidth;
|
184 |
private JSymbolPreviewButton btnOutline;
|
185 |
private JSlider sldOutlineTransparency; |
186 |
private int outlineAlpha = 255; |
187 |
private ILineSymbol outline;
|
188 |
private JCheckBox useBorder; |
189 |
|
190 |
/**
|
191 |
* constructor method
|
192 |
* @param owner
|
193 |
*/
|
194 |
public MarkerFill(SymbolEditor owner) {
|
195 |
super(owner);
|
196 |
initialize(); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Initializes the parameters that allows the user to fill the padding of
|
201 |
* a polygon with a style made of markers.To do it, two tabs are created (marker
|
202 |
* fill and MarkerFillProperties)inside the SymbolEditor panel with default values
|
203 |
* for the different attributes.
|
204 |
*/
|
205 |
private void initialize() { |
206 |
// GridLayout layout;
|
207 |
JPanel myTab;
|
208 |
// Marker fill tab
|
209 |
|
210 |
{ |
211 |
myTab = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10)); |
212 |
myTab.setName(Messages.getText("marker_fill"));
|
213 |
|
214 |
GridBagLayoutPanel p = new GridBagLayoutPanel();
|
215 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
216 |
markerCC = new ColorChooserPanel(true); |
217 |
markerCC.setAlpha(255);
|
218 |
markerCC.addActionListener(this);
|
219 |
aux.add(markerCC); |
220 |
|
221 |
p.addComponent(Messages.getText("color")+":", aux); |
222 |
btnChooseMarker = new JButton(Messages.getText("choose_marker")); |
223 |
btnChooseMarker.addActionListener(this);
|
224 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
225 |
aux.add(btnChooseMarker); |
226 |
p.addComponent("", aux);
|
227 |
|
228 |
ButtonGroup group = new ButtonGroup(); |
229 |
rdGrid = new JRadioButton(Messages.getText("grid")); |
230 |
rdGrid.addActionListener(this);
|
231 |
rdRandom = new JRadioButton(Messages.getText("random")); |
232 |
rdRandom.addActionListener(this);
|
233 |
group.add(rdGrid); |
234 |
group.add(rdRandom); |
235 |
|
236 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
237 |
aux.add(rdGrid); |
238 |
aux.add(rdRandom); |
239 |
rdGrid.setSelected(true);
|
240 |
p.addComponent("", aux);
|
241 |
|
242 |
|
243 |
JPanel myTab2 = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
244 |
GridBagLayoutPanel aux3 = new GridBagLayoutPanel();
|
245 |
|
246 |
JPanel aux2 = new JPanel(); |
247 |
btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
|
248 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
249 |
aux2.add(btnOutline); |
250 |
|
251 |
aux3.addComponent(new JBlank(10, 10)); |
252 |
useBorder = new JCheckBox(Messages.getText("use_outline")); |
253 |
aux3.addComponent(useBorder, aux2); |
254 |
aux3.addComponent(new JBlank(10, 10)); |
255 |
|
256 |
sldOutlineTransparency = new JSlider(); |
257 |
sldOutlineTransparency.setValue(100);
|
258 |
aux3.addComponent(Messages.getText("outline")+":", |
259 |
aux2); |
260 |
aux3.addComponent(Messages.getText("outline_opacity")+":", sldOutlineTransparency); |
261 |
txtOutlineWidth = new JIncrementalNumberField("", 25, 0, Double.MAX_VALUE, 1); |
262 |
aux3.addComponent(Messages.getText("outline_width")+":", txtOutlineWidth); |
263 |
myTab2.add(aux3); |
264 |
|
265 |
p.addComponent("", myTab2);
|
266 |
myTab.add(p); |
267 |
|
268 |
useBorder.addActionListener(this);
|
269 |
btnOutline.addActionListener(this);
|
270 |
txtOutlineWidth.addActionListener(this);
|
271 |
sldOutlineTransparency.addChangeListener(this);
|
272 |
|
273 |
} |
274 |
tabs.add(myTab); |
275 |
|
276 |
// Fill properties tab
|
277 |
tabs.add(panelStyle); |
278 |
panelStyle.addActionListener(this);
|
279 |
} |
280 |
|
281 |
public void refreshControls(ISymbol layer) { |
282 |
if (layer == null) { |
283 |
System.err.println(getClass().getName()+":: should be unreachable code"); |
284 |
// set defaults
|
285 |
markerCC.setColor(Color.BLACK);
|
286 |
rdGrid.setSelected(true);
|
287 |
rdRandom.setSelected(false);
|
288 |
} else {
|
289 |
|
290 |
IMarkerFillSymbol mfs = (IMarkerFillSymbol) layer; |
291 |
int fillStyle = mfs.getMarkerFillProperties().getFillStyle();
|
292 |
marker = mfs.getMarker(); |
293 |
rdGrid.setSelected(fillStyle == IMarkerFillPropertiesStyle.GRID_FILL); |
294 |
rdRandom.setSelected(fillStyle == IMarkerFillPropertiesStyle.RANDOM_FILL); |
295 |
panelStyle.setModel(mfs.getMarkerFillProperties()); |
296 |
markerCC.setColor(marker.getColor()); |
297 |
|
298 |
//outline
|
299 |
sldOutlineTransparency.removeChangeListener(this);
|
300 |
|
301 |
outline=mfs.getOutline(); |
302 |
btnOutline.setSymbol(outline); |
303 |
useBorder.setSelected(mfs.hasOutline()); |
304 |
|
305 |
if (outline != null) { |
306 |
outlineAlpha = outline.getAlpha(); |
307 |
sldOutlineTransparency.setValue((int)((outlineAlpha/255D)*100)); |
308 |
txtOutlineWidth.setDouble(outline.getLineWidth()); |
309 |
} else {
|
310 |
sldOutlineTransparency.setValue(100);
|
311 |
} |
312 |
|
313 |
sldOutlineTransparency.addChangeListener(this);
|
314 |
|
315 |
|
316 |
|
317 |
} |
318 |
} |
319 |
|
320 |
public String getName() { |
321 |
return Messages.getText("marker_fill_symbol"); |
322 |
} |
323 |
|
324 |
public JPanel[] getTabs() { |
325 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
326 |
} |
327 |
|
328 |
public void actionPerformed(ActionEvent e) { |
329 |
|
330 |
JComponent comp = (JComponent) e.getSource(); |
331 |
if (comp.equals(btnChooseMarker)) {
|
332 |
ISymbolSelector symSelect = SymbolSelector.createSymbolSelector(marker, Geometry.TYPES.POINT); |
333 |
PluginServices.getMDIManager().addWindow(symSelect); |
334 |
marker = (IMarkerSymbol) symSelect.getSelectedObject(); |
335 |
|
336 |
if (marker == null) return; |
337 |
|
338 |
} |
339 |
|
340 |
if (!(marker instanceof IMultiLayerSymbol)) { |
341 |
marker.setColor(markerCC.getColor()); |
342 |
} |
343 |
|
344 |
if (comp.equals(btnOutline)) {
|
345 |
ISymbol sym = btnOutline.getSymbol(); |
346 |
if (sym instanceof ILineSymbol) { |
347 |
ILineSymbol outline = (ILineSymbol) sym; |
348 |
if (outline != null) |
349 |
txtOutlineWidth.setDouble(outline.getLineWidth()); |
350 |
} |
351 |
|
352 |
} |
353 |
|
354 |
fireSymbolChangedEvent(); |
355 |
} |
356 |
|
357 |
public ISymbol getLayer() {
|
358 |
IMarkerFillSymbol mfs = SymbologyLocator.getSymbologyManager().createMarkerFillSymbol(); |
359 |
IMarkerFillPropertiesStyle prop = panelStyle.getMarkerFillProperties(); |
360 |
prop.setFillStyle(rdGrid.isSelected() ? |
361 |
IMarkerFillPropertiesStyle.GRID_FILL : IMarkerFillPropertiesStyle.RANDOM_FILL); |
362 |
|
363 |
IMarkerSymbol myMarker; |
364 |
try {
|
365 |
myMarker = (IMarkerSymbol) marker.clone(); |
366 |
mfs.setMarker(myMarker); |
367 |
} catch (CloneNotSupportedException e) { |
368 |
NotificationManager.addWarning( |
369 |
"Marker Symbol does not support cloning", e);
|
370 |
} |
371 |
|
372 |
mfs.setMarkerFillProperties(prop); |
373 |
|
374 |
mfs.setHasOutline(useBorder.isSelected()); |
375 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
376 |
|
377 |
if (outline!=null) { |
378 |
outline.setLineWidth(txtOutlineWidth.getDouble()); |
379 |
outline.setAlpha(outlineAlpha); |
380 |
} |
381 |
|
382 |
mfs.setOutline(outline); |
383 |
|
384 |
return mfs;
|
385 |
} |
386 |
|
387 |
public EditorTool[] getEditorTools() { |
388 |
return null; |
389 |
} |
390 |
|
391 |
public void stateChanged(ChangeEvent e) { |
392 |
Object s = e.getSource();
|
393 |
|
394 |
if (s.equals(sldOutlineTransparency)) {
|
395 |
outlineAlpha = (int) (255*(sldOutlineTransparency.getValue()/100.0)); |
396 |
} |
397 |
|
398 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
399 |
fireSymbolChangedEvent(); |
400 |
|
401 |
} |
402 |
|
403 |
@Override
|
404 |
public boolean canManageSymbol(ISymbol symbol) { |
405 |
return symbol instanceof IMarkerFillSymbol; |
406 |
} |
407 |
} |