2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.gui2
;
21 import com
.googlecode
.lanterna
.*;
22 import com
.googlecode
.lanterna
.graphics
.*;
23 import com
.googlecode
.lanterna
.screen
.TabBehaviour
;
25 import java
.util
.Collection
;
26 import java
.util
.EnumSet
;
29 * TextGraphics implementation used by TextGUI when doing any drawing operation.
32 public final class TextGUIGraphics
implements ThemedTextGraphics
, TextGraphics
{
33 private final TextGUI textGUI
;
34 private final ImmutableThemedTextGraphics backend
;
36 TextGUIGraphics(TextGUI textGUI
, TextGraphics backend
, Theme theme
) {
37 this.backend
= new ImmutableThemedTextGraphics(backend
, theme
);
38 this.textGUI
= textGUI
;
42 public Theme
getTheme() {
43 return backend
.getTheme();
47 * Returns a new {@code TextGUIGraphics} object that has another theme attached to it
48 * @param theme Theme to be used with the new {@code TextGUIGraphics}
49 * @return New {@code TextGUIGraphics} that has the specified theme
51 public TextGUIGraphics
withTheme(Theme theme
) {
52 return new TextGUIGraphics(textGUI
, backend
.getUnderlyingTextGraphics(), theme
);
56 * Returns the {@code TextGUI} this {@code TextGUIGraphics} belongs to
57 * @return {@code TextGUI} this {@code TextGUIGraphics} belongs to
59 public TextGUI
getTextGUI() {
64 public TextGUIGraphics
newTextGraphics(TerminalPosition topLeftCorner
, TerminalSize size
) throws IllegalArgumentException
{
65 return new TextGUIGraphics(textGUI
, backend
.getUnderlyingTextGraphics().newTextGraphics(topLeftCorner
, size
), backend
.getTheme());
69 public TextGUIGraphics
applyThemeStyle(ThemeStyle themeStyle
) {
70 backend
.applyThemeStyle(themeStyle
);
75 public ThemeDefinition
getThemeDefinition(Class
<?
> clazz
) {
76 return backend
.getThemeDefinition(clazz
);
80 public TerminalSize
getSize() {
81 return backend
.getSize();
85 public TextColor
getBackgroundColor() {
86 return backend
.getBackgroundColor();
90 public TextGUIGraphics
setBackgroundColor(TextColor backgroundColor
) {
91 backend
.setBackgroundColor(backgroundColor
);
96 public TextColor
getForegroundColor() {
97 return backend
.getForegroundColor();
101 public TextGUIGraphics
setForegroundColor(TextColor foregroundColor
) {
102 backend
.setForegroundColor(foregroundColor
);
107 public TextGUIGraphics
enableModifiers(SGR
... modifiers
) {
108 backend
.enableModifiers(modifiers
);
113 public TextGUIGraphics
disableModifiers(SGR
... modifiers
) {
114 backend
.disableModifiers(modifiers
);
119 public TextGUIGraphics
setModifiers(EnumSet
<SGR
> modifiers
) {
120 backend
.setModifiers(modifiers
);
125 public TextGUIGraphics
clearModifiers() {
126 backend
.clearModifiers();
131 public EnumSet
<SGR
> getActiveModifiers() {
132 return backend
.getActiveModifiers();
136 public TabBehaviour
getTabBehaviour() {
137 return backend
.getTabBehaviour();
141 public TextGUIGraphics
setTabBehaviour(TabBehaviour tabBehaviour
) {
142 backend
.setTabBehaviour(tabBehaviour
);
147 public TextGUIGraphics
fill(char c
) {
153 public TextGraphics
fillRectangle(TerminalPosition topLeft
, TerminalSize size
, char character
) {
154 backend
.fillRectangle(topLeft
, size
, character
);
159 public TextGraphics
fillRectangle(TerminalPosition topLeft
, TerminalSize size
, TextCharacter character
) {
160 backend
.fillRectangle(topLeft
, size
, character
);
165 public TextGraphics
drawRectangle(TerminalPosition topLeft
, TerminalSize size
, char character
) {
166 backend
.drawRectangle(topLeft
, size
, character
);
171 public TextGraphics
drawRectangle(TerminalPosition topLeft
, TerminalSize size
, TextCharacter character
) {
172 backend
.drawRectangle(topLeft
, size
, character
);
177 public TextGraphics
fillTriangle(TerminalPosition p1
, TerminalPosition p2
, TerminalPosition p3
, char character
) {
178 backend
.fillTriangle(p1
, p2
, p3
, character
);
183 public TextGraphics
fillTriangle(TerminalPosition p1
, TerminalPosition p2
, TerminalPosition p3
, TextCharacter character
) {
184 backend
.fillTriangle(p1
, p2
, p3
, character
);
189 public TextGraphics
drawTriangle(TerminalPosition p1
, TerminalPosition p2
, TerminalPosition p3
, char character
) {
190 backend
.drawTriangle(p1
, p2
, p3
, character
);
195 public TextGraphics
drawTriangle(TerminalPosition p1
, TerminalPosition p2
, TerminalPosition p3
, TextCharacter character
) {
196 backend
.drawTriangle(p1
, p2
, p3
, character
);
201 public TextGraphics
drawLine(TerminalPosition fromPoint
, TerminalPosition toPoint
, char character
) {
202 backend
.drawLine(fromPoint
, toPoint
, character
);
207 public TextGraphics
drawLine(TerminalPosition fromPoint
, TerminalPosition toPoint
, TextCharacter character
) {
208 backend
.drawLine(fromPoint
, toPoint
, character
);
213 public TextGraphics
drawLine(int fromX
, int fromY
, int toX
, int toY
, char character
) {
214 backend
.drawLine(fromX
, fromY
, toX
, toY
, character
);
219 public TextGraphics
drawLine(int fromX
, int fromY
, int toX
, int toY
, TextCharacter character
) {
220 backend
.drawLine(fromX
, fromY
, toX
, toY
, character
);
225 public TextGraphics
drawImage(TerminalPosition topLeft
, TextImage image
) {
226 backend
.drawImage(topLeft
, image
);
231 public TextGraphics
drawImage(TerminalPosition topLeft
, TextImage image
, TerminalPosition sourceImageTopLeft
, TerminalSize sourceImageSize
) {
232 backend
.drawImage(topLeft
, image
, sourceImageTopLeft
, sourceImageSize
);
237 public TextGraphics
setCharacter(TerminalPosition position
, char character
) {
238 backend
.setCharacter(position
, character
);
243 public TextGraphics
setCharacter(TerminalPosition position
, TextCharacter character
) {
244 backend
.setCharacter(position
, character
);
249 public TextGraphics
setCharacter(int column
, int row
, char character
) {
250 backend
.setCharacter(column
, row
, character
);
255 public TextGraphics
setCharacter(int column
, int row
, TextCharacter character
) {
256 backend
.setCharacter(column
, row
, character
);
261 public TextGUIGraphics
putString(int column
, int row
, String string
) {
262 backend
.putString(column
, row
, string
);
267 public TextGUIGraphics
putString(TerminalPosition position
, String string
) {
268 backend
.putString(position
, string
);
273 public TextGUIGraphics
putString(int column
, int row
, String string
, SGR extraModifier
, SGR
... optionalExtraModifiers
) {
274 backend
.putString(column
, row
, string
, extraModifier
, optionalExtraModifiers
);
279 public TextGUIGraphics
putString(TerminalPosition position
, String string
, SGR extraModifier
, SGR
... optionalExtraModifiers
) {
280 backend
.putString(position
, string
, extraModifier
, optionalExtraModifiers
);
285 public TextGraphics
putString(int column
, int row
, String string
, Collection
<SGR
> extraModifiers
) {
286 backend
.putString(column
, row
, string
, extraModifiers
);
291 public TextCharacter
getCharacter(int column
, int row
) {
292 return backend
.getCharacter(column
, row
);
296 public TextCharacter
getCharacter(TerminalPosition position
) {
297 return backend
.getCharacter(position
);