1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.layout;
20
21 import java.awt.Color;
22 import java.awt.Graphics2D;
23 import java.awt.font.TextLayout;
24 import java.awt.geom.AffineTransform;
25
26
27
28
29 public class TextObject implements GraphicsObject {
30
31 private final TextLayout layout;
32
33 private final Color color;
34
35 private final float xoffset;
36
37 private final float yoffset;
38
39 private final AffineTransform trans;
40
41
42
43
44
45
46
47
48
49
50
51 public TextObject(final TextLayout textLayout, final float xo,
52 final Color textColor) {
53 assert textLayout != null;
54 this.layout = textLayout;
55 this.color = textColor;
56 this.xoffset = xo;
57 this.yoffset = 0.0f;
58 this.trans = null;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public TextObject(final TextLayout textLayout, final float xo,
76 final float yo, final AffineTransform transform,
77 final Color textColor) {
78 assert textLayout != null;
79 this.layout = textLayout;
80 this.color = textColor;
81 this.xoffset = xo;
82 this.yoffset = yo;
83 this.trans = transform;
84 }
85
86
87 public void paint(final float x, final float y, final Graphics2D g) {
88 g.setColor(this.color);
89 final AffineTransform oldTrans = g.getTransform();
90 g.translate(x + this.xoffset, y + this.yoffset);
91 if (this.trans != null) {
92 g.transform(this.trans);
93 }
94 this.layout.draw(g, 0, 0);
95 g.setTransform(oldTrans);
96 }
97 }