svn-gvsig-desktop / tags / Root_CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfText.java @ 1933
History | View | Annotate | Download (3.56 KB)
1 | 2 | luisw | /*
|
---|---|---|---|
2 | * Created on 09-may-2004
|
||
3 | *
|
||
4 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
5 | */
|
||
6 | package org.cresques.px.dxf; |
||
7 | |||
8 | import java.awt.Font; |
||
9 | import java.awt.Graphics2D; |
||
10 | 112 | jmorell | import java.awt.geom.AffineTransform; |
11 | 2 | luisw | import java.awt.geom.Point2D; |
12 | |||
13 | 94 | luisw | import org.cresques.cts.ICoordTrans; |
14 | import org.cresques.cts.IProjection; |
||
15 | 91 | luisw | import org.cresques.geo.ViewPortData; |
16 | 2 | luisw | import org.cresques.px.Extent; |
17 | |||
18 | /**
|
||
19 | * Entidad TEXT de AutoCAD
|
||
20 | *
|
||
21 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
||
22 | */
|
||
23 | public class DxfText extends DxfEntity { |
||
24 | public final static int ALIGN_LEFT = 0; |
||
25 | public final static int ALIGN_CENTER = 1; |
||
26 | public final static int ALIGN_RIGHT = 2; |
||
27 | public final static int ALIGN_ALIGNED = 3; |
||
28 | public final static int ALIGN_MIDDLE = 4; |
||
29 | public final static int ALIGN_FIT = 5; |
||
30 | 96 | luisw | private String text = null; |
31 | 2 | luisw | Point2D [] pts; |
32 | 96 | luisw | private double rot = 0.0; |
33 | private double h = 1.0; |
||
34 | 2 | luisw | int align = ALIGN_LEFT;
|
35 | |||
36 | 94 | luisw | public DxfText(IProjection proj, DxfLayer layer, String txt) { |
37 | 2 | luisw | super(proj, layer);
|
38 | 83 | luisw | //System.out.println("Dxf: TEXT '"+txt+"'.");
|
39 | 2 | luisw | extent = new Extent();
|
40 | text = txt; |
||
41 | pts = new Point2D[2]; |
||
42 | } |
||
43 | |||
44 | public void setPt1(Point2D pt) { |
||
45 | pts[0] = pt;
|
||
46 | extent.add(pt); |
||
47 | } |
||
48 | 96 | luisw | public Point2D getPt1() { return pts[0]; } |
49 | 2 | luisw | public void setPt2(Point2D pt) { |
50 | pts[1] = pt;
|
||
51 | extent.add(pt); |
||
52 | } |
||
53 | 96 | luisw | public Point2D getPt2() { return pts[1]; } |
54 | public void setHeight(double h) { this.h = h; } |
||
55 | public void setRotation(double r) { rot = r; } |
||
56 | 112 | jmorell | public double getRotation() { return rot; } |
57 | 96 | luisw | public String getText() { return text; } |
58 | 2 | luisw | |
59 | 94 | luisw | public void reProject(ICoordTrans rp) { |
60 | 2 | luisw | Point2D [] savePts = pts; |
61 | |||
62 | pts = new Point2D[2]; |
||
63 | extent = new Extent();
|
||
64 | Point2D ptDest = null; |
||
65 | for (int i=0; i<savePts.length; i++) { |
||
66 | ptDest = rp.getPDest().createPoint(0.0,0.0); |
||
67 | if (savePts[i] == null) |
||
68 | ptDest = null;
|
||
69 | else {
|
||
70 | 95 | luisw | ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
71 | 2 | luisw | extent.add(ptDest); |
72 | } |
||
73 | pts[i] = ptDest; |
||
74 | } |
||
75 | 96 | luisw | // Reproyecto la altura del texto
|
76 | Point2D ptOrig = rp.getPOrig().createPoint(savePts[0].getX(),savePts[0].getY()+h); |
||
77 | ptDest = rp.getPDest().createPoint(0D, 0D); |
||
78 | ptDest = rp.convert(ptOrig, ptDest); |
||
79 | h = ptDest.getY()-pts[0].getY();
|
||
80 | 2 | luisw | setProjection(rp.getPDest()); |
81 | } |
||
82 | |||
83 | 91 | luisw | public void draw(Graphics2D g, ViewPortData vp) { |
84 | 2 | luisw | if (dxfColor == AcadColor.BYLAYER)
|
85 | g.setColor(layer.getColor()); |
||
86 | else
|
||
87 | g.setColor(AcadColor.getColor(dxfColor)); |
||
88 | 29 | luisw | Font fntSave = g.getFont(), fnt;
|
89 | 96 | luisw | Point2D ptT0 = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
90 | Point2D ptT1 = new Point2D.Double(pts[0].getX()+h, pts[0].getY()+h); |
||
91 | 25 | luisw | vp.mat.transform(ptT0, ptT0); |
92 | vp.mat.transform(ptT1, ptT1); |
||
93 | 29 | luisw | fnt = new Font(fntSave.getName(), fntSave.getStyle(), (int) (ptT1.getX()-ptT0.getX())); |
94 | 2 | luisw | g.setFont(fnt); |
95 | 25 | luisw | ptT0.setLocation(pts[0].getX(), pts[0].getY()); |
96 | vp.mat.transform(ptT0, ptT0); |
||
97 | 112 | jmorell | |
98 | 113 | jmorell | // Codigo para implementar rotacion de textos.
|
99 | // Falta depurar.
|
||
100 | /*System.out.println("040906: rot = " + rot);
|
||
101 | 112 | jmorell | //angle = pathLen.angleAtLength(midDistance);
|
102 | rot = Math.toRadians(rot);
|
||
103 | 113 | jmorell | if (rot < 0) rot = rot + 2.0*Math.PI;
|
104 | if ((rot > (Math.PI/2)) && (rot < (3 * Math.PI /2))) rot = rot - (Math.PI/2.0);
|
||
105 | rot = Math.toDegrees(rot);
|
||
106 | 112 | jmorell | //theLabel.setRotation(Math.toDegrees(angle));
|
107 | AffineTransform transfRot = AffineTransform.getRotateInstance(rot, ptT0.getX(), ptT0.getY());
|
||
108 | AffineTransform ant = g.getTransform();
|
||
109 | 113 | jmorell | g.setTransform(transfRot);*/
|
110 | 112 | jmorell | |
111 | 25 | luisw | g.drawString(text, (int) ptT0.getX(), (int)ptT0.getY()); |
112 | 29 | luisw | g.setFont(fntSave); |
113 | 112 | jmorell | |
114 | 113 | jmorell | //g.setTransform(ant);
|
115 | 2 | luisw | } |
116 | 13 | luisw | |
117 | /* (non-Javadoc)
|
||
118 | * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
|
||
119 | */
|
||
120 | 14 | luisw | public String toDxfString() { |
121 | 13 | luisw | // TODO Auto-generated method stub
|
122 | 14 | luisw | return ""; |
123 | 13 | luisw | } |
124 | 2 | luisw | } |