Revision 30102 branches/v2_0_0_prep/extensions/org.gvsig.symbology/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/AbstractVectorialLegend.java
AbstractVectorialLegend.java | ||
---|---|---|
27 | 27 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
28 | 28 |
|
29 | 29 |
import java.awt.Graphics2D; |
30 |
import java.awt.geom.AffineTransform; |
|
31 |
import java.awt.geom.PathIterator; |
|
30 | 32 |
import java.awt.geom.Point2D; |
31 | 33 |
import java.awt.image.BufferedImage; |
32 | 34 |
import java.util.Iterator; |
... | ... | |
47 | 49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
48 | 50 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
49 | 51 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.operation.DrawInts; |
|
51 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
|
52 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
53 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
52 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
53 |
import org.gvsig.fmap.geom.GeometryManager; |
|
54 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
55 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
56 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
54 | 57 |
import org.gvsig.fmap.geom.primitive.Envelope; |
58 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
55 | 59 |
import org.gvsig.fmap.mapcontext.MapContext; |
56 | 60 |
import org.gvsig.fmap.mapcontext.ViewPort; |
57 | 61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsEnvelopeEvaluator; |
... | ... | |
68 | 72 |
*/ |
69 | 73 |
public abstract class AbstractVectorialLegend extends AbstractLegend { |
70 | 74 |
|
75 |
private static final GeometryManager geomManager = GeometryLocator |
|
76 |
.getGeometryManager(); |
|
77 |
|
|
71 | 78 |
protected ZSort zSort; |
72 | 79 |
|
73 | 80 |
public ZSort getZSort() { |
... | ... | |
131 | 138 |
containsAll = viewPortEnvelope.contains(myEnvelope); |
132 | 139 |
|
133 | 140 |
// Create the context for the DRAW Geometry operation |
134 |
DrawOperationContext doc = new DrawOperationContext(); |
|
141 |
// DrawOperationContext doc = new DrawOperationContext();
|
|
135 | 142 |
// FIXME Why double??? |
136 | 143 |
double dpi = MapContext.getScreenDPI(); |
137 |
doc.setViewPort(viewPort); |
|
138 |
doc.setScale(scale); |
|
139 |
doc.setCancellable(cancel); |
|
140 |
doc.setDPI(dpi); |
|
144 |
// doc.setViewPort(viewPort);
|
|
145 |
// doc.setScale(scale);
|
|
146 |
// doc.setCancellable(cancel);
|
|
147 |
// doc.setDPI(dpi);
|
|
141 | 148 |
|
142 | 149 |
// Create the drawing notification to be reused on each iteration |
143 | 150 |
DefaultFeatureDrawnNotification drawnNotification = new DefaultFeatureDrawnNotification(); |
... | ... | |
288 | 295 |
// FIXME: this need to check the symbol size too |
289 | 296 |
boolean onePoint = sym.isOneDotOrPixel(geom, xyCoordsDbl, |
290 | 297 |
viewPort, (int) dpi); |
291 |
|
|
298 |
|
|
292 | 299 |
// Avoid out of bounds exceptions because is out of |
293 | 300 |
// graphics extension |
294 | 301 |
if (onePoint) { |
... | ... | |
350 | 357 |
imageLevels[symbolLevel].setRGB(x, y, mySym |
351 | 358 |
.getOnePointRgb()); |
352 | 359 |
} else { |
353 |
if (!bDrawCartographicSupport) { |
|
354 |
doc.setGraphics(graphics[symbolLevel]); |
|
355 |
doc.setSymbol(mySym); |
|
356 |
geom |
|
357 |
.invokeOperation(DrawInts.CODE, |
|
358 |
doc); |
|
359 |
} else { |
|
360 |
doc.setGraphics(graphics[symbolLevel]); |
|
361 |
doc.setSymbol(mySym); |
|
362 |
geom |
|
363 |
.invokeOperation(DrawInts.CODE, |
|
364 |
doc); |
|
365 |
} |
|
360 |
drawGeometry(geom, mySym, viewPort, |
|
361 |
graphics[symbolLevel], dpi, |
|
362 |
cancel); |
|
363 |
// if (!bDrawCartographicSupport) { |
|
364 |
// doc.setGraphics(graphics[symbolLevel]); |
|
365 |
// doc.setSymbol(mySym); |
|
366 |
// geom |
|
367 |
// .invokeOperation(DrawInts.CODE, |
|
368 |
// doc); |
|
369 |
// } else { |
|
370 |
// doc.setGraphics(graphics[symbolLevel]); |
|
371 |
// doc.setSymbol(mySym); |
|
372 |
// geom |
|
373 |
// .invokeOperation(DrawInts.CODE, |
|
374 |
// doc); |
|
375 |
// } |
|
366 | 376 |
} |
367 | 377 |
} |
368 | 378 |
} else { |
... | ... | |
372 | 382 |
symbolLevel = symLevels[0]; |
373 | 383 |
} |
374 | 384 |
if (!bDrawCartographicSupport) { |
375 |
doc.setGraphics(graphics[symbolLevel]); |
|
376 |
doc.setSymbol(sym); |
|
377 |
geom.invokeOperation(DrawInts.CODE, doc); |
|
385 |
drawGeometry(geom, sym, viewPort, |
|
386 |
graphics[symbolLevel], dpi, cancel); |
|
387 |
// doc.setGraphics(graphics[symbolLevel]); |
|
388 |
// doc.setSymbol(sym); |
|
389 |
// geom.invokeOperation(DrawInts.CODE, doc); |
|
378 | 390 |
} else { |
379 |
doc.setGraphics(graphics[symbolLevel]); |
|
380 |
doc.setSymbol((ISymbol) csSym); |
|
381 |
geom.invokeOperation(DrawInts.CODE, doc); |
|
391 |
drawGeometry(geom, (ISymbol) csSym, viewPort, |
|
392 |
graphics[symbolLevel], dpi, cancel); |
|
393 |
// doc.setGraphics(graphics[symbolLevel]); |
|
394 |
// doc.setSymbol((ISymbol) csSym); |
|
395 |
// geom.invokeOperation(DrawInts.CODE, doc); |
|
382 | 396 |
} |
383 | 397 |
} |
384 | 398 |
|
... | ... | |
424 | 438 |
} else { |
425 | 439 |
|
426 | 440 |
if (!bDrawCartographicSupport) { |
427 |
doc.setGraphics(g); |
|
428 |
doc.setSymbol(sym); |
|
429 |
geom.invokeOperation(DrawInts.CODE, doc); |
|
441 |
drawGeometry(geom, sym, viewPort, g, dpi, |
|
442 |
cancel); |
|
443 |
// doc.setGraphics(g); |
|
444 |
// doc.setSymbol(sym); |
|
445 |
// geom.invokeOperation(DrawInts.CODE, doc); |
|
430 | 446 |
} else { |
431 |
doc.setGraphics(g); |
|
432 |
doc.setSymbol((ISymbol) csSym); |
|
433 |
geom.invokeOperation(DrawInts.CODE, doc); |
|
447 |
drawGeometry(geom, (ISymbol) csSym, viewPort, |
|
448 |
g, dpi, cancel); |
|
449 |
// doc.setGraphics(g); |
|
450 |
// doc.setSymbol((ISymbol) csSym); |
|
451 |
// geom.invokeOperation(DrawInts.CODE, doc); |
|
434 | 452 |
} |
435 | 453 |
} |
436 | 454 |
} |
... | ... | |
468 | 486 |
|
469 | 487 |
} catch (ReadException e) { |
470 | 488 |
throw new LegendDrawingException(e); |
471 |
} catch (GeometryOperationNotSupportedException e) { |
|
489 |
// } catch (GeometryOperationNotSupportedException e) { |
|
490 |
// throw new LegendDrawingException(e); |
|
491 |
} catch (CreateGeometryException e) { |
|
472 | 492 |
throw new LegendDrawingException(e); |
473 |
} catch (GeometryOperationException e) { |
|
474 |
throw new LegendDrawingException(e); |
|
475 | 493 |
} catch (BaseException e) { |
476 | 494 |
throw new LegendDrawingException(e); |
477 | 495 |
} |
... | ... | |
486 | 504 |
// TODO Auto-generated method stub |
487 | 505 |
|
488 | 506 |
} |
507 |
|
|
508 |
private void drawGeometry(Geometry geom, ISymbol symbol, ViewPort viewPort, |
|
509 |
Graphics2D graphics, double dpi, Cancellable cancellable) |
|
510 |
throws CreateGeometryException { |
|
489 | 511 |
|
512 |
if (geom instanceof Aggregate) { |
|
513 |
Aggregate aggregate = (Aggregate) geom; |
|
514 |
for (int i = 0; i < aggregate.getPrimitivesNumber(); i++) { |
|
515 |
Geometry prim = aggregate.getPrimitiveAt(i); |
|
516 |
drawGeometry(prim, symbol, viewPort, graphics, dpi, cancellable); |
|
517 |
} |
|
518 |
} else { |
|
490 | 519 |
|
520 |
// make the symbol to resize itself with the current rendering |
|
521 |
// context |
|
522 |
double previousSize = ((CartographicSupport) symbol) |
|
523 |
.toCartographicSize(viewPort, dpi, geom); |
|
524 |
// draw it as normally |
|
525 |
Geometry decimatedShape = transformToInts(geom, viewPort |
|
526 |
.getAffineTransform()); |
|
527 |
symbol.draw(graphics, viewPort.getAffineTransform(), |
|
528 |
decimatedShape, cancellable); |
|
529 |
|
|
530 |
// restore previous size |
|
531 |
((CartographicSupport) symbol).setCartographicSize(previousSize, |
|
532 |
geom); |
|
533 |
} |
|
534 |
} |
|
535 |
|
|
536 |
private Geometry transformToInts(Geometry gp, AffineTransform at) |
|
537 |
throws CreateGeometryException { |
|
538 |
GeneralPathX newGp = new GeneralPathX(); |
|
539 |
double[] theData = new double[6]; |
|
540 |
double[] aux = new double[6]; |
|
541 |
|
|
542 |
// newGp.reset(); |
|
543 |
PathIterator theIterator; |
|
544 |
int theType; |
|
545 |
int numParts = 0; |
|
546 |
|
|
547 |
java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double(); |
|
548 |
java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double(); |
|
549 |
boolean bFirst = true; |
|
550 |
int xInt, yInt, antX = -1, antY = -1; |
|
551 |
|
|
552 |
theIterator = gp.getPathIterator(null); // , flatness); |
|
553 |
int numSegmentsAdded = 0; |
|
554 |
while (!theIterator.isDone()) { |
|
555 |
theType = theIterator.currentSegment(theData); |
|
556 |
|
|
557 |
switch (theType) { |
|
558 |
case PathIterator.SEG_MOVETO: |
|
559 |
numParts++; |
|
560 |
ptSrc.setLocation(theData[0], theData[1]); |
|
561 |
at.transform(ptSrc, ptDst); |
|
562 |
antX = (int) ptDst.getX(); |
|
563 |
antY = (int) ptDst.getY(); |
|
564 |
newGp.moveTo(antX, antY); |
|
565 |
numSegmentsAdded++; |
|
566 |
bFirst = true; |
|
567 |
break; |
|
568 |
|
|
569 |
case PathIterator.SEG_LINETO: |
|
570 |
ptSrc.setLocation(theData[0], theData[1]); |
|
571 |
at.transform(ptSrc, ptDst); |
|
572 |
xInt = (int) ptDst.getX(); |
|
573 |
yInt = (int) ptDst.getY(); |
|
574 |
if ((bFirst) || ((xInt != antX) || (yInt != antY))) { |
|
575 |
newGp.lineTo(xInt, yInt); |
|
576 |
antX = xInt; |
|
577 |
antY = yInt; |
|
578 |
bFirst = false; |
|
579 |
numSegmentsAdded++; |
|
580 |
} |
|
581 |
break; |
|
582 |
|
|
583 |
case PathIterator.SEG_QUADTO: |
|
584 |
at.transform(theData, 0, aux, 0, 2); |
|
585 |
newGp.quadTo(aux[0], aux[1], aux[2], aux[3]); |
|
586 |
numSegmentsAdded++; |
|
587 |
break; |
|
588 |
|
|
589 |
case PathIterator.SEG_CUBICTO: |
|
590 |
at.transform(theData, 0, aux, 0, 3); |
|
591 |
newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]); |
|
592 |
numSegmentsAdded++; |
|
593 |
break; |
|
594 |
|
|
595 |
case PathIterator.SEG_CLOSE: |
|
596 |
if (numSegmentsAdded < 3) { |
|
597 |
newGp.lineTo(antX, antY); |
|
598 |
} |
|
599 |
newGp.closePath(); |
|
600 |
|
|
601 |
break; |
|
602 |
} // end switch |
|
603 |
|
|
604 |
theIterator.next(); |
|
605 |
} // end while loop |
|
606 |
|
|
607 |
Geometry geom = null; |
|
608 |
switch (gp.getType()) { |
|
609 |
case Geometry.TYPES.POINT: |
|
610 |
geom = geomManager.createPoint(ptDst.getX(), ptDst.getY(), |
|
611 |
SUBTYPES.GEOM2D); |
|
612 |
break; |
|
613 |
case Geometry.TYPES.CURVE: |
|
614 |
case Geometry.TYPES.ARC: |
|
615 |
geom = geomManager.createCurve(newGp, SUBTYPES.GEOM2D); |
|
616 |
break; |
|
617 |
|
|
618 |
case Geometry.TYPES.SURFACE: |
|
619 |
case Geometry.TYPES.CIRCLE: |
|
620 |
case Geometry.TYPES.ELLIPSE: |
|
621 |
|
|
622 |
geom = geomManager.createSurface(newGp, SUBTYPES.GEOM2D); |
|
623 |
break; |
|
624 |
} |
|
625 |
return geom; |
|
626 |
} |
|
627 |
|
|
491 | 628 |
protected abstract String[] getRequiredFeatureAttributeNames( |
492 | 629 |
FeatureStore featureStore) throws DataException; |
493 | 630 |
} |
Also available in: Unified diff