- java.lang.Object
-
- com.googlecode.lanterna.graphics.SimpleTheme
-
- All Implemented Interfaces:
Theme
public class SimpleTheme extends java.lang.Object implements Theme
Very basic implementation ofTheme
that allows you to quickly define a theme in code. It is a very simple implementation that doesn't implement any intelligent fallback based on class hierarchy or package names. If a particular class has not been defined with an explicit override, it will get the default theme style definition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleTheme.Definition
Internal class insideSimpleTheme
used to allow basic editing of the default style and the optional overrides.static interface
SimpleTheme.RendererProvider<T extends Component>
-
Field Summary
Fields Modifier and Type Field Description private SimpleTheme.Definition
defaultDefinition
private java.util.Map<java.lang.Class<?>,SimpleTheme.Definition>
overrideDefinitions
private WindowDecorationRenderer
windowDecorationRenderer
private WindowPostRenderer
windowPostRenderer
-
Constructor Summary
Constructors Constructor Description SimpleTheme(TextColor foreground, TextColor background, SGR... styles)
Creates a newSimpleTheme
object that uses the supplied constructor arguments as the default style
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleTheme.Definition
addOverride(java.lang.Class<?> clazz, TextColor foreground, TextColor background, SGR... styles)
Adds an override for a particular class, or overwrites a previously defined override.SimpleTheme.Definition
getDefaultDefinition()
Returns what this theme considers to be the default definitionSimpleTheme.Definition
getDefinition(java.lang.Class<?> clazz)
Returns the theme definition associated with this class.WindowDecorationRenderer
getWindowDecorationRenderer()
Returns theWindowDecorationRenderer
to use for windows drawn in this theme.WindowPostRenderer
getWindowPostRenderer()
Returns a post-renderer to invoke after drawing each window, unless the GUI system or individual windows has their own renderers set.static SimpleTheme
makeTheme(boolean activeIsBold, TextColor baseForeground, TextColor baseBackground, TextColor editableForeground, TextColor editableBackground, TextColor selectedForeground, TextColor selectedBackground, TextColor guiBackground)
Helper method that will quickly setup a new theme with some sensible component overrides.SimpleTheme
setWindowDecorationRenderer(WindowDecorationRenderer windowDecorationRenderer)
Changes theWindowDecorationRenderer
this theme will return.SimpleTheme
setWindowPostRenderer(WindowPostRenderer windowPostRenderer)
Changes theWindowPostRenderer
this theme will return.
-
-
-
Field Detail
-
defaultDefinition
private final SimpleTheme.Definition defaultDefinition
-
overrideDefinitions
private final java.util.Map<java.lang.Class<?>,SimpleTheme.Definition> overrideDefinitions
-
windowPostRenderer
private WindowPostRenderer windowPostRenderer
-
windowDecorationRenderer
private WindowDecorationRenderer windowDecorationRenderer
-
-
Constructor Detail
-
SimpleTheme
public SimpleTheme(TextColor foreground, TextColor background, SGR... styles)
Creates a newSimpleTheme
object that uses the supplied constructor arguments as the default style- Parameters:
foreground
- Color to use as the foreground unless overriddenbackground
- Color to use as the background unless overriddenstyles
- Extra SGR styles to apply unless overridden
-
-
Method Detail
-
makeTheme
public static SimpleTheme makeTheme(boolean activeIsBold, TextColor baseForeground, TextColor baseBackground, TextColor editableForeground, TextColor editableBackground, TextColor selectedForeground, TextColor selectedBackground, TextColor guiBackground)
Helper method that will quickly setup a new theme with some sensible component overrides.- Parameters:
activeIsBold
- Should focused components also use bold SGR style?baseForeground
- The base foreground color of the themebaseBackground
- The base background color of the themeeditableForeground
- Foreground color for editable components, or editable areas of componentseditableBackground
- Background color for editable components, or editable areas of componentsselectedForeground
- Foreground color for the selection marker when a component has multiple selection statesselectedBackground
- Background color for the selection marker when a component has multiple selection statesguiBackground
- Background color of the GUI, if this theme is assigned to theTextGUI
- Returns:
- Assembled
SimpleTheme
using the parameters from above
-
getDefaultDefinition
public SimpleTheme.Definition getDefaultDefinition()
Description copied from interface:Theme
Returns what this theme considers to be the default definition- Specified by:
getDefaultDefinition
in interfaceTheme
- Returns:
- The default theme definition
-
getDefinition
public SimpleTheme.Definition getDefinition(java.lang.Class<?> clazz)
Description copied from interface:Theme
Returns the theme definition associated with this class. The implementation of Theme should ensure that this call never returnsnull
, it should always give back a valid value (falling back to the default is nothing else can be used).- Specified by:
getDefinition
in interfaceTheme
- Parameters:
clazz
- Class to get the theme definition for- Returns:
- The ThemeDefinition for the class passed in
-
addOverride
public SimpleTheme.Definition addOverride(java.lang.Class<?> clazz, TextColor foreground, TextColor background, SGR... styles)
Adds an override for a particular class, or overwrites a previously defined override.- Parameters:
clazz
- Class to override the theme forforeground
- Color to use as the foreground color for this override stylebackground
- Color to use as the background color for this override stylestyles
- SGR styles to apply for this override- Returns:
- The newly created
SimpleTheme.Definition
that corresponds to this override.
-
getWindowPostRenderer
public WindowPostRenderer getWindowPostRenderer()
Description copied from interface:Theme
Returns a post-renderer to invoke after drawing each window, unless the GUI system or individual windows has their own renderers set. Ifnull
, no post-renderer will be done (unless the GUI system or the windows has a post-renderer).- Specified by:
getWindowPostRenderer
in interfaceTheme
- Returns:
- A
WindowPostRenderer
to invoke after drawing each window unless overridden, ornull
if none
-
setWindowPostRenderer
public SimpleTheme setWindowPostRenderer(WindowPostRenderer windowPostRenderer)
Changes theWindowPostRenderer
this theme will return. If called withnull
, the theme returns no post renderer and the GUI system will use whatever is the default.- Parameters:
windowPostRenderer
- Post-renderer to use along with this theme, ornull
to remove- Returns:
- Itself
-
getWindowDecorationRenderer
public WindowDecorationRenderer getWindowDecorationRenderer()
Description copied from interface:Theme
Returns theWindowDecorationRenderer
to use for windows drawn in this theme. Ifnull
then lanterna will fall back to useDefaultWindowDecorationRenderer
.- Specified by:
getWindowDecorationRenderer
in interfaceTheme
- Returns:
- The decoration renderer to use for this theme, or
null
to use system default
-
setWindowDecorationRenderer
public SimpleTheme setWindowDecorationRenderer(WindowDecorationRenderer windowDecorationRenderer)
Changes theWindowDecorationRenderer
this theme will return. If called withnull
, the theme returns no decoration renderer and the GUI system will use whatever is the default.- Parameters:
windowDecorationRenderer
- Decoration renderer to use along with this theme, ornull
to remove- Returns:
- Itself
-
-