1 package org.opentrafficsim.draw.core;
2
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.font.TextAttribute;
6 import java.io.Serializable;
7 import java.util.Hashtable;
8 import java.util.Map;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class TextProperties implements Serializable
23 {
24
25 private static final long serialVersionUID = 20170400L;
26
27
28 private final TextAlignment textAlignment;
29
30
31 private final Color color;
32
33
34 private final String font;
35
36
37 private final Map<TextAttribute, Object> textAttributes;
38
39
40 private final float fontSize;
41
42
43
44
45 public TextProperties()
46 {
47 this(TextAlignment.CENTER, Color.BLACK, 1.5f);
48 }
49
50
51
52
53
54
55
56 public TextProperties(final TextAlignment textAlignment, final Color color, final float fontSize)
57 {
58 this(textAlignment, color, fontSize, Font.SANS_SERIF, new Hashtable<>());
59 }
60
61
62
63
64
65
66
67
68
69 public TextProperties(final TextAlignment textAlignment, final Color color, final float fontSize, final String font,
70 final Map<TextAttribute, Object> textAttributes)
71 {
72 this.textAlignment = textAlignment;
73 this.color = color;
74 this.fontSize = fontSize;
75 this.font = font;
76 this.textAttributes = new Hashtable<>(textAttributes);
77 }
78
79
80
81
82 public final TextAlignment getTextAlignment()
83 {
84 return this.textAlignment;
85 }
86
87
88
89
90 public final Color getColor()
91 {
92 return this.color;
93 }
94
95
96
97
98 public final String getFont()
99 {
100 return this.font;
101 }
102
103
104
105
106 public final Map<TextAttribute, Object> getTextAttributes()
107 {
108 return this.textAttributes;
109 }
110
111
112
113
114 public final float getFontSize()
115 {
116 return this.fontSize;
117 }
118
119
120
121
122
123 public final void setBold(final boolean bold)
124 {
125 this.textAttributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
126 }
127
128
129
130
131
132 public final void setBold(final TextWeight weight)
133 {
134 this.textAttributes.put(TextAttribute.WEIGHT, weight.getValue());
135 }
136
137
138
139
140
141 public final void setItalic(final boolean italic)
142 {
143 this.textAttributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
144 }
145
146
147
148
149
150 public final void setWeightBold(final TextWidth width)
151 {
152 this.textAttributes.put(TextAttribute.WIDTH, width.getValue());
153 }
154
155
156
157
158
159 public final void setUnderline(final boolean underline)
160 {
161 this.textAttributes.put(TextAttribute.UNDERLINE, underline ? TextAttribute.UNDERLINE_ON : -1);
162 }
163
164
165
166
167
168 public final void setStrikethrough(final boolean strikethrough)
169 {
170 this.textAttributes.put(TextAttribute.STRIKETHROUGH, strikethrough ? TextAttribute.STRIKETHROUGH_ON : -1);
171 }
172
173
174 @Override
175 public final String toString()
176 {
177 return "TextProperties [textAlignment=" + this.textAlignment + ", color=" + this.color + ", font=" + this.font
178 + ", textAttributes=" + this.textAttributes + ", fontSize=" + this.fontSize + "]";
179 }
180
181 }