1 package fi.jyu.mit.graphics;
2
3 import java.awt.*;
4
5
10 public class Text extends BasicShape {
11
12 String text;
13 RPoint leftBottom;
14 double tx = 1.0;
15 double ty = 1.0;
16
17
23 public Text(String text, double x, double y) {
24 super();
25 this.text = text;
26 this.leftBottom = new RPoint(x, y);
27 }
28
29
34 public void setTranslate(double sx,double sy) {
35 tx = sx;
36 ty = sy;
37 }
38
39
40
47 public Text(String text, double x, double y, double z) {
48 super();
49 this.text = text;
50 this.leftBottom = new RPoint(x, y, z);
51 }
52
53
57 @Override
58 protected void drawShape(Graphics g, Matrix a) {
59 FontMetrics fm = g.getFontMetrics();
60 int w = fm.stringWidth(text);
61 int h = fm.getAscent();
62 SPoint sp = a.transform(this.leftBottom);
63 g.drawString(this.text, (int)(sp.getX()+w/2.0*(tx-1)), (int)(sp.getY()-h/2.0*(ty-1)));
64 }
65 }
66