svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfText.java @ 83
History | View | Annotate | Download (2.35 KB)
1 |
/*
|
---|---|
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 |
import java.awt.geom.Point2D; |
11 |
|
12 |
import org.cresques.geo.Projection; |
13 |
import org.cresques.geo.ReProjection; |
14 |
import org.cresques.geo.ViewPort; |
15 |
import org.cresques.px.Extent; |
16 |
|
17 |
/**
|
18 |
* Entidad TEXT de AutoCAD
|
19 |
*
|
20 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
21 |
*/
|
22 |
public class DxfText extends DxfEntity { |
23 |
public final static int ALIGN_LEFT = 0; |
24 |
public final static int ALIGN_CENTER = 1; |
25 |
public final static int ALIGN_RIGHT = 2; |
26 |
public final static int ALIGN_ALIGNED = 3; |
27 |
public final static int ALIGN_MIDDLE = 4; |
28 |
public final static int ALIGN_FIT = 5; |
29 |
String text = null; |
30 |
Point2D [] pts; |
31 |
double rot = 0.0; |
32 |
double h = 1.0; |
33 |
int align = ALIGN_LEFT;
|
34 |
|
35 |
public DxfText(Projection proj, DxfLayer layer, String txt) { |
36 |
super(proj, layer);
|
37 |
//System.out.println("Dxf: TEXT '"+txt+"'.");
|
38 |
extent = new Extent();
|
39 |
text = txt; |
40 |
pts = new Point2D[2]; |
41 |
} |
42 |
|
43 |
public void setPt1(Point2D pt) { |
44 |
pts[0] = pt;
|
45 |
extent.add(pt); |
46 |
} |
47 |
public void setPt2(Point2D pt) { |
48 |
pts[1] = pt;
|
49 |
extent.add(pt); |
50 |
} |
51 |
|
52 |
public void reProject(ReProjection rp) { |
53 |
Point2D [] savePts = pts; |
54 |
|
55 |
pts = new Point2D[2]; |
56 |
extent = new Extent();
|
57 |
Point2D ptDest = null; |
58 |
for (int i=0; i<savePts.length; i++) { |
59 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
60 |
if (savePts[i] == null) |
61 |
ptDest = null;
|
62 |
else {
|
63 |
rp.convert((Point2D) savePts[i], ptDest);
|
64 |
extent.add(ptDest); |
65 |
} |
66 |
pts[i] = ptDest; |
67 |
} |
68 |
setProjection(rp.getPDest()); |
69 |
} |
70 |
|
71 |
public void draw(Graphics2D g, ViewPort vp) { |
72 |
if (dxfColor == AcadColor.BYLAYER)
|
73 |
g.setColor(layer.getColor()); |
74 |
else
|
75 |
g.setColor(AcadColor.getColor(dxfColor)); |
76 |
Font fntSave = g.getFont(), fnt;
|
77 |
Point2D ptT0 = new Point2D.Double(0, 0); |
78 |
Point2D ptT1 = new Point2D.Double(h, h); |
79 |
vp.mat.transform(ptT0, ptT0); |
80 |
vp.mat.transform(ptT1, ptT1); |
81 |
fnt = new Font(fntSave.getName(), fntSave.getStyle(), (int) (ptT1.getX()-ptT0.getX())); |
82 |
g.setFont(fnt); |
83 |
ptT0.setLocation(pts[0].getX(), pts[0].getY()); |
84 |
vp.mat.transform(ptT0, ptT0); |
85 |
g.drawString(text, (int) ptT0.getX(), (int)ptT0.getY()); |
86 |
g.setFont(fntSave); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
|
91 |
*/
|
92 |
public String toDxfString() { |
93 |
// TODO Auto-generated method stub
|
94 |
return ""; |
95 |
} |
96 |
} |