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