Revision 11588 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/operation/strategies/Annotation_Strategy.java
Annotation_Strategy.java | ||
---|---|---|
4 | 4 |
import java.awt.Font; |
5 | 5 |
import java.awt.FontMetrics; |
6 | 6 |
import java.awt.Graphics2D; |
7 |
import java.awt.Shape; |
|
8 |
import java.awt.font.FontRenderContext; |
|
9 |
import java.awt.font.GlyphVector; |
|
10 |
import java.awt.geom.AffineTransform; |
|
11 | 7 |
import java.awt.geom.Point2D; |
12 | 8 |
import java.awt.geom.Rectangle2D; |
13 | 9 |
import java.awt.image.BufferedImage; |
14 | 10 |
import java.util.List; |
15 |
import java.util.logging.Level; |
|
16 |
import java.util.logging.Logger; |
|
17 | 11 |
|
18 | 12 |
import org.cresques.cts.ICoordTrans; |
19 | 13 |
|
... | ... | |
26 | 20 |
import com.iver.cit.gvsig.fmap.ViewPort; |
27 | 21 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
28 | 22 |
import com.iver.cit.gvsig.fmap.core.FShape; |
29 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
30 | 23 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
31 | 24 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
32 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
33 | 25 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
34 | 26 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
35 | 27 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
... | ... | |
43 | 35 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
44 | 36 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
45 | 37 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
46 |
import com.iver.cit.gvsig.fmap.layers.SpatialCache; |
|
47 | 38 |
import com.iver.cit.gvsig.fmap.operations.strategies.DefaultStrategy; |
48 | 39 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
49 | 40 |
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend; |
50 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
|
51 | 41 |
import com.iver.utiles.swing.threads.Cancellable; |
52 | 42 |
import com.vividsolutions.jts.geom.Geometry; |
53 | 43 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
... | ... | |
61 | 51 |
*/ |
62 | 52 |
public class Annotation_Strategy extends DefaultStrategy { |
63 | 53 |
private FSymbol symbolPoint=new FSymbol(FShape.POINT,Color.black); |
64 |
private Graphics2D graphics=null; |
|
65 |
private ViewPort viewPort=null; |
|
66 |
private double heightDefault=-1; |
|
67 | 54 |
private Annotation_Layer capa; |
68 | 55 |
/** |
69 | 56 |
* Crea un nuevo AnotationStrategy. |
... | ... | |
240 | 227 |
FBitSet bitSet=recordSet.getSelection(); |
241 | 228 |
FontMetrics metrics = g.getFontMetrics(); |
242 | 229 |
Annotation_Mapping mapping = ((Annotation_Layer) capa) |
243 |
.getMapping(); |
|
230 |
.getAnnotatonMapping();
|
|
244 | 231 |
int idHeightField = mapping.getColumnHeight(); |
245 | 232 |
int idFontName = mapping.getColumnTypeFont(); |
246 | 233 |
int idFontStyle = mapping.getColumnStyleFont(); |
... | ... | |
331 | 318 |
aux[0].setHeight(size); |
332 | 319 |
aux[0].setRotation((int) rotation); |
333 | 320 |
aux[0].setString(vv[idTextField].toString()); |
334 |
symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
|
321 |
if (sym.isShapeVisible()){ |
|
322 |
symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
|
323 |
} |
|
335 | 324 |
FGraphicUtilities.DrawAnnotation(g, viewPort |
336 | 325 |
.getAffineTransform(), sym, aux[0], metrics, false); |
337 | 326 |
} |
... | ... | |
438 | 427 |
// heightDefault=-1; |
439 | 428 |
} |
440 | 429 |
|
441 |
public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics, |
|
442 |
Point2D p, String s) { |
|
443 |
int w = metrics.stringWidth(s); |
|
444 |
double width = viewPort.toMapDistance(w); |
|
445 |
if (heightDefault == -1) { |
|
446 |
int h = metrics.getMaxAscent(); |
|
447 |
heightDefault = viewPort.toMapDistance(h); |
|
448 |
} |
|
449 |
return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault); |
|
430 |
// public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics, |
|
431 |
// Point2D p, String s) { |
|
432 |
// int w = metrics.stringWidth(s); |
|
433 |
// double width = viewPort.toMapDistance(w); |
|
434 |
// if (heightDefault == -1) { |
|
435 |
// int h = metrics.getMaxAscent(); |
|
436 |
// heightDefault = viewPort.toMapDistance(h); |
|
437 |
// } |
|
438 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault); |
|
439 |
// |
|
440 |
// } |
|
450 | 441 |
|
451 |
} |
|
452 |
|
|
453 | 442 |
/** |
454 | 443 |
* Construcci?n del rect?ngulo |
455 | 444 |
* |
... | ... | |
463 | 452 |
* |
464 | 453 |
* @return |
465 | 454 |
*/ |
466 |
public Rectangle2D getBoundBox(Point2D p, float hp, |
|
467 |
int justification,String s) { |
|
468 |
//Rectangle2D bounding=null; |
|
469 |
if (((Annotation_Layer)capa).isInPixels()){ |
|
470 |
graphics.setFont(graphics.getFont().deriveFont(hp)); |
|
471 |
}else{ |
|
472 |
float alturaPixels = (float) ((hp * viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR); |
|
473 |
graphics.setFont(graphics.getFont().deriveFont(alturaPixels)); |
|
474 |
} |
|
475 |
FontMetrics metrics = graphics.getFontMetrics(); |
|
476 |
int w = metrics.stringWidth(s); |
|
477 |
double width = viewPort.toMapDistance(w); |
|
478 |
int h = metrics.getMaxAscent(); |
|
479 |
double height = viewPort.toMapDistance(h); |
|
480 |
//double dist = viewPort.toMapDistance(3); |
|
481 |
return new Rectangle2D.Double(p.getX(), p.getY(), width, height); |
|
482 |
/* switch (justification) { |
|
483 |
case FLabel.LEFT_BOTTOM: |
|
484 |
bounding=justification(p, width,height, 0, 0); |
|
485 |
|
|
486 |
break; |
|
487 |
|
|
488 |
case FLabel.LEFT_CENTER: |
|
489 |
bounding=justification(p, width,height, 0, -(height / 2)); |
|
490 |
|
|
491 |
break; |
|
492 |
|
|
493 |
case FLabel.LEFT_TOP: |
|
494 |
bounding=justification(p,width,height, 0, -height); |
|
495 |
|
|
496 |
break; |
|
497 |
|
|
498 |
case FLabel.CENTER_BOTTOM: |
|
499 |
bounding=justification(p, width,height, -(width / 2), -dist); |
|
500 |
|
|
501 |
break; |
|
502 |
|
|
503 |
case FLabel.CENTER_CENTER: |
|
504 |
bounding=justification(p, width,height, -(width / 2), -(height / 2)); |
|
505 |
|
|
506 |
break; |
|
507 |
|
|
508 |
case FLabel.CENTER_TOP: |
|
509 |
bounding=justification(p, width,height, -(width / 2), -height); |
|
510 |
|
|
511 |
break; |
|
512 |
|
|
513 |
case FLabel.RIGHT_BOTTOM: |
|
514 |
bounding=justification(p, width,height, -width, -dist); |
|
515 |
|
|
516 |
break; |
|
517 |
|
|
518 |
case FLabel.RIGHT_CENTER: |
|
519 |
bounding=justification(p, width,height, -width, -(height / 2)); |
|
520 |
|
|
521 |
break; |
|
522 |
|
|
523 |
case FLabel.RIGHT_TOP: |
|
524 |
bounding=justification(p, width,height, -width, -height); |
|
525 |
|
|
526 |
break; |
|
527 |
} |
|
528 |
|
|
529 |
return bounding; |
|
530 |
*/ |
|
531 |
} |
|
455 |
// public Rectangle2D getBoundBox(Point2D p, float hp,
|
|
456 |
// int justification,String s) {
|
|
457 |
// //Rectangle2D bounding=null;
|
|
458 |
// if (((Annotation_Layer)capa).isInPixels()){
|
|
459 |
// graphics.setFont(graphics.getFont().deriveFont(hp));
|
|
460 |
// }else{
|
|
461 |
// float alturaPixels = (float) ((hp * viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR);
|
|
462 |
// graphics.setFont(graphics.getFont().deriveFont(alturaPixels));
|
|
463 |
// }
|
|
464 |
// FontMetrics metrics = graphics.getFontMetrics();
|
|
465 |
// int w = metrics.stringWidth(s);
|
|
466 |
// double width = viewPort.toMapDistance(w);
|
|
467 |
// int h = metrics.getMaxAscent();
|
|
468 |
// double height = viewPort.toMapDistance(h);
|
|
469 |
// //double dist = viewPort.toMapDistance(3);
|
|
470 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, height);
|
|
471 |
// /* switch (justification) {
|
|
472 |
// case FLabel.LEFT_BOTTOM:
|
|
473 |
// bounding=justification(p, width,height, 0, 0);
|
|
474 |
// |
|
475 |
// break;
|
|
476 |
// |
|
477 |
// case FLabel.LEFT_CENTER:
|
|
478 |
// bounding=justification(p, width,height, 0, -(height / 2));
|
|
479 |
// |
|
480 |
// break;
|
|
481 |
// |
|
482 |
// case FLabel.LEFT_TOP:
|
|
483 |
// bounding=justification(p,width,height, 0, -height);
|
|
484 |
// |
|
485 |
// break;
|
|
486 |
// |
|
487 |
// case FLabel.CENTER_BOTTOM:
|
|
488 |
// bounding=justification(p, width,height, -(width / 2), -dist);
|
|
489 |
// |
|
490 |
// break;
|
|
491 |
// |
|
492 |
// case FLabel.CENTER_CENTER:
|
|
493 |
// bounding=justification(p, width,height, -(width / 2), -(height / 2));
|
|
494 |
// |
|
495 |
// break;
|
|
496 |
// |
|
497 |
// case FLabel.CENTER_TOP:
|
|
498 |
// bounding=justification(p, width,height, -(width / 2), -height);
|
|
499 |
// |
|
500 |
// break;
|
|
501 |
// |
|
502 |
// case FLabel.RIGHT_BOTTOM:
|
|
503 |
// bounding=justification(p, width,height, -width, -dist);
|
|
504 |
// |
|
505 |
// break;
|
|
506 |
// |
|
507 |
// case FLabel.RIGHT_CENTER:
|
|
508 |
// bounding=justification(p, width,height, -width, -(height / 2));
|
|
509 |
// |
|
510 |
// break;
|
|
511 |
// |
|
512 |
// case FLabel.RIGHT_TOP:
|
|
513 |
// bounding=justification(p, width,height, -width, -height);
|
|
514 |
// |
|
515 |
// break;
|
|
516 |
// }
|
|
517 |
// |
|
518 |
// return bounding;
|
|
519 |
// */
|
|
520 |
// }
|
|
532 | 521 |
/* private Rectangle2D justification(Point2D p, double w,double h, double x, double y) { |
533 | 522 |
Rectangle2D r=new Rectangle2D.Double(p.getX() + x, p.getY() - y, w, h); |
534 | 523 |
return r; |
... | ... | |
686 | 675 |
index = idRec.intValue(); |
687 | 676 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(index); |
688 | 677 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index); |
689 |
Annotation_Mapping mapping=((Annotation_Layer)capa).getMapping(); |
|
678 |
Annotation_Mapping mapping=((Annotation_Layer)capa).getAnnotatonMapping();
|
|
690 | 679 |
NumericValue vRotation = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnRotate()); |
691 | 680 |
NumericValue vHeight = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnHeight()); |
692 | 681 |
Value vText = va.getRecordset().getFieldValue(index,mapping.getColumnText()); |
... | ... | |
733 | 722 |
p.getY() - (tolerance / 2), tolerance, tolerance); |
734 | 723 |
return queryByRect(recPoint); |
735 | 724 |
} |
736 |
private IGeometry getGeometry(Rectangle2D r){ |
|
737 |
GeneralPathX resul = new GeneralPathX(); |
|
738 |
Point2D[] vs=new Point2D[4]; |
|
739 |
vs[0]=new Point2D.Double(r.getX(),r.getY()); |
|
740 |
vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
|
741 |
vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
742 |
vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
|
743 |
//vs[4]=new Point2D.Double(r.getX(),r.getY()); |
|
744 |
for (int i = 0; i < vs.length; i++) { |
|
745 |
if (i == 0) { |
|
746 |
resul.moveTo(vs[i].getX(),vs[i].getY()); |
|
747 |
} else { |
|
748 |
resul.lineTo(vs[i].getX(),vs[i].getY()); |
|
749 |
} |
|
750 |
} |
|
751 |
resul.closePath(); |
|
752 |
return ShapeFactory.createPolygon2D(resul); |
|
753 |
} |
|
754 |
// public IGeometry getTextWrappingGeometry(FSymbol symbol,String description,double rotation,int numReg) throws DriverIOException { |
|
755 |
// ReadableVectorial adapter = capa.getSource(); |
|
756 |
//// adapter.start(); |
|
757 |
// ICoordTrans ct = capa.getCoordTrans(); |
|
758 |
// IGeometry geom = adapter.getShape(numReg); |
|
759 |
// boolean bMustClone = false; |
|
760 |
// if (geom == null) { |
|
761 |
// return null; |
|
725 |
// private IGeometry getGeometry(Rectangle2D r){ |
|
726 |
// GeneralPathX resul = new GeneralPathX(); |
|
727 |
// Point2D[] vs=new Point2D[4]; |
|
728 |
// vs[0]=new Point2D.Double(r.getX(),r.getY()); |
|
729 |
// vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
|
730 |
// vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
731 |
// vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
|
732 |
// //vs[4]=new Point2D.Double(r.getX(),r.getY()); |
|
733 |
// for (int i = 0; i < vs.length; i++) { |
|
734 |
// if (i == 0) { |
|
735 |
// resul.moveTo(vs[i].getX(),vs[i].getY()); |
|
736 |
// } else { |
|
737 |
// resul.lineTo(vs[i].getX(),vs[i].getY()); |
|
738 |
// } |
|
762 | 739 |
// } |
763 |
// if (ct != null) { |
|
764 |
// if (bMustClone) |
|
765 |
// geom = geom.cloneGeometry(); |
|
766 |
// geom.reProject(ct); |
|
767 |
// } |
|
768 |
// FLabel[] lbls = geom.createLabels(0, true); |
|
769 |
// Point2D p=lbls[0].getOrig(); |
|
770 |
// // assuming FShape is a point with the starting position of the text |
|
771 |
// Font font = symbol.getFont(); |
|
772 |
// |
|
773 |
// FontRenderContext frc = new FontRenderContext(new AffineTransform(),false,false);//g.getFontRenderContext(); |
|
774 |
// |
|
775 |
// GlyphVector gv = font.createGlyphVector(frc, description); |
|
776 |
// |
|
777 |
// /*p.transform(affineTransform);*/ |
|
778 |
// Shape shape = gv.getOutline((float) p.getX(), (float) p.getY()); |
|
779 |
// IGeometry myFShape = ShapeFactory.createPolygon2D(new GeneralPathX(shape.getBounds2D())); |
|
780 |
// if (rotation != 0) { |
|
781 |
// myFShape.transform(AffineTransform.getRotateInstance(rotation, p.getX(), p.getY())); |
|
782 |
// } |
|
783 |
//// adapter.stop(); |
|
784 |
// return myFShape; |
|
785 |
// } |
|
786 |
|
|
740 |
// resul.closePath(); |
|
741 |
// return ShapeFactory.createPolygon2D(resul); |
|
742 |
// } |
|
787 | 743 |
} |
Also available in: Unified diff