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