Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfText.java @ 2218

History | View | Annotate | Download (3.94 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.AffineTransform;
11
import java.awt.geom.Point2D;
12

    
13
import org.cresques.cts.ICoordTrans;
14
import org.cresques.cts.IProjection;
15
import org.cresques.geo.ViewPortData;
16
import org.cresques.px.Extent;
17

    
18
/**
19
 * Entidad TEXT de AutoCAD
20
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
21
 * 
22
 * jmorell, 050406: El segundo punto es opcional.
23
 */
24
public class DxfText extends DxfEntity {
25
        public final static int ALIGN_LEFT                = 0;
26
        public final static int ALIGN_CENTER        = 1;
27
        public final static int ALIGN_RIGHT                = 2;
28
        public final static int ALIGN_ALIGNED        = 3;
29
        public final static int ALIGN_MIDDLE        = 4;
30
        public final static int ALIGN_FIT                = 5;
31
        private String text = null;
32
        Point2D [] pts;
33
        private Point2D pt;
34
        private double rot = 0.0;
35
        private double h = 1.0;
36
        int align = ALIGN_LEFT;
37
        private boolean twoPointsFlag;
38
        
39
        public DxfText(IProjection proj, DxfLayer layer, String txt) {
40
                super(proj, layer);
41
                //System.out.println("Dxf: TEXT '"+txt+"'.");
42
                extent = new Extent();
43
                text = txt;
44
                pts = new Point2D[2];
45
                pt = new Point2D.Double();
46
                twoPointsFlag = false;
47
        }
48
        
49
        public void setPt(Point2D pt) {
50
                this.pt = pt;
51
        }
52
        public Point2D getPt() {
53
                return pt;
54
        }
55
        public void setTwoPointsFlag(boolean f) {
56
                twoPointsFlag = f;
57
        }
58
        public boolean getTwoPointsFlag() {
59
                return twoPointsFlag;
60
        }
61

    
62
        public void setPt1(Point2D pt) { 
63
                pts[0] = pt;
64
                extent.add(pt);
65
        }
66
        public Point2D getPt1() { return pts[0]; }
67
        public void setPt2(Point2D pt) {
68
                pts[1] = pt;
69
                extent.add(pt);
70
        }
71
        public Point2D getPt2() { return pts[1]; }
72
        public void setHeight(double h) { this.h = h; }
73
        public void setRotation(double r) { rot = r; }
74
        public double getRotation() { return rot; }
75
        public String getText() { return text; }
76

    
77
        public void reProject(ICoordTrans rp) {
78
                Point2D [] savePts = pts;
79

    
80
                pts = new Point2D[2];
81
                extent = new Extent();
82
                Point2D ptDest = null;
83
                for (int i=0; i<savePts.length; i++) {
84
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
85
                        if (savePts[i] == null)
86
                                ptDest = null;
87
                        else {
88
                                ptDest = rp.convert((Point2D) savePts[i], ptDest);
89
                                extent.add(ptDest);
90
                        }
91
                        pts[i] = ptDest;
92
                }
93
                // Reproyecto la altura del texto
94
                Point2D ptOrig = rp.getPOrig().createPoint(savePts[0].getX(),savePts[0].getY()+h);
95
                ptDest = rp.getPDest().createPoint(0D, 0D);
96
                ptDest = rp.convert(ptOrig, ptDest);
97
                h = ptDest.getY()-pts[0].getY();
98
                setProjection(rp.getPDest());
99
        }
100

    
101
        public void draw(Graphics2D g, ViewPortData vp) {
102
                if (dxfColor == AcadColor.BYLAYER)
103
                        g.setColor(layer.getColor());
104
                else
105
                        g.setColor(AcadColor.getColor(dxfColor));
106
                Font fntSave = g.getFont(), fnt;
107
                Point2D ptT0 = new Point2D.Double(pts[0].getX(), pts[0].getY());
108
                Point2D ptT1 = new Point2D.Double(pts[0].getX()+h, pts[0].getY()+h);
109
                vp.mat.transform(ptT0, ptT0);
110
                vp.mat.transform(ptT1, ptT1);
111
                fnt = new Font(fntSave.getName(), fntSave.getStyle(), (int) (ptT1.getX()-ptT0.getX()));
112
                g.setFont(fnt);
113
                ptT0.setLocation(pts[0].getX(), pts[0].getY());
114
                vp.mat.transform(ptT0, ptT0);
115
                
116
                // Codigo para implementar rotacion de textos.
117
                // Falta depurar.
118
                /*System.out.println("040906: rot = " + rot);
119
                //angle = pathLen.angleAtLength(midDistance);
120
                rot = Math.toRadians(rot);
121
                if (rot < 0) rot = rot + 2.0*Math.PI;
122
                if ((rot > (Math.PI/2)) && (rot < (3 * Math.PI /2))) rot = rot - (Math.PI/2.0);
123
                rot = Math.toDegrees(rot);
124
                //theLabel.setRotation(Math.toDegrees(angle));
125
                AffineTransform transfRot = AffineTransform.getRotateInstance(rot, ptT0.getX(), ptT0.getY());
126
                AffineTransform ant = g.getTransform();
127
                g.setTransform(transfRot);*/
128
                
129
                g.drawString(text, (int) ptT0.getX(), (int)ptT0.getY());
130
                g.setFont(fntSave);
131
                
132
                //g.setTransform(ant);
133
        }
134

    
135
        /* (non-Javadoc)
136
         * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
137
         */
138
        public String toDxfString() {
139
                // TODO Auto-generated method stub
140
                return "";
141
        }
142
}