Package org.apache.pivot.wtk
Class Theme
- java.lang.Object
-
- org.apache.pivot.wtk.Theme
-
- Direct Known Subclasses:
TerraTheme
public abstract class Theme extends java.lang.Object
Base class for Pivot themes. A theme defines a complete "look and feel" for a Pivot application.Note that concrete Theme implementations should be declared as final. If multiple third-party libraries attempted to extend a theme, it would cause a conflict, as only one could be used in any given application.
IMPORTANT All skin mappings must be added to the map, even non-static inner classes. Otherwise, the component's base class will attempt to install its own skin, which will result in the addition of duplicate listeners.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BOLD_KEY
Key for the font bold style in a font dictionary.static java.lang.String
ITALIC_KEY
Key for the font italic style in a font dictionary.static java.lang.String
NAME_KEY
Key for the font name in a font dictionary.static java.lang.String
PROVIDER_NAME
The service provider name (seeService.getProvider(String)
).static java.lang.String
SIZE_KEY
Key for the font size in a font dictionary.
-
Constructor Summary
Constructors Constructor Description Theme()
Construct the generic theme by assigning default skin classes to some components.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static java.awt.Font
deriveFont(Dictionary<java.lang.String,?> dictionary)
Produce a font by describing it relative to the current theme's font.abstract java.awt.Color
getBaseColor(int index)
abstract java.awt.Color
getColor(int index)
java.awt.Color
getDefaultBackgroundColor()
Returns a safe (and general) default background color.java.awt.Color
getDefaultForegroundColor()
Returns a safe (and general) default foreground color.abstract java.awt.Font
getFont()
abstract int
getNumberOfColors()
Gets the total number of Colors (including derived colors, if any).abstract int
getNumberOfPaletteColors()
Gets the number of Palette Colors.java.lang.Class<? extends Skin>
getSkinClass(java.lang.Class<? extends Component> componentClass)
Returns the skin class responsible for skinning the specified component class.static Theme
getTheme()
abstract boolean
isThemeDark()
Tell if the theme is dark.
Usually this means that (if true) any color will be transformed in the opposite way (brightening instead of darkening, and darkening instead of brightening).abstract boolean
isThemeFlat()
Tell if the theme is flat.
Usually this means that (if true) any border/shadow will not be drawn.abstract boolean
isThickFocusRectangle()
Tell if the theme has "thick" focus rectangles, rather than a one pixel version that may be hard to distinguish in certain color schemes, or screen resolutions.abstract boolean
isTransitionEnabled()
Tell if the theme has transitions enabled.
Usually this means that (if false) any effect/transition will not be drawn.void
set(java.lang.Class<? extends Component> componentClass, java.lang.Class<? extends Skin> skinClass)
Sets the skin class responsible for skinning the specified component class.abstract void
setBaseColor(int index, java.awt.Color baseColor)
Sets a color in the theme's base color palette.abstract void
setColor(int index, java.awt.Color color)
Sets a value in the theme's complete color palette (including derived colors, if any).abstract <T extends ComponentSkin>
voidsetDefaultStyles(T skin)
Set appropriate default styles for the given skin object, specified by the current theme.abstract void
setFont(java.awt.Font font)
Sets the theme's font.
-
-
-
Field Detail
-
NAME_KEY
public static final java.lang.String NAME_KEY
Key for the font name in a font dictionary.- See Also:
- Constant Field Values
-
SIZE_KEY
public static final java.lang.String SIZE_KEY
Key for the font size in a font dictionary.- See Also:
- Constant Field Values
-
BOLD_KEY
public static final java.lang.String BOLD_KEY
Key for the font bold style in a font dictionary.- See Also:
- Constant Field Values
-
ITALIC_KEY
public static final java.lang.String ITALIC_KEY
Key for the font italic style in a font dictionary.- See Also:
- Constant Field Values
-
PROVIDER_NAME
public static final java.lang.String PROVIDER_NAME
The service provider name (seeService.getProvider(String)
).
-
-
Method Detail
-
getSkinClass
public final java.lang.Class<? extends Skin> getSkinClass(java.lang.Class<? extends Component> componentClass)
Returns the skin class responsible for skinning the specified component class.- Parameters:
componentClass
- The component class.- Returns:
- The skin class, or
null
if no skin mapping exists for the component class. - Throws:
java.lang.IllegalArgumentException
- if the given component class isnull
.
-
set
public void set(java.lang.Class<? extends Component> componentClass, java.lang.Class<? extends Skin> skinClass)
Sets the skin class responsible for skinning the specified component class.- Parameters:
componentClass
- The component class.skinClass
- The skin class.
-
getFont
public abstract java.awt.Font getFont()
- Returns:
- The theme's font.
-
setFont
public abstract void setFont(java.awt.Font font)
Sets the theme's font.- Parameters:
font
- The font.
-
getBaseColor
public abstract java.awt.Color getBaseColor(int index)
- Parameters:
index
- The index of the color, starting from 0.- Returns:
- A color from the theme's base color palette.
-
setBaseColor
public abstract void setBaseColor(int index, java.awt.Color baseColor)
Sets a color in the theme's base color palette.- Parameters:
index
- The index of the color, starting from 0.baseColor
- The color value to set.
-
getColor
public abstract java.awt.Color getColor(int index)
- Parameters:
index
- The index of the color, starting from 0.- Returns:
- A value from the theme's complete color palette (including derived colors, if any).
-
setColor
public abstract void setColor(int index, java.awt.Color color)
Sets a value in the theme's complete color palette (including derived colors, if any).- Parameters:
index
- The index of the color, starting from 0.color
- The color value to set.
-
getNumberOfPaletteColors
public abstract int getNumberOfPaletteColors()
Gets the number of Palette Colors.- Returns:
- The number of colors in the theme's palette.
-
getNumberOfColors
public abstract int getNumberOfColors()
Gets the total number of Colors (including derived colors, if any).- Returns:
- The total number of colors.
-
isThemeDark
public abstract boolean isThemeDark()
Tell if the theme is dark.
Usually this means that (if true) any color will be transformed in the opposite way (brightening instead of darkening, and darkening instead of brightening).Note: this value is set in the theme properties file.
- Returns:
true
if dark,false
otherwise.
-
isThemeFlat
public abstract boolean isThemeFlat()
Tell if the theme is flat.
Usually this means that (if true) any border/shadow will not be drawn.- Returns:
true
if flat,false
otherwise.
-
isTransitionEnabled
public abstract boolean isTransitionEnabled()
Tell if the theme has transitions enabled.
Usually this means that (if false) any effect/transition will not be drawn.- Returns:
true
if enabled (default),false
otherwise.
-
isThickFocusRectangle
public abstract boolean isThickFocusRectangle()
Tell if the theme has "thick" focus rectangles, rather than a one pixel version that may be hard to distinguish in certain color schemes, or screen resolutions.- Returns:
true
if thick focus rectangles should be drawn, orfalse
for thin ones (the default in earlier versions).
-
setDefaultStyles
public abstract <T extends ComponentSkin> void setDefaultStyles(T skin)
Set appropriate default styles for the given skin object, specified by the current theme.- Type Parameters:
T
- The skin class whose type we are dealing with.- Parameters:
skin
- The skin object of that type whose styles are to be set.
-
getDefaultBackgroundColor
public java.awt.Color getDefaultBackgroundColor()
Returns a safe (and general) default background color.- Returns:
- White if the theme is not dark (default), or Black.
-
getDefaultForegroundColor
public java.awt.Color getDefaultForegroundColor()
Returns a safe (and general) default foreground color.- Returns:
- Black if the theme is not dark (default), or White otherwise.
-
getTheme
public static Theme getTheme()
- Returns:
- The current theme, as determined by the theme provider.
- Throws:
ThemeNotFoundException
- If a theme has not been installed.
-
deriveFont
public static java.awt.Font deriveFont(Dictionary<java.lang.String,?> dictionary)
Produce a font by describing it relative to the current theme's font.- Parameters:
dictionary
- A dictionary with any of the following keys:- "name" - the family name of the font
- "size" - the font size as an integer, or a string "x%" for a relative size
- "bold" - true/false
- "italic" - true/false
Arial,Verdana,SansSerif
.- Returns:
- The new font derived from the current font.
- Throws:
java.lang.IllegalArgumentException
- if the supplied dictionary isnull
.
-
-