Statistics
| Revision:

svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfText.java @ 1732

History | View | Annotate | Download (3.56 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
 * 
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
        private String text = null;
31
        Point2D [] pts;
32
        private double rot = 0.0;
33
        private double h = 1.0;
34
        int align = ALIGN_LEFT;
35
        
36
        public DxfText(IProjection proj, DxfLayer layer, String txt) {
37
                super(proj, layer);
38
                //System.out.println("Dxf: TEXT '"+txt+"'.");
39
                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
        public Point2D getPt1() { return pts[0]; }
49
        public void setPt2(Point2D pt) {
50
                pts[1] = pt;
51
                extent.add(pt);
52
        }
53
        public Point2D getPt2() { return pts[1]; }
54
        public void setHeight(double h) { this.h = h; }
55
        public void setRotation(double r) { rot = r; }
56
        public double getRotation() { return rot; }
57
        public String getText() { return text; }
58

    
59
        public void reProject(ICoordTrans rp) {
60
                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
                                ptDest = rp.convert((Point2D) savePts[i], ptDest);
71
                                extent.add(ptDest);
72
                        }
73
                        pts[i] = ptDest;
74
                }
75
                // 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
                setProjection(rp.getPDest());
81
        }
82

    
83
        public void draw(Graphics2D g, ViewPortData vp) {
84
                if (dxfColor == AcadColor.BYLAYER)
85
                        g.setColor(layer.getColor());
86
                else
87
                        g.setColor(AcadColor.getColor(dxfColor));
88
                Font fntSave = g.getFont(), fnt;
89
                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
                vp.mat.transform(ptT0, ptT0);
92
                vp.mat.transform(ptT1, ptT1);
93
                fnt = new Font(fntSave.getName(), fntSave.getStyle(), (int) (ptT1.getX()-ptT0.getX()));
94
                g.setFont(fnt);
95
                ptT0.setLocation(pts[0].getX(), pts[0].getY());
96
                vp.mat.transform(ptT0, ptT0);
97
                
98
                // Codigo para implementar rotacion de textos.
99
                // Falta depurar.
100
                /*System.out.println("040906: rot = " + rot);
101
                //angle = pathLen.angleAtLength(midDistance);
102
                rot = Math.toRadians(rot);
103
                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
                //theLabel.setRotation(Math.toDegrees(angle));
107
                AffineTransform transfRot = AffineTransform.getRotateInstance(rot, ptT0.getX(), ptT0.getY());
108
                AffineTransform ant = g.getTransform();
109
                g.setTransform(transfRot);*/
110
                
111
                g.drawString(text, (int) ptT0.getX(), (int)ptT0.getY());
112
                g.setFont(fntSave);
113
                
114
                //g.setTransform(ant);
115
        }
116

    
117
        /* (non-Javadoc)
118
         * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
119
         */
120
        public String toDxfString() {
121
                // TODO Auto-generated method stub
122
                return "";
123
        }
124
}