APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.nimbus

pack-priv final Class NimbusDefaults

extends Object
Class Inheritance
Imports
javax.swing.Painter, .BorderFactory, .JComponent, .JInternalFrame, .UIDefaults, .UIManager, java.awt.Graphics, .Color, .Component, .Dimension, .Font, .Graphics2D, .Insets, sun.font.FontUtilities, sun.swing.plaf.synth.DefaultSynthStyle, javax.swing.plaf.BorderUIResource, .ColorUIResource, .DimensionUIResource, .FontUIResource, .InsetsUIResource, .UIResource, javax.swing.plaf.synth.Region, .SynthStyle, java.awt.image.BufferedImage, java.beans.PropertyChangeEvent, .PropertyChangeListener, java.lang.reflect.Constructor, java.util.ArrayList, .HashMap, .LinkedList, .List, .Map, .WeakHashMap, javax.swing.border.Border

This class contains all the implementation details related to Nimbus. It contains all the code for initializing the UIDefaults table, as well as for selecting a SynthStyle based on a JComponent/Region pair.
Author
Richard Bair

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
NimbusDefaults.DefaultsListener

Listener to update derived colors on UIManager Defaults changes

pack-priv static class
NimbusDefaults.DerivedFont

Derives its font value based on a parent font and a set of offsets and attributes.

private static class
NimbusDefaults.LazyPainter

This class is private because it relies on the constructor of the auto-generated AbstractRegionPainter subclasses.

private class
NimbusDefaults.LazyStyle

A class which creates the NimbusStyle associated with it lazily, but also manages a lot more information about the style.

private static class

Field Summary

Modifier and TypeField and Description
private NimbusDefaults.ColorTree
private FontUIResource
defaultFont

The default font that will be used.

private NimbusDefaults.DefaultsListener
defaultsListener

Listener for changes to user defaults table

private DefaultSynthStyle
defaultStyle

Our fallback style to avoid NPEs if the proper style cannot be found in this class.

private Map<DerivedColor, DerivedColor>
private Map<Region, List<NimbusDefaults.LazyStyle>>
m

The map of SynthStyles.

private Map<JComponent, Map<Region, SynthStyle>>
private Map<String, Region>
registeredRegions

A map of regions which have been registered.

Constructor Summary

AccessConstructor and Description
pack-priv
NimbusDefaults()

Create a new NimbusDefaults.

Method Summary

Modifier and TypeMethod and Description
private void
addColor(UIDefaults d, String uin, int r, int g, int b, int a)

private void
addColor(UIDefaults d, String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset)

private void
addColor(UIDefaults d, String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource)

public void
public DerivedColor

Returns:

The stored derived color
getDerivedColor
(String
The parent UIDefault key
parentUin
,
float
The hue offset
hOffset
,
float
The saturation offset
sOffset
,
float
The brightness offset
bOffset
,
int
The alpha offset
aOffset
,
boolean
True if the derived color should be a UIResource, false if it should not be a UIResource
uiResource
)

Get a derived color, derived colors are shared instances and will be updated when its parent UIDefault color changes.

private DerivedColor
getDerivedColor(String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource)

pack-priv SynthStyle
getStyle(JComponent
The component associated with this region. For example, if the Region is Region.Button then the component will be a JButton. If the Region is a subregion, such as ScrollBarThumb, then the associated component will be the component that subregion belongs to, such as JScrollBar. The JComponent may be named. It may not be null.
comp
,
Region
The region we are looking for a style for. May not be null.
r
)

Locate the style associated with the given region, and component.

pack-priv void
initialize()

Called by UIManager when this look and feel is installed.

pack-priv void
initializeDefaults(UIDefaults
UIDefaults table to initialize. This will never be null. If listeners are attached to d, then you will only receive notification of LookAndFeel level defaults, not all defaults on the UIManager.
d
)

Called from NimbusLookAndFeel to initialize the UIDefaults.

pack-priv void
register(Region
The Synth Region that is being registered. Such as Button, or ScrollBarThumb.
region
,
String
The UIDefault prefix. For example, could be ComboBox, or if a named components, "MyComboBox", or even something like ToolBar:"MyComboBox":"ComboBox.arrowButton"
prefix
)

Registers the given region and prefix.

pack-priv void
uninitialize()

Called by UIManager when this look and feel is uninstalled.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

colorTreeback to summary
private NimbusDefaults.ColorTree colorTree
defaultFontback to summary
private FontUIResource defaultFont

The default font that will be used. I store this value so that it can be set in the UIDefaults when requested.

defaultsListenerback to summary
private NimbusDefaults.DefaultsListener defaultsListener

Listener for changes to user defaults table

defaultStyleback to summary
private DefaultSynthStyle defaultStyle

Our fallback style to avoid NPEs if the proper style cannot be found in this class. Not sure if relying on DefaultSynthStyle is the best choice.

derivedColorsback to summary
private Map<DerivedColor, DerivedColor> derivedColors
mback to summary
private Map<Region, List<NimbusDefaults.LazyStyle>> m

The map of SynthStyles. This map is keyed by Region. Each Region maps to a List of LazyStyles. Each LazyStyle has a reference to the prefix that was registered with it. This reference can then be inspected to see if it is the proper lazy style.

There can be more than one LazyStyle for a single Region if there is more than one prefix defined for a given region. For example, both Button and "MyButton" might be prefixes assigned to the Region.Button region.

overridesCacheback to summary
private Map<JComponent, Map<Region, SynthStyle>> overridesCache
registeredRegionsback to summary
private Map<String, Region> registeredRegions

A map of regions which have been registered. This mapping is maintained so that the Region can be found based on prefix in a very fast manner. This is used in the "matches" method of LazyStyle.

Constructor Detail

NimbusDefaultsback to summary
pack-priv NimbusDefaults()

Create a new NimbusDefaults. This constructor is only called from within NimbusLookAndFeel.

Method Detail

addColorback to summary
private void addColor(UIDefaults d, String uin, int r, int g, int b, int a)
addColorback to summary
private void addColor(UIDefaults d, String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset)
addColorback to summary
private void addColor(UIDefaults d, String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource)
clearOverridesCacheback to summary
public void clearOverridesCache(JComponent c)
getDerivedColorback to summary
public DerivedColor getDerivedColor(String parentUin, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource)

Get a derived color, derived colors are shared instances and will be updated when its parent UIDefault color changes.

Parameters
parentUin:String

The parent UIDefault key

hOffset:float

The hue offset

sOffset:float

The saturation offset

bOffset:float

The brightness offset

aOffset:int

The alpha offset

uiResource:boolean

True if the derived color should be a UIResource, false if it should not be a UIResource

Returns:DerivedColor

The stored derived color

getDerivedColorback to summary
private DerivedColor getDerivedColor(String uin, String parentUin, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource)
getStyleback to summary
pack-priv SynthStyle getStyle(JComponent comp, Region r)

Locate the style associated with the given region, and component. This is called from NimbusLookAndFeel in the SynthStyleFactory implementation.

Lookup occurs as follows:
Check the map of styles m. If the map contains no styles at all, then simply return the defaultStyle. If the map contains styles, then iterate over all of the styles for the Region r looking for the best match, based on prefix. If a match was made, then return that SynthStyle. Otherwise, return the defaultStyle.

Parameters
comp:JComponent

The component associated with this region. For example, if the Region is Region.Button then the component will be a JButton. If the Region is a subregion, such as ScrollBarThumb, then the associated component will be the component that subregion belongs to, such as JScrollBar. The JComponent may be named. It may not be null.

r:Region

The region we are looking for a style for. May not be null.

initializeback to summary
pack-priv void initialize()

Called by UIManager when this look and feel is installed.

initializeDefaultsback to summary
pack-priv void initializeDefaults(UIDefaults d)

Called from NimbusLookAndFeel to initialize the UIDefaults.

Parameters
d:UIDefaults

UIDefaults table to initialize. This will never be null. If listeners are attached to d, then you will only receive notification of LookAndFeel level defaults, not all defaults on the UIManager.

registerback to summary
pack-priv void register(Region region, String prefix)

Registers the given region and prefix. The prefix, if it contains quoted sections, refers to certain named components. If there are not quoted sections, then the prefix refers to a generic component type.

If the given region/prefix combo has already been registered, then it will not be registered twice. The second registration attempt will fail silently.

Parameters
region:Region

The Synth Region that is being registered. Such as Button, or ScrollBarThumb.

prefix:String

The UIDefault prefix. For example, could be ComboBox, or if a named components, "MyComboBox", or even something like ToolBar:"MyComboBox":"ComboBox.arrowButton"

uninitializeback to summary
pack-priv void uninitialize()

Called by UIManager when this look and feel is uninstalled.

javax.swing.plaf.nimbus back to summary

private Class NimbusDefaults.ColorTree

extends Object
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private Map<String, NimbusDefaults.ColorTree.Node>
private NimbusDefaults.ColorTree.Node

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
addColor(String uin, Color color)

public Color
private NimbusDefaults.ColorTree.Node
public void
propertyChange(PropertyChangeEvent ev)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nodesback to summary
private Map<String, NimbusDefaults.ColorTree.Node> nodes
rootback to summary
private NimbusDefaults.ColorTree.Node root

Constructor Detail

ColorTreeback to summary
private ColorTree()

Method Detail

addColorback to summary
public void addColor(String uin, Color color)
getColorback to summary
public Color getColor(String uin)
getParentNodeback to summary
private NimbusDefaults.ColorTree.Node getParentNode(Color color)
propertyChangeback to summary
public void propertyChange(PropertyChangeEvent ev)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Annotations
@Override
updateback to summary
public void update()
javax.swing.plaf.nimbus back to summary

pack-priv Class NimbusDefaults.ColorTree.Node

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv List<NimbusDefaults.ColorTree.Node>
pack-priv Color
pack-priv NimbusDefaults.ColorTree.Node

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childrenback to summary
pack-priv List<NimbusDefaults.ColorTree.Node> children
colorback to summary
pack-priv Color color
parentback to summary
pack-priv NimbusDefaults.ColorTree.Node parent

Constructor Detail

Nodeback to summary
pack-priv Node(Color color, NimbusDefaults.ColorTree.Node parent)

Method Detail

setback to summary
public void set(Color color, NimbusDefaults.ColorTree.Node parent)
updateback to summary
public void update()
javax.swing.plaf.nimbus back to summary

private Class NimbusDefaults.DefaultsListener

extends Object
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener

Listener to update derived colors on UIManager Defaults changes

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
propertyChange(PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultsListenerback to summary
private DefaultsListener()

Method Detail

propertyChangeback to summary
public void propertyChange(PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Annotations
@Override
javax.swing.plaf.nimbus back to summary

pack-priv final Class NimbusDefaults.DerivedFont

extends Object
implements ActiveValue
Class Inheritance
All Implemented Interfaces
javax.swing.UIDefaults.ActiveValue

Derives its font value based on a parent font and a set of offsets and attributes. This class is an ActiveValue, meaning that it will recompute its value each time it is requested from UIDefaults. It is therefore recommended to read this value once and cache it in the UI delegate class until asked to reinitialize.

To use this class, create an instance with the key of the font in the UI defaults table from which to derive this font, along with a size offset (if any), and whether it is to be bold, italic, or left in its default form.

Field Summary

Modifier and TypeField and Description
private Boolean
private Boolean
private String
private float

Constructor Summary

AccessConstructor and Description
public
DerivedFont(String
The UIDefault key associated with this derived font's parent or source. If this key leads to a null value, or a value that is not a font, then null will be returned as the derived font. The key must not be null.
key
,
float
The size offset, as a percentage, to use. For example, if the source font was a 12pt font and the sizeOffset were specified as .9, then the new font will be 90% of what the source font was, or, 10.8 pts which is rounded to 11pts. This fractional based offset allows for proper font scaling in high DPI or large system font scenarios.
sizeOffset
,
Boolean
Whether the new font should be bold. If null, then this new font will inherit the bold setting of the source font.
bold
,
Boolean
Whether the new font should be italicized. If null, then this new font will inherit the italic setting of the source font.
italic
)

Create a new DerivedFont.

Method Summary

Modifier and TypeMethod and Description
public Object
createValue(UIDefaults defaults)

Implements javax.swing.UIDefaults.ActiveValue.createValue.

Creates the value retrieved from the UIDefaults table.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boldback to summary
private Boolean bold
italicback to summary
private Boolean italic
parentKeyback to summary
private String parentKey
sizeOffsetback to summary
private float sizeOffset

Constructor Detail

DerivedFontback to summary
public DerivedFont(String key, float sizeOffset, Boolean bold, Boolean italic)

Create a new DerivedFont.

Parameters
key:String

The UIDefault key associated with this derived font's parent or source. If this key leads to a null value, or a value that is not a font, then null will be returned as the derived font. The key must not be null.

sizeOffset:float

The size offset, as a percentage, to use. For example, if the source font was a 12pt font and the sizeOffset were specified as .9, then the new font will be 90% of what the source font was, or, 10.8 pts which is rounded to 11pts. This fractional based offset allows for proper font scaling in high DPI or large system font scenarios.

bold:Boolean

Whether the new font should be bold. If null, then this new font will inherit the bold setting of the source font.

italic:Boolean

Whether the new font should be italicized. If null, then this new font will inherit the italic setting of the source font.

Method Detail

createValueback to summary
public Object createValue(UIDefaults defaults)

Implements javax.swing.UIDefaults.ActiveValue.createValue.

Doc from javax.swing.UIDefaults.ActiveValue.createValue.

Creates the value retrieved from the UIDefaults table. The object is created each time it is accessed.

Annotations
@Override
javax.swing.plaf.nimbus back to summary

private final Class NimbusDefaults.LazyPainter

extends Object
implements LazyValue
Class Inheritance
All Implemented Interfaces
javax.swing.UIDefaults.LazyValue

This class is private because it relies on the constructor of the auto-generated AbstractRegionPainter subclasses. Hence, it is not generally useful, and is private.

LazyPainter is a LazyValue class. It will create the AbstractRegionPainter lazily, when asked. It uses reflection to load the proper class and invoke its constructor.

Field Summary

Modifier and TypeField and Description
private String
private AbstractRegionPainter.PaintContext
private int

Constructor Summary

AccessConstructor and Description
pack-priv
LazyPainter(String className, int which, Insets insets, Dimension canvasSize, boolean inverted)

pack-priv
LazyPainter(String className, int which, Insets insets, Dimension canvasSize, boolean inverted, AbstractRegionPainter.PaintContext.CacheMode cacheMode, double maxH, double maxV)

Method Summary

Modifier and TypeMethod and Description
public Object
createValue(UIDefaults table)

Implements javax.swing.UIDefaults.LazyValue.createValue.

Creates the actual value retrieved from the UIDefaults table.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameback to summary
private String className
ctxback to summary
private AbstractRegionPainter.PaintContext ctx
whichback to summary
private int which

Constructor Detail

LazyPainterback to summary
pack-priv LazyPainter(String className, int which, Insets insets, Dimension canvasSize, boolean inverted)
LazyPainterback to summary
pack-priv LazyPainter(String className, int which, Insets insets, Dimension canvasSize, boolean inverted, AbstractRegionPainter.PaintContext.CacheMode cacheMode, double maxH, double maxV)

Method Detail

createValueback to summary
public Object createValue(UIDefaults table)

Implements javax.swing.UIDefaults.LazyValue.createValue.

Doc from javax.swing.UIDefaults.LazyValue.createValue.

Creates the actual value retrieved from the UIDefaults table. When an object that implements this interface is retrieved from the table, this method is used to create the real value, which is then stored in the table and returned to the calling method.

Annotations
@Override
javax.swing.plaf.nimbus back to summary

private final Class NimbusDefaults.LazyStyle

extends Object
Class Inheritance

A class which creates the NimbusStyle associated with it lazily, but also manages a lot more information about the style. It is less of a LazyValue type of class, and more of an Entry or Item type of class, as it represents an entry in the list of LazyStyles in the map m. The primary responsibilities of this class include:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private NimbusDefaults.LazyStyle.Part[]
parts

The various parts, or sections, of the prefix.

private String
prefix

The prefix this LazyStyle was registered with.

private boolean
simple

Whether or not this LazyStyle represents an unnamed component

private NimbusStyle
style

Cached shared style.

Constructor Summary

AccessConstructor and Description
private
LazyStyle(String
The prefix associated with this style. Cannot be null.
prefix
)

Create a new LazyStyle.

Method Summary

Modifier and TypeMethod and Description
pack-priv SynthStyle

Returns:

the style
getStyle
(JComponent c, Region r)

Gets the style.

pack-priv boolean
matches(JComponent c)

This LazyStyle is a match for the given component if, and only if, for each part of the prefix the component hierarchy matches exactly.

private boolean
matches(Component c, int partIndex)

private List<String>
split(String prefix)

Given some dot separated prefix, split on the colons that are not within quotes, and not within brackets.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

partsback to summary
private NimbusDefaults.LazyStyle.Part[] parts

The various parts, or sections, of the prefix. For example, the prefix: ComboBox:"ComboBox.arrowButton" will be broken into two parts, ComboBox and "ComboBox.arrowButton"

prefixback to summary
private String prefix

The prefix this LazyStyle was registered with. Something like Button or ComboBox:"ComboBox.arrowButton"

simpleback to summary
private boolean simple

Whether or not this LazyStyle represents an unnamed component

styleback to summary
private NimbusStyle style

Cached shared style.

Constructor Detail

LazyStyleback to summary
private LazyStyle(String prefix)

Create a new LazyStyle.

Parameters
prefix:String

The prefix associated with this style. Cannot be null.

Method Detail

getStyleback to summary
pack-priv SynthStyle getStyle(JComponent c, Region r)

Gets the style. Creates it if necessary.

Returns:SynthStyle

the style

matchesback to summary
pack-priv boolean matches(JComponent c)

This LazyStyle is a match for the given component if, and only if, for each part of the prefix the component hierarchy matches exactly. That is, if given "a":something:"b", then: c.getName() must equals "b" c.getParent() can be anything c.getParent().getParent().getName() must equal "a".

matchesback to summary
private boolean matches(Component c, int partIndex)
splitback to summary
private List<String> split(String prefix)

Given some dot separated prefix, split on the colons that are not within quotes, and not within brackets.

javax.swing.plaf.nimbus back to summary

private final Class NimbusDefaults.LazyStyle.Part

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Class<?>
c

private boolean
private String
s

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

cback to summary
private Class<?> c
namedback to summary
private boolean named
sback to summary
private String s

Constructor Detail

Partback to summary
pack-priv Part(String s)
javax.swing.plaf.nimbus back to summary

private final Class NimbusDefaults.PainterBorder

extends Object
implements Border, UIResource
Class Inheritance
All Implemented Interfaces
javax.swing.plaf.UIResource, javax.swing.border.Border

Field Summary

Modifier and TypeField and Description
private Insets
private Painter<Component>
private String

Constructor Summary

AccessConstructor and Description
pack-priv
PainterBorder(String painterKey, Insets insets)

Method Summary

Modifier and TypeMethod and Description
public Insets
getBorderInsets(Component c)

Implements javax.swing.border.Border.getBorderInsets.

Returns the insets of the border.

public boolean
isBorderOpaque()

Implements javax.swing.border.Border.isBorderOpaque.

Returns whether or not the border is opaque.

public void
paintBorder(Component c, Graphics g, int x, int y, int w, int h)

Implements javax.swing.border.Border.paintBorder.

Paints the border for the specified component with the specified position and size.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

insetsback to summary
private Insets insets
painterback to summary
private Painter<Component> painter
painterKeyback to summary
private String painterKey

Constructor Detail

PainterBorderback to summary
pack-priv PainterBorder(String painterKey, Insets insets)

Method Detail

getBorderInsetsback to summary
public Insets getBorderInsets(Component c)

Implements javax.swing.border.Border.getBorderInsets.

Doc from javax.swing.border.Border.getBorderInsets.

Returns the insets of the border.

Annotations
@Override
isBorderOpaqueback to summary
public boolean isBorderOpaque()

Implements javax.swing.border.Border.isBorderOpaque.

Doc from javax.swing.border.Border.isBorderOpaque.

Returns whether or not the border is opaque. If the border is opaque, it is responsible for filling in it's own background when painting.

Annotations
@Override
paintBorderback to summary
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)

Implements javax.swing.border.Border.paintBorder.

Doc from javax.swing.border.Border.paintBorder.

Paints the border for the specified component with the specified position and size.

Annotations
@Override