Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / graphics / ImmutableThemedTextGraphics.java
1 package com.googlecode.lanterna.graphics;
2
3 import com.googlecode.lanterna.*;
4 import com.googlecode.lanterna.screen.TabBehaviour;
5
6 import java.util.Collection;
7 import java.util.EnumSet;
8
9 /**
10 * Implementation of ThemedTextGraphics that wraps a TextGraphics that all calls are delegated to, except for the
11 * method from ThemedTextGraphics which are handled. The theme is set at construction time, but you can create a clone
12 * of this object with a different theme.
13 * @author Martin
14 */
15 public class ImmutableThemedTextGraphics implements ThemedTextGraphics {
16 private final TextGraphics backend;
17 private final Theme theme;
18
19 /**
20 * Creates a new {@code ImmutableThemedTextGraphics} with a specified backend for all drawing operations and a
21 * theme.
22 * @param backend Backend to send all drawing operations to
23 * @param theme Theme to be associated with this object
24 */
25 public ImmutableThemedTextGraphics(TextGraphics backend, Theme theme) {
26 this.backend = backend;
27 this.theme = theme;
28 }
29
30 /**
31 * Returns a new {@code ImmutableThemedTextGraphics} that targets the same backend but with another theme
32 * @param theme Theme the new {@code ImmutableThemedTextGraphics} is using
33 * @return New {@code ImmutableThemedTextGraphics} object that uses the same backend as this object
34 */
35 public ImmutableThemedTextGraphics withTheme(Theme theme) {
36 return new ImmutableThemedTextGraphics(backend, theme);
37 }
38
39 /**
40 * Returns the underlying {@code TextGraphics} that is handling all drawing operations
41 * @return Underlying {@code TextGraphics} that is handling all drawing operations
42 */
43 public TextGraphics getUnderlyingTextGraphics() {
44 return backend;
45 }
46
47 /**
48 * Returns the theme associated with this {@code ImmutableThemedTextGraphics}
49 * @return The theme associated with this {@code ImmutableThemedTextGraphics}
50 */
51 public Theme getTheme() {
52 return theme;
53 }
54
55 @Override
56 public ThemeDefinition getThemeDefinition(Class<?> clazz) {
57 return theme.getDefinition(clazz);
58 }
59
60 @Override
61 public ImmutableThemedTextGraphics applyThemeStyle(ThemeStyle themeStyle) {
62 setForegroundColor(themeStyle.getForeground());
63 setBackgroundColor(themeStyle.getBackground());
64 setModifiers(themeStyle.getSGRs());
65 return this;
66 }
67
68 @Override
69 public TerminalSize getSize() {
70 return backend.getSize();
71 }
72
73 @Override
74 public ImmutableThemedTextGraphics newTextGraphics(TerminalPosition topLeftCorner, TerminalSize size) throws IllegalArgumentException {
75 return new ImmutableThemedTextGraphics(backend.newTextGraphics(topLeftCorner, size), theme);
76 }
77
78 @Override
79 public TextColor getBackgroundColor() {
80 return backend.getBackgroundColor();
81 }
82
83 @Override
84 public ImmutableThemedTextGraphics setBackgroundColor(TextColor backgroundColor) {
85 backend.setBackgroundColor(backgroundColor);
86 return this;
87 }
88
89 @Override
90 public TextColor getForegroundColor() {
91 return backend.getForegroundColor();
92 }
93
94 @Override
95 public ImmutableThemedTextGraphics setForegroundColor(TextColor foregroundColor) {
96 backend.setForegroundColor(foregroundColor);
97 return this;
98 }
99
100 @Override
101 public ImmutableThemedTextGraphics enableModifiers(SGR... modifiers) {
102 backend.enableModifiers(modifiers);
103 return this;
104 }
105
106 @Override
107 public ImmutableThemedTextGraphics disableModifiers(SGR... modifiers) {
108 backend.disableModifiers(modifiers);
109 return this;
110 }
111
112 @Override
113 public ImmutableThemedTextGraphics setModifiers(EnumSet<SGR> modifiers) {
114 backend.setModifiers(modifiers);
115 return this;
116 }
117
118 @Override
119 public ImmutableThemedTextGraphics clearModifiers() {
120 backend.clearModifiers();
121 return this;
122 }
123
124 @Override
125 public EnumSet<SGR> getActiveModifiers() {
126 return backend.getActiveModifiers();
127 }
128
129 @Override
130 public TabBehaviour getTabBehaviour() {
131 return backend.getTabBehaviour();
132 }
133
134 @Override
135 public ImmutableThemedTextGraphics setTabBehaviour(TabBehaviour tabBehaviour) {
136 backend.setTabBehaviour(tabBehaviour);
137 return this;
138 }
139
140 @Override
141 public ImmutableThemedTextGraphics fill(char c) {
142 backend.fill(c);
143 return this;
144 }
145
146 @Override
147 public TextGraphics fillRectangle(TerminalPosition topLeft, TerminalSize size, char character) {
148 backend.fillRectangle(topLeft, size, character);
149 return this;
150 }
151
152 @Override
153 public TextGraphics fillRectangle(TerminalPosition topLeft, TerminalSize size, TextCharacter character) {
154 backend.fillRectangle(topLeft, size, character);
155 return this;
156 }
157
158 @Override
159 public TextGraphics drawRectangle(TerminalPosition topLeft, TerminalSize size, char character) {
160 backend.drawRectangle(topLeft, size, character);
161 return this;
162 }
163
164 @Override
165 public TextGraphics drawRectangle(TerminalPosition topLeft, TerminalSize size, TextCharacter character) {
166 backend.drawRectangle(topLeft, size, character);
167 return this;
168 }
169
170 @Override
171 public TextGraphics fillTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, char character) {
172 backend.fillTriangle(p1, p2, p3, character);
173 return this;
174 }
175
176 @Override
177 public TextGraphics fillTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, TextCharacter character) {
178 backend.fillTriangle(p1, p2, p3, character);
179 return this;
180 }
181
182 @Override
183 public TextGraphics drawTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, char character) {
184 backend.drawTriangle(p1, p2, p3, character);
185 return this;
186 }
187
188 @Override
189 public TextGraphics drawTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, TextCharacter character) {
190 backend.drawTriangle(p1, p2, p3, character);
191 return this;
192 }
193
194 @Override
195 public TextGraphics drawLine(TerminalPosition fromPoint, TerminalPosition toPoint, char character) {
196 backend.drawLine(fromPoint, toPoint, character);
197 return this;
198 }
199
200 @Override
201 public TextGraphics drawLine(TerminalPosition fromPoint, TerminalPosition toPoint, TextCharacter character) {
202 backend.drawLine(fromPoint, toPoint, character);
203 return this;
204 }
205
206 @Override
207 public TextGraphics drawLine(int fromX, int fromY, int toX, int toY, char character) {
208 backend.drawLine(fromX, fromY, toX, toY, character);
209 return this;
210 }
211
212 @Override
213 public TextGraphics drawLine(int fromX, int fromY, int toX, int toY, TextCharacter character) {
214 backend.drawLine(fromX, fromY, toX, toY, character);
215 return this;
216 }
217
218 @Override
219 public TextGraphics drawImage(TerminalPosition topLeft, TextImage image) {
220 backend.drawImage(topLeft, image);
221 return this;
222 }
223
224 @Override
225 public TextGraphics drawImage(TerminalPosition topLeft, TextImage image, TerminalPosition sourceImageTopLeft, TerminalSize sourceImageSize) {
226 backend.drawImage(topLeft, image, sourceImageTopLeft, sourceImageSize);
227 return this;
228 }
229
230 @Override
231 public TextGraphics setCharacter(TerminalPosition position, char character) {
232 backend.setCharacter(position, character);
233 return this;
234 }
235
236 @Override
237 public TextGraphics setCharacter(TerminalPosition position, TextCharacter character) {
238 backend.setCharacter(position, character);
239 return this;
240 }
241
242 @Override
243 public TextGraphics setCharacter(int column, int row, char character) {
244 backend.setCharacter(column, row, character);
245 return this;
246 }
247
248 @Override
249 public TextGraphics setCharacter(int column, int row, TextCharacter character) {
250 backend.setCharacter(column, row, character);
251 return this;
252 }
253
254 @Override
255 public ImmutableThemedTextGraphics putString(int column, int row, String string) {
256 backend.putString(column, row, string);
257 return this;
258 }
259
260 @Override
261 public ImmutableThemedTextGraphics putString(TerminalPosition position, String string) {
262 backend.putString(position, string);
263 return this;
264 }
265
266 @Override
267 public ImmutableThemedTextGraphics putString(int column, int row, String string, SGR extraModifier, SGR... optionalExtraModifiers) {
268 backend.putString(column, row, string, extraModifier, optionalExtraModifiers);
269 return this;
270 }
271
272 @Override
273 public ImmutableThemedTextGraphics putString(TerminalPosition position, String string, SGR extraModifier, SGR... optionalExtraModifiers) {
274 backend.putString(position, string, extraModifier, optionalExtraModifiers);
275 return this;
276 }
277
278 @Override
279 public TextGraphics putString(int column, int row, String string, Collection<SGR> extraModifiers) {
280 backend.putString(column, row, string, extraModifiers);
281 return this;
282 }
283
284 @Override
285 public TextCharacter getCharacter(TerminalPosition position) {
286 return backend.getCharacter(position);
287 }
288
289 @Override
290 public TextCharacter getCharacter(int column, int row) {
291 return backend.getCharacter(column, row);
292 }
293 }