root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / symbols / SimpleMarkerSymbol.java @ 24494
History | View | Annotate | Download (12.2 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: SimpleMarkerSymbol.java 21071 2008-06-02 10:55:35Z vcaballero $
|
45 |
* $Log$
|
46 |
* Revision 1.19 2007-09-21 12:25:32 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.18 2007/09/19 16:22:04 jaume
|
50 |
* removed unnecessary imports
|
51 |
*
|
52 |
* Revision 1.17 2007/08/09 07:32:20 jvidal
|
53 |
* javadoc
|
54 |
*
|
55 |
* Revision 1.16 2007/07/23 06:52:25 jaume
|
56 |
* default selection color refactored, moved to MapContext
|
57 |
*
|
58 |
* Revision 1.15 2007/07/18 06:54:35 jaume
|
59 |
* continuing with cartographic support
|
60 |
*
|
61 |
* Revision 1.14 2007/07/03 10:58:29 jaume
|
62 |
* first refactor on CartographicSupport
|
63 |
*
|
64 |
* Revision 1.13 2007/06/27 06:31:17 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.12 2007/06/07 06:50:40 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.11 2007/05/29 15:46:37 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.10 2007/05/28 15:36:42 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.9 2007/05/09 16:07:26 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.8 2007/05/08 08:47:40 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.7 2007/03/27 07:11:32 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.6 2007/03/13 16:58:36 jaume
|
86 |
* Added QuantityByCategory (Multivariable legend) and some bugfixes in symbols
|
87 |
*
|
88 |
* Revision 1.5 2007/03/09 11:20:56 jaume
|
89 |
* Advanced symbology (start committing)
|
90 |
*
|
91 |
* Revision 1.3.2.7 2007/02/21 07:34:09 jaume
|
92 |
* labeling starts working
|
93 |
*
|
94 |
* Revision 1.3.2.6 2007/02/16 10:54:12 jaume
|
95 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
96 |
*
|
97 |
* Revision 1.3.2.5 2007/02/15 16:23:44 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.3.2.4 2007/02/13 16:19:19 jaume
|
101 |
* graduated symbol legends (start commiting)
|
102 |
*
|
103 |
* Revision 1.3.2.3 2007/02/12 15:15:20 jaume
|
104 |
* refactored interval legend and added graduated symbol legend
|
105 |
*
|
106 |
* Revision 1.3.2.2 2007/02/09 07:47:05 jaume
|
107 |
* Isymbol moved
|
108 |
*
|
109 |
* Revision 1.3.2.1 2007/02/05 14:59:03 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.3 2007/01/25 16:25:23 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
116 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
117 |
*
|
118 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
* Revision 1.1 2006/11/14 11:10:27 jaume
|
122 |
* *** empty log message ***
|
123 |
*
|
124 |
*
|
125 |
*/
|
126 |
package org.gvsig.fmap.mapcontext.rendering.symbols; |
127 |
|
128 |
import java.awt.BasicStroke; |
129 |
import java.awt.Color; |
130 |
import java.awt.Graphics2D; |
131 |
import java.awt.Point; |
132 |
import java.awt.geom.AffineTransform; |
133 |
|
134 |
import javax.print.attribute.PrintRequestAttributeSet; |
135 |
|
136 |
import org.gvsig.fmap.dal.exceptions.ReadException; |
137 |
import org.gvsig.fmap.geom.Geometry; |
138 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
139 |
import org.gvsig.fmap.geom.primitive.Point2D; |
140 |
import org.gvsig.fmap.mapcontext.MapContext; |
141 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IMask; |
142 |
|
143 |
import com.iver.utiles.StringUtilities; |
144 |
import com.iver.utiles.XMLEntity; |
145 |
import com.iver.utiles.swing.threads.Cancellable; |
146 |
|
147 |
/**
|
148 |
* SimpleMarkerSymbol is the most basic symbol for the representation of point objects
|
149 |
* which can define its size and color apart from the rotation and the offset from a point
|
150 |
* in the map.
|
151 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
152 |
*/
|
153 |
public class SimpleMarkerSymbol extends AbstractMarkerSymbol { |
154 |
|
155 |
public static final int CIRCLE_STYLE = 0; |
156 |
public static final int SQUARE_STYLE = 1; |
157 |
public static final int CROSS_STYLE = 2; |
158 |
public static final int DIAMOND_STYLE = 3; |
159 |
public static final int X_STYLE = 4; |
160 |
public static final int TRIANGLE_STYLE = 5; |
161 |
public static final int STAR_STYLE = 6; |
162 |
private boolean outlined; |
163 |
private Color outlineColor; |
164 |
private double outlineSize; |
165 |
private ISymbol selectionSymbol;
|
166 |
private int markerStyle; |
167 |
|
168 |
public ISymbol getSymbolForSelection() {
|
169 |
if (selectionSymbol == null) { |
170 |
XMLEntity xml = getXMLEntity(); |
171 |
xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
|
172 |
selectionSymbol = SymbologyFactory. |
173 |
createSymbolFromXML(xml, getDescription()+" version for selection");
|
174 |
} |
175 |
return selectionSymbol;
|
176 |
} |
177 |
|
178 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Cancellable cancel) { |
179 |
int x, y;
|
180 |
// Point2D p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp)
|
181 |
// .getY());
|
182 |
Point2D p = (Point2D) geom; |
183 |
|
184 |
int size = (int) getSize(); |
185 |
|
186 |
int halfSize = size/2; |
187 |
x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
188 |
y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
189 |
|
190 |
IMask mask = getMask(); |
191 |
if (mask != null) { |
192 |
IFillSymbol maskShape = mask.getFillSymbol(); |
193 |
// maskShape.draw(g, null, mask.getHaloShape(shp));
|
194 |
} |
195 |
|
196 |
g.setColor(getColor()); |
197 |
GeneralPathX genPath = null;
|
198 |
|
199 |
switch (markerStyle) {
|
200 |
case CIRCLE_STYLE:
|
201 |
g.fillOval(x, y, size, size); |
202 |
break;
|
203 |
case SQUARE_STYLE:
|
204 |
g.fillRect(x, y, size, size); |
205 |
break;
|
206 |
case CROSS_STYLE:
|
207 |
x = x + halfSize; |
208 |
y = y + halfSize; |
209 |
genPath = new GeneralPathX();
|
210 |
genPath.moveTo(x, y - halfSize); |
211 |
genPath.lineTo(x, y + halfSize); |
212 |
genPath.moveTo(x - halfSize, y); |
213 |
genPath.lineTo(x + halfSize, y); |
214 |
g.draw(genPath); |
215 |
break;
|
216 |
case DIAMOND_STYLE:
|
217 |
x = x + halfSize; |
218 |
y = y + halfSize; |
219 |
genPath = new GeneralPathX();
|
220 |
genPath.moveTo(x-halfSize, y); |
221 |
genPath.lineTo(x, y+halfSize); |
222 |
genPath.lineTo(x+halfSize, y); |
223 |
genPath.lineTo(x, y-halfSize); |
224 |
genPath.lineTo(x-halfSize, y); |
225 |
genPath.closePath(); |
226 |
g.fill(genPath); |
227 |
break;
|
228 |
case X_STYLE:
|
229 |
x = x + halfSize; |
230 |
y = y + halfSize; |
231 |
genPath = new GeneralPathX();
|
232 |
genPath.moveTo(x-halfSize, y - halfSize); |
233 |
genPath.lineTo(x+halfSize, y + halfSize); |
234 |
genPath.moveTo(x - halfSize, y + halfSize); |
235 |
genPath.lineTo(x + halfSize, y - halfSize); |
236 |
g.draw(genPath); |
237 |
break;
|
238 |
case TRIANGLE_STYLE:
|
239 |
x = x + halfSize; |
240 |
y = y + halfSize; |
241 |
int otherSize = (int) (size * 0.55); |
242 |
genPath = new GeneralPathX();
|
243 |
genPath.moveTo(x - halfSize, |
244 |
y + halfSize); |
245 |
genPath.lineTo(x + halfSize, |
246 |
y + halfSize); |
247 |
genPath.lineTo(x, y - otherSize); |
248 |
genPath.closePath(); |
249 |
|
250 |
g.fill(genPath); |
251 |
break;
|
252 |
case STAR_STYLE:
|
253 |
x = x + halfSize; |
254 |
y = y + halfSize; |
255 |
genPath = new GeneralPathX();
|
256 |
genPath.moveTo(x-halfSize, y); |
257 |
|
258 |
genPath.lineTo(x-2*(halfSize/3), y+(halfSize/3)); |
259 |
genPath.lineTo(x-2*(halfSize/3), y+2*(halfSize/3)); |
260 |
genPath.lineTo(x-(halfSize/3), y+2*(halfSize/3)); |
261 |
|
262 |
genPath.lineTo(x, y+halfSize); |
263 |
|
264 |
genPath.lineTo(x+(halfSize/3), y+2*(halfSize/3)); |
265 |
genPath.lineTo(x+2*(halfSize/3), y+2*(halfSize/3)); |
266 |
genPath.lineTo(x+2*(halfSize/3), y+(halfSize/3)); |
267 |
|
268 |
genPath.lineTo(x+(halfSize), y); |
269 |
|
270 |
genPath.lineTo(x+2*(halfSize/3), y-(halfSize/3)); |
271 |
genPath.lineTo(x+2*(halfSize/3), y-2*(halfSize/3)); |
272 |
genPath.lineTo(x+(halfSize/3), y-2*(halfSize/3)); |
273 |
|
274 |
genPath.lineTo(x, y-halfSize); |
275 |
|
276 |
genPath.lineTo(x-(halfSize/3), y-2*(halfSize/3)); |
277 |
genPath.lineTo(x-2*(halfSize/3), y-2*(halfSize/3)); |
278 |
genPath.lineTo(x-2*(halfSize/3), y-(halfSize/3)); |
279 |
|
280 |
genPath.lineTo(x-halfSize, y); |
281 |
|
282 |
genPath.closePath(); |
283 |
|
284 |
|
285 |
g.fill(genPath); |
286 |
|
287 |
break;
|
288 |
} |
289 |
|
290 |
|
291 |
if (outlined) {
|
292 |
g.setColor(outlineColor); |
293 |
g.setStroke(new BasicStroke(1)); |
294 |
switch (markerStyle) {
|
295 |
case CIRCLE_STYLE:
|
296 |
g.drawOval(x, y, size, size); |
297 |
break;
|
298 |
case SQUARE_STYLE:
|
299 |
g.drawRect(x, y, size, size); |
300 |
break;
|
301 |
case CROSS_STYLE:
|
302 |
case DIAMOND_STYLE:
|
303 |
case STAR_STYLE:
|
304 |
case X_STYLE:
|
305 |
case TRIANGLE_STYLE:
|
306 |
g.draw(genPath); |
307 |
break;
|
308 |
} |
309 |
} |
310 |
} |
311 |
|
312 |
public XMLEntity getXMLEntity() {
|
313 |
XMLEntity xml = new XMLEntity();
|
314 |
xml.putProperty("className", getClassName());
|
315 |
xml.putProperty("desc", getDescription());
|
316 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
317 |
xml.putProperty("color", StringUtilities.color2String(getColor()));
|
318 |
xml.putProperty("rotation", getRotation());
|
319 |
xml.putProperty("offsetX", getOffset().getX());
|
320 |
xml.putProperty("offsetY", getOffset().getY());
|
321 |
xml.putProperty("size", getSize());
|
322 |
xml.putProperty("outline", outlined);
|
323 |
xml.putProperty("unit", getUnit());
|
324 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
325 |
xml.putProperty("markerStyle", getStyle());
|
326 |
|
327 |
if (outlined) {
|
328 |
xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
|
329 |
xml.putProperty("outlineSize", outlineSize);
|
330 |
} |
331 |
return xml;
|
332 |
} |
333 |
|
334 |
|
335 |
public String getClassName() { |
336 |
return getClass().getName();
|
337 |
} |
338 |
|
339 |
public void setXMLEntity(XMLEntity xml) { |
340 |
setDescription(xml.getStringProperty("desc"));
|
341 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
342 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
343 |
setRotation(xml.getDoubleProperty("rotation"));
|
344 |
setOffset(new Point.Double(xml.getDoubleProperty("offsetX"), |
345 |
xml.getDoubleProperty("offsetY")));
|
346 |
setSize(xml.getDoubleProperty("size"));
|
347 |
setOutlined(xml.getBooleanProperty("outline"));
|
348 |
setUnit(xml.getIntProperty("unit"));
|
349 |
setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
350 |
setStyle(xml.getIntProperty("markerStyle"));
|
351 |
if (hasOutline()) {
|
352 |
setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
|
353 |
setOutlineSize(xml.getDoubleProperty("outlineSize"));
|
354 |
} |
355 |
} |
356 |
|
357 |
/**
|
358 |
* Returns true or false depending if the simple marker symbol has an outline or not.
|
359 |
* @return Returns the outline.
|
360 |
*/
|
361 |
public boolean hasOutline() { |
362 |
return outlined;
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* Establishes the outline for the simple marker symbol.
|
367 |
* @param outline The outline to set.
|
368 |
*/
|
369 |
public void setOutlined(boolean outlined) { |
370 |
this.outlined = outlined;
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* Returns the outline color for the symple marker symbol
|
375 |
*
|
376 |
* @return Color,outlineColor.
|
377 |
*/
|
378 |
public Color getOutlineColor() { |
379 |
return outlineColor;
|
380 |
} |
381 |
|
382 |
/**
|
383 |
* Sets the outline color for the simple marker symbol
|
384 |
* @param outlineColor, Color
|
385 |
*/
|
386 |
public void setOutlineColor(Color outlineColor) { |
387 |
this.outlineColor = outlineColor;
|
388 |
} |
389 |
|
390 |
/**
|
391 |
* Gets the size of the outline for the simple marker symbol
|
392 |
* @return Returns the outlineSize.
|
393 |
*/
|
394 |
public double getOutlineSize() { |
395 |
return outlineSize;
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* Establishes the size for the outline of the simple marker symbol
|
400 |
* @param outlineSize The outlineSize to set.
|
401 |
*/
|
402 |
public void setOutlineSize(double outlineSize) { |
403 |
this.outlineSize = outlineSize;
|
404 |
} |
405 |
|
406 |
/**
|
407 |
* @return Returns the selectionSymbol.
|
408 |
*/
|
409 |
public ISymbol getSelectionSymbol() {
|
410 |
return selectionSymbol;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* @param selectionSymbol The selectionSymbol to set.
|
415 |
*/
|
416 |
public void setSelectionSymbol(ISymbol selectionSymbol) { |
417 |
this.selectionSymbol = selectionSymbol;
|
418 |
} |
419 |
/**
|
420 |
* Sets the style for the simple marker symbol
|
421 |
* @param style
|
422 |
*/
|
423 |
public void setStyle(int style) { |
424 |
this.markerStyle = style;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* Obtains the style for the simple marker symbol
|
429 |
* @return markerStyle,int
|
430 |
*/
|
431 |
public int getStyle() { |
432 |
return markerStyle;
|
433 |
} |
434 |
|
435 |
} |