root / branches / v2_0_0_prep / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / symbols / MultiShapeSymbol.java @ 21200
History | View | Annotate | Download (14 KB)
1 |
package org.gvsig.fmap.mapcontext.rendering.symbols; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.Rectangle; |
6 |
import java.awt.geom.AffineTransform; |
7 |
import java.awt.geom.Point2D; |
8 |
import java.util.logging.Logger; |
9 |
|
10 |
import javax.print.attribute.PrintRequestAttributeSet; |
11 |
|
12 |
import org.gvsig.data.ReadException; |
13 |
import org.gvsig.fmap.geom.Geometry; |
14 |
import org.gvsig.fmap.geom.primitive.FShape; |
15 |
import org.gvsig.fmap.mapcontext.ViewPort; |
16 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILineStyle; |
17 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IMask; |
18 |
|
19 |
import com.iver.utiles.XMLEntity; |
20 |
import com.iver.utiles.swing.threads.Cancellable; |
21 |
|
22 |
/**
|
23 |
* MultiShapeSymbol class allows to create a composition of several symbols with
|
24 |
* different shapes and be treated as a single symbol.These shapes can be marker,line
|
25 |
* or fill.
|
26 |
*
|
27 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
28 |
*/
|
29 |
|
30 |
public class MultiShapeSymbol implements ILineSymbol, IMarkerSymbol, IFillSymbol { |
31 |
private IMarkerSymbol marker = SymbologyFactory.createDefaultMarkerSymbol();
|
32 |
private ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
|
33 |
private IFillSymbol fill = SymbologyFactory.createDefaultFillSymbol();
|
34 |
private IMask mask;
|
35 |
private String desc; |
36 |
private int referenceSystem; |
37 |
private MultiShapeSymbol symSelect;
|
38 |
|
39 |
public Color getLineColor() { |
40 |
return line.getColor();
|
41 |
} |
42 |
|
43 |
public void setLineColor(Color color) { |
44 |
line.setLineColor(color); |
45 |
} |
46 |
|
47 |
public ILineStyle getLineStyle() {
|
48 |
return line.getLineStyle();
|
49 |
} |
50 |
|
51 |
public void setLineStyle(ILineStyle lineStyle) { |
52 |
line.setLineStyle(lineStyle); |
53 |
} |
54 |
|
55 |
public void setLineWidth(double width) { |
56 |
line.setLineWidth(width); |
57 |
} |
58 |
|
59 |
public double getLineWidth() { |
60 |
return line.getLineWidth();
|
61 |
} |
62 |
|
63 |
public int getAlpha() { |
64 |
return line.getAlpha();
|
65 |
} |
66 |
|
67 |
public void setAlpha(int outlineAlpha) { |
68 |
line.setAlpha(outlineAlpha); |
69 |
} |
70 |
|
71 |
public ISymbol getSymbolForSelection() {
|
72 |
if (symSelect == null) { |
73 |
symSelect = new MultiShapeSymbol();
|
74 |
} |
75 |
|
76 |
if (marker!=null){ |
77 |
symSelect.setMarkerSymbol((IMarkerSymbol) marker.getSymbolForSelection()); |
78 |
} |
79 |
|
80 |
if (line!=null){ |
81 |
symSelect.setLineSymbol((ILineSymbol) line.getSymbolForSelection()); |
82 |
} |
83 |
|
84 |
if (fill!=null ){ |
85 |
symSelect.setFillSymbol((IFillSymbol) fill.getSymbolForSelection()); |
86 |
} |
87 |
|
88 |
return symSelect;
|
89 |
|
90 |
} |
91 |
|
92 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Cancellable cancel) { |
93 |
switch (geom.getType()) {
|
94 |
case Geometry.TYPES.POINT: //Tipo punto |
95 |
case Geometry.TYPES.POINT + Geometry.TYPES.Z:
|
96 |
if (marker != null) |
97 |
marker.draw(g, affineTransform, geom, cancel); |
98 |
break;
|
99 |
case Geometry.TYPES.CURVE:
|
100 |
case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
|
101 |
case Geometry.TYPES.ARC:
|
102 |
case Geometry.TYPES.ARC + Geometry.TYPES.Z:
|
103 |
if (line != null) |
104 |
line.draw(g, affineTransform, geom, cancel); |
105 |
break;
|
106 |
|
107 |
case Geometry.TYPES.SURFACE:
|
108 |
case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
|
109 |
case Geometry.TYPES.ELLIPSE:
|
110 |
case Geometry.TYPES.ELLIPSE + Geometry.TYPES.Z:
|
111 |
case Geometry.TYPES.CIRCLE:
|
112 |
case Geometry.TYPES.CIRCLE + Geometry.TYPES.Z:
|
113 |
if (fill != null) |
114 |
fill.draw(g, affineTransform, geom, cancel); |
115 |
break;
|
116 |
} |
117 |
|
118 |
|
119 |
} |
120 |
|
121 |
public void getPixExtentPlus(Geometry geom, float[] distances, |
122 |
ViewPort viewPort, int dpi) {
|
123 |
// TODO Implement it
|
124 |
throw new Error("Not yet implemented!"); |
125 |
|
126 |
} |
127 |
|
128 |
public int getOnePointRgb() { |
129 |
// will return a mixture of all symbol's getOnePointRgb() value
|
130 |
|
131 |
int rMarker = 0; |
132 |
int gMarker = 0; |
133 |
int bMarker = 0; |
134 |
int aMarker = 0; |
135 |
|
136 |
if (marker!=null && marker.getColor() != null) { |
137 |
rMarker = marker.getColor().getRed(); |
138 |
gMarker = marker.getColor().getGreen(); |
139 |
bMarker = marker.getColor().getBlue(); |
140 |
aMarker = marker.getColor().getAlpha(); |
141 |
} |
142 |
|
143 |
int rLine = 0; |
144 |
int gLine = 0; |
145 |
int bLine = 0; |
146 |
int aLine = 0; |
147 |
|
148 |
if (line != null && line.getColor() != null) { |
149 |
rLine = line.getColor().getRed(); |
150 |
gLine = line.getColor().getGreen(); |
151 |
bLine = line.getColor().getBlue(); |
152 |
aLine = line.getColor().getAlpha(); |
153 |
} |
154 |
|
155 |
int rFill = 0; |
156 |
int gFill = 0; |
157 |
int bFill = 0; |
158 |
int aFill = 0; |
159 |
|
160 |
if (fill != null ) { |
161 |
Color colorOfFill = null; |
162 |
if (fill.getOutline()!=null) { |
163 |
colorOfFill = fill.getOutline().getColor(); |
164 |
} else if (fill.getFillColor()!=null) { |
165 |
colorOfFill = fill.getFillColor(); |
166 |
} |
167 |
if (colorOfFill != null) { |
168 |
rFill = colorOfFill.getRed(); |
169 |
gFill = colorOfFill.getGreen(); |
170 |
bFill = colorOfFill.getBlue(); |
171 |
aFill = colorOfFill.getAlpha(); |
172 |
|
173 |
} |
174 |
} |
175 |
|
176 |
int red = (rMarker + rLine + rFill) / 3; |
177 |
int green = (gMarker + gLine + gFill) / 3; |
178 |
int blue = (bMarker + bLine + bFill) / 3; |
179 |
int alpha = (aMarker + aLine + aFill) / 3; |
180 |
|
181 |
return (alpha) << 24 + (red << 16) + (green << 8) + blue; |
182 |
} |
183 |
|
184 |
public XMLEntity getXMLEntity() {
|
185 |
XMLEntity xml = new XMLEntity();
|
186 |
xml.putProperty("className", getClassName());
|
187 |
xml.putProperty("desc", getDescription());
|
188 |
xml.putProperty("unit", getUnit());
|
189 |
|
190 |
if (marker!=null) { |
191 |
XMLEntity markerXML = marker.getXMLEntity(); |
192 |
markerXML.putProperty("id", "marker"); |
193 |
xml.addChild(markerXML); |
194 |
} |
195 |
|
196 |
if (line!=null) { |
197 |
XMLEntity lineXML = line.getXMLEntity(); |
198 |
lineXML.putProperty("id", "line"); |
199 |
xml.addChild(lineXML); |
200 |
} |
201 |
|
202 |
if (fill!=null) { |
203 |
XMLEntity fillXML = fill.getXMLEntity(); |
204 |
fillXML.putProperty("id", "fill"); |
205 |
xml.addChild(fillXML); |
206 |
|
207 |
|
208 |
} |
209 |
return xml;
|
210 |
} |
211 |
|
212 |
public void setXMLEntity(XMLEntity xml) { |
213 |
setDescription(xml.getStringProperty("desc"));
|
214 |
setUnit(xml.getIntProperty("unit"));
|
215 |
|
216 |
XMLEntity myXML; |
217 |
myXML = xml.firstChild("id", "marker"); |
218 |
if (myXML != null) |
219 |
marker = (IMarkerSymbol) SymbologyFactory. |
220 |
createSymbolFromXML(myXML, null);
|
221 |
|
222 |
myXML = xml.firstChild("id", "line"); |
223 |
if (myXML != null) |
224 |
line = (ILineSymbol) SymbologyFactory. |
225 |
createSymbolFromXML(myXML, null);
|
226 |
|
227 |
myXML = xml.firstChild("id", "fill"); |
228 |
if (myXML != null) |
229 |
fill = (IFillSymbol) SymbologyFactory. |
230 |
createSymbolFromXML(myXML, null);
|
231 |
|
232 |
|
233 |
} |
234 |
|
235 |
public String getDescription() { |
236 |
return desc;
|
237 |
} |
238 |
|
239 |
public boolean isShapeVisible() { |
240 |
if (marker!=null) { |
241 |
return marker.isShapeVisible();
|
242 |
} |
243 |
|
244 |
if (line != null) |
245 |
return line.isShapeVisible();
|
246 |
|
247 |
if (fill != null) |
248 |
fill.isShapeVisible(); |
249 |
|
250 |
return false; |
251 |
} |
252 |
|
253 |
public void setDescription(String desc) { |
254 |
this.desc = desc ;
|
255 |
} |
256 |
|
257 |
public int getSymbolType() { |
258 |
return Geometry.TYPES.AGGREGATE;
|
259 |
} |
260 |
|
261 |
public boolean isSuitableFor(Geometry geom) { |
262 |
// suitable for everything (why else does it exist?)
|
263 |
return true; |
264 |
} |
265 |
|
266 |
public void drawInsideRectangle(Graphics2D g, |
267 |
AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException { |
268 |
double myWidth = (r.getWidth()/3); |
269 |
|
270 |
Rectangle rect = new Rectangle(0, r.y, (int) myWidth, r.height); |
271 |
|
272 |
if (marker != null) { |
273 |
g.translate(r.x, r.y); |
274 |
marker.drawInsideRectangle(g, scaleInstance, rect); |
275 |
g.translate(-(r.x), -(r.y)); |
276 |
} |
277 |
|
278 |
if (line != null) { |
279 |
g.translate(r.x+myWidth, r.y); |
280 |
line.drawInsideRectangle(g, scaleInstance, rect); |
281 |
g.translate(-(r.x+myWidth), -(r.y)); |
282 |
} |
283 |
|
284 |
if (fill != null) { |
285 |
g.translate(r.x+myWidth+myWidth, r.y); |
286 |
fill.drawInsideRectangle(g, scaleInstance, rect); |
287 |
g.translate(-(r.x+myWidth+myWidth), -(r.y)); |
288 |
|
289 |
} |
290 |
} |
291 |
|
292 |
public String getClassName() { |
293 |
return getClass().getName();
|
294 |
} |
295 |
|
296 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet properties) |
297 |
throws ReadException {
|
298 |
switch (geom.getType()) {
|
299 |
case Geometry.TYPES.POINT: //Tipo punto |
300 |
case Geometry.TYPES.POINT + Geometry.TYPES.Z:
|
301 |
if (marker != null) |
302 |
marker.print(g, at, geom, properties); |
303 |
break;
|
304 |
case Geometry.TYPES.CURVE:
|
305 |
case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
|
306 |
case Geometry.TYPES.ARC:
|
307 |
case Geometry.TYPES.ARC + Geometry.TYPES.Z:
|
308 |
if (line != null) |
309 |
line.print(g, at, geom, properties); |
310 |
break;
|
311 |
|
312 |
case Geometry.TYPES.SURFACE:
|
313 |
case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
|
314 |
case Geometry.TYPES.ELLIPSE:
|
315 |
case Geometry.TYPES.ELLIPSE + Geometry.TYPES.Z:
|
316 |
case Geometry.TYPES.CIRCLE:
|
317 |
case Geometry.TYPES.CIRCLE + Geometry.TYPES.Z:
|
318 |
if (fill != null) |
319 |
fill.print(g, at, geom, properties); |
320 |
break;
|
321 |
} |
322 |
} |
323 |
|
324 |
public double getRotation() { |
325 |
if (marker != null) |
326 |
return marker.getRotation();
|
327 |
return 0; |
328 |
} |
329 |
|
330 |
public void setRotation(double rotation) { |
331 |
if (marker != null) |
332 |
marker.setRotation(rotation); |
333 |
} |
334 |
|
335 |
public Point2D getOffset() { |
336 |
if (marker != null) |
337 |
return marker.getOffset();
|
338 |
return new Point2D.Double(); |
339 |
} |
340 |
|
341 |
public void setOffset(Point2D offset) { |
342 |
if (marker != null) |
343 |
marker.setOffset(offset); |
344 |
} |
345 |
|
346 |
public double getSize() { |
347 |
if (marker != null) |
348 |
return marker.getSize();
|
349 |
return 0; |
350 |
} |
351 |
|
352 |
public void setSize(double size) { |
353 |
if (marker != null) |
354 |
marker.setSize(size); |
355 |
|
356 |
} |
357 |
|
358 |
public Color getColor() { |
359 |
if (marker != null) |
360 |
return marker.getColor();
|
361 |
return null; |
362 |
} |
363 |
|
364 |
public void setColor(Color color) { |
365 |
if (marker != null) |
366 |
marker.setColor(color); |
367 |
} |
368 |
|
369 |
public void setFillColor(Color color) { |
370 |
if (fill != null) |
371 |
fill.setFillColor(color); |
372 |
} |
373 |
|
374 |
public void setOutline(ILineSymbol outline) { |
375 |
if (fill != null) |
376 |
fill.setOutline(outline); |
377 |
} |
378 |
|
379 |
public Color getFillColor() { |
380 |
if (fill != null) |
381 |
return fill.getFillColor();
|
382 |
return null; |
383 |
} |
384 |
|
385 |
public ILineSymbol getOutline() {
|
386 |
if (fill != null) |
387 |
return fill.getOutline();
|
388 |
return null; |
389 |
} |
390 |
|
391 |
public int getFillAlpha() { |
392 |
if (fill != null) |
393 |
return fill.getFillAlpha();
|
394 |
return 255; |
395 |
} |
396 |
|
397 |
public IMask getMask() {
|
398 |
return mask;
|
399 |
} |
400 |
|
401 |
public void setUnit(int unitIndex) { |
402 |
if (marker != null) |
403 |
marker.setUnit(unitIndex); |
404 |
if (line != null) |
405 |
line.setUnit(unitIndex); |
406 |
} |
407 |
|
408 |
public int getUnit() { |
409 |
if (marker != null) |
410 |
return marker.getUnit();
|
411 |
if (line != null) |
412 |
return line.getUnit();
|
413 |
return -1; |
414 |
} |
415 |
|
416 |
public void setMask(IMask mask) { |
417 |
// TODO Implement it
|
418 |
throw new Error("Not yet implemented!"); |
419 |
|
420 |
} |
421 |
|
422 |
public int getReferenceSystem() { |
423 |
return this.referenceSystem; |
424 |
} |
425 |
|
426 |
public void setReferenceSystem(int system) { |
427 |
this.referenceSystem = system;
|
428 |
|
429 |
} |
430 |
|
431 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
432 |
switch (geom.getType()) {
|
433 |
case Geometry.TYPES.POINT: //Tipo punto |
434 |
case Geometry.TYPES.POINT + Geometry.TYPES.Z:
|
435 |
if (marker != null) |
436 |
return marker.toCartographicSize(viewPort, dpi, geom);
|
437 |
case Geometry.TYPES.CURVE:
|
438 |
case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
|
439 |
case Geometry.TYPES.ARC:
|
440 |
case Geometry.TYPES.ARC + Geometry.TYPES.Z:
|
441 |
if (line != null) |
442 |
return line.toCartographicSize(viewPort, dpi, geom);
|
443 |
case Geometry.TYPES.SURFACE:
|
444 |
case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
|
445 |
case Geometry.TYPES.ELLIPSE:
|
446 |
case Geometry.TYPES.ELLIPSE + Geometry.TYPES.Z:
|
447 |
case Geometry.TYPES.CIRCLE:
|
448 |
case Geometry.TYPES.CIRCLE + Geometry.TYPES.Z:
|
449 |
Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols"); |
450 |
|
451 |
} |
452 |
return -1; |
453 |
} |
454 |
|
455 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
456 |
switch (geom.getType()) {
|
457 |
case Geometry.TYPES.POINT: //Tipo punto |
458 |
case Geometry.TYPES.POINT + Geometry.TYPES.Z:
|
459 |
if (marker != null) |
460 |
marker.setCartographicSize(cartographicSize, null);
|
461 |
break;
|
462 |
case Geometry.TYPES.CURVE:
|
463 |
case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
|
464 |
case Geometry.TYPES.ARC:
|
465 |
case Geometry.TYPES.ARC + Geometry.TYPES.Z:
|
466 |
if (line != null) |
467 |
line.setCartographicSize(cartographicSize, null);
|
468 |
break;
|
469 |
case Geometry.TYPES.SURFACE:
|
470 |
case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
|
471 |
case Geometry.TYPES.ELLIPSE:
|
472 |
case Geometry.TYPES.ELLIPSE + Geometry.TYPES.Z:
|
473 |
case Geometry.TYPES.CIRCLE:
|
474 |
case Geometry.TYPES.CIRCLE + Geometry.TYPES.Z:
|
475 |
Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols"); |
476 |
} |
477 |
} |
478 |
|
479 |
|
480 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
481 |
switch (geom.getType()) {
|
482 |
case Geometry.TYPES.POINT: //Tipo punto |
483 |
case Geometry.TYPES.POINT + Geometry.TYPES.Z:
|
484 |
return CartographicSupportToolkit.
|
485 |
getCartographicLength(marker, |
486 |
getSize(), |
487 |
viewPort, |
488 |
dpi); |
489 |
case Geometry.TYPES.CURVE:
|
490 |
case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
|
491 |
case Geometry.TYPES.ARC:
|
492 |
case Geometry.TYPES.ARC + Geometry.TYPES.Z:
|
493 |
return CartographicSupportToolkit.
|
494 |
getCartographicLength(line, |
495 |
getSize(), |
496 |
viewPort, |
497 |
dpi); |
498 |
case Geometry.TYPES.SURFACE:
|
499 |
case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
|
500 |
case Geometry.TYPES.ELLIPSE:
|
501 |
case Geometry.TYPES.ELLIPSE + Geometry.TYPES.Z:
|
502 |
case Geometry.TYPES.CIRCLE:
|
503 |
case Geometry.TYPES.CIRCLE + Geometry.TYPES.Z:
|
504 |
Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols"); |
505 |
} |
506 |
return -1; |
507 |
} |
508 |
|
509 |
public IMarkerSymbol getMarkerSymbol() {
|
510 |
return marker;
|
511 |
} |
512 |
|
513 |
public ILineSymbol getLineSymbol() {
|
514 |
return line;
|
515 |
} |
516 |
|
517 |
public IFillSymbol getFillSymbol() {
|
518 |
return fill;
|
519 |
} |
520 |
|
521 |
public void setMarkerSymbol(IMarkerSymbol markerSymbol) { |
522 |
this.marker = markerSymbol;
|
523 |
} |
524 |
|
525 |
public void setLineSymbol(ILineSymbol lineSymbol) { |
526 |
this.line = lineSymbol;
|
527 |
} |
528 |
|
529 |
public void setFillSymbol(IFillSymbol fillFillSymbol) { |
530 |
this.fill = fillFillSymbol;
|
531 |
} |
532 |
|
533 |
public boolean hasFill() { |
534 |
if (fill == null) return false; |
535 |
return fill.hasFill();
|
536 |
} |
537 |
|
538 |
public void setHasFill(boolean hasFill) { |
539 |
if (fill != null) { |
540 |
fill.setHasFill(hasFill); |
541 |
// this.hasFill = hasFill;
|
542 |
} |
543 |
} |
544 |
|
545 |
public boolean hasOutline() { |
546 |
// TODO Auto-generated method stub
|
547 |
return false; |
548 |
} |
549 |
|
550 |
public void setHasOutline(boolean hasOutline) { |
551 |
// TODO Auto-generated method stub
|
552 |
|
553 |
} |
554 |
|
555 |
} |