A SynthStyle implementation used by Nimbus. Each Region that has been registered with the NimbusLookAndFeel will have an associated NimbusStyle. Third party components that are registered with the NimbusLookAndFeel will therefore be handed a NimbusStyle from the look and feel from the #getStyle(JComponent, Region) method.
This class properly reads and retrieves values placed in the UIDefaults according to the standard Nimbus naming conventions. It will create and retrieve painters, fonts, colors, and other data stored there.
NimbusStyle also supports the ability to override settings on a per component basis. NimbusStyle checks the component's client property map for "Nimbus.Overrides". If the value associated with this key is an instance of UIDefaults, then the values in that defaults table will override the standard Nimbus defaults in UIManager, but for that component instance only.
Optionally, you may specify the client property "Nimbus.Overrides.InheritDefaults". If true, this client property indicates that the defaults located in UIManager should first be read, and then replaced with defaults located in the component client properties. If false, then only the defaults located in the component client property map will be used. If not specified, it is assumed to be true.
You must specify "Nimbus.Overrides" for "Nimbus.Overrides.InheritDefaults" to have any effect. "Nimbus.Overrides" indicates whether there are any overrides, while "Nimbus.Overrides.InheritDefaults" indicates whether those overrides should first be initialized with the defaults from UIManager.
The NimbusStyle is reloaded whenever a property change event is fired for a component for "Nimbus.Overrides" or "Nimbus.Overrides.InheritDefaults". So for example, setting a new UIDefaults on a component would cause the style to be reloaded.
The values are only read out of UIManager once, and then cached. If you need to read the values again (for example, if the UI is being reloaded), then discard this NimbusStyle and read a new one from NimbusLookAndFeel using NimbusLookAndFeel.getStyle.
The primary API of interest in this class for 3rd party component authors are the three methods which retrieve painters: #getBackgroundPainter, #getForegroundPainter, and #getBorderPainter.
NimbusStyle allows you to specify custom states, or modify the order of states. Synth (and thus Nimbus) has the concept of a "state". For example, a JButton might be in the "MOUSE_OVER" state, or the "ENABLED" state, or the "DISABLED" state. These are all "standard" states which are defined in synth, and which apply to all synth Regions.
Sometimes, however, you need to have a custom state. For example, you want JButton to render differently if it's parent is a JToolbar. In Nimbus, you specify these custom states by including a special key in UIDefaults. The following UIDefaults entries define three states for this button:
JButton.States = Enabled, Disabled, Toolbar
JButton[Enabled].backgroundPainter = somePainter
JButton[Disabled].background = BLUE
JButton[Toolbar].backgroundPainter = someOtherPaint
As you can see, the JButton.States entry lists the states
that the JButton style will support. You then specify the settings for
each state. If you do not specify the JButton.States entry,
then the standard Synth states will be assumed. If you specify the entry
but the list of states is empty or null, then the standard synth states
will be assumed.
| Modifier and Type | Class and Description |
|---|---|
| private static class | NimbusStyle.
This implementation presupposes that key is never null and that the two keys being checked for equality are never null |
| private static class | NimbusStyle.
Contains values such as the UIDefaults and painters associated with a state. |
| private static class | NimbusStyle.
Essentially a struct of data for a style. |
| Modifier and Type | Field and Description |
|---|---|
| private WeakReference | component
Some NimbusStyles are created for a specific component only. |
| private static final Color | DEFAULT_COLOR
The Color to return from getColorForState if it would otherwise have returned null. |
| public static final String | LARGE_KEY
Large key |
| public static final double | LARGE_SCALE
Large scale |
| public static final String | MINI_KEY
Mini key |
| public static final double | MINI_SCALE
Mini scale |
| private static final Object | NULL
Special constant used for performance reasons during the get() method. |
| private SynthPainter | painter
The SynthPainter that will be returned from this NimbusStyle. |
| private String | prefix
The prefix for the component or region that this NimbusStyle represents. |
| public static final String | SMALL_KEY
Small key |
| public static final double | SMALL_SCALE
Small scale |
| private static final Comparator | STATE_COMPARATOR
Simple Comparator for ordering the RuntimeStates according to their rank. |
| private NimbusStyle. | tmpKey
A temporary CacheKey used to perform lookups. |
| private NimbusStyle. | values
Data structure containing all of the defaults, insets, states, and other values associated with this style. |
| Access | Constructor and Description |
|---|---|
| pack-priv | NimbusStyle(String
Something like Button or Slider.Thumb or
org.jdesktop.swingx.JXStatusBar or ComboBox."ComboBox.arrowButton" prefix, JComponent an optional reference to a component that this NimbusStyle
should be associated with. This is only used when the component
has Nimbus overrides registered in its client properties and
should be null otherwise. c)Create a new NimbusStyle. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| public Object | get(SynthContext
SynthContext identifying requester ctx, Object must not be null key)Overrides javax. Getter for a region specific style property. |
| public Painter | Returns: The background painter associated for the given state, or null if none could be found.The SynthContext. Must not be null. ctx)Gets the appropriate background Painter, if there is one, for the state specified in the given SynthContext. |
| public Painter | Returns: The border painter associated for the given state, or null if none could be found.The SynthContext. Must not be null. ctx)Gets the appropriate border Painter, if there is one, for the state specified in the given SynthContext. |
| protected Color | getColorForState(SynthContext ctx, ColorType type)
Implements abstract javax. Returns the color for the specified state. |
| private int | getExtendedState(SynthContext ctx, NimbusStyle.
Gets the extended state for a given synth context. |
| protected Font | getFontForState(SynthContext ctx)
Implements abstract javax. Returns the font for the specified state. |
| public Painter | Returns: The foreground painter associated for the given state, or null if none could be found.The SynthContext. Must not be null. ctx)Gets the appropriate foreground Painter, if there is one, for the state specified in the given SynthContext. |
| public Insets | getInsets(SynthContext ctx, Insets in)
Overrides javax. Returns the Insets that are used to calculate sizing information. |
| private NimbusStyle. | getNextState(NimbusStyle.
a 1 element array, allowing me to do pass-by-reference. lastState, int xstate)Gets the RuntimeState that most closely matches the state in the given context, but is less specific than the given "lastState". |
| private Painter | |
| public SynthPainter | getPainter(SynthContext ctx)
Overrides javax. Returns the |
| private NimbusStyle. | Returns: a non-null values referenceThe SynthContext ctx)Utility method which returns the proper Values based on the given SynthContext. |
| public void | installDefaults(SynthContext ctx)
Overrides javax. Installs the necessary state from this Style on the
|
| public boolean | isOpaque(SynthContext ctx)
Overrides javax. Returns true if the region is opaque. |
| private static Painter | |
| private void | validate()
Pulls data out of UIDefaults, if it has not done so already, and sets up the internal state. |
| component | back to summary |
|---|---|
| private WeakReference<JComponent> component Some NimbusStyles are created for a specific component only. In Nimbus, this happens whenever the component has as a client property a UIDefaults which overrides (or supplements) those defaults found in UIManager. | |
| DEFAULT_COLOR | back to summary |
|---|---|
| private static final Color DEFAULT_COLOR The Color to return from getColorForState if it would otherwise have returned null. Returning null from getColorForState is a very bad thing, as it causes
the AWT peer for the component to install a SystemColor, which is not a
UIResource. As a result, if | |
| LARGE_KEY | back to summary |
|---|---|
| public static final String LARGE_KEY Large key | |
| LARGE_SCALE | back to summary |
|---|---|
| public static final double LARGE_SCALE Large scale | |
| MINI_KEY | back to summary |
|---|---|
| public static final String MINI_KEY Mini key | |
| MINI_SCALE | back to summary |
|---|---|
| public static final double MINI_SCALE Mini scale | |
| NULL | back to summary |
|---|---|
| private static final Object NULL Special constant used for performance reasons during the get() method. If get() runs through all of the search locations and determines that there is no value, then NULL will be placed into the values map. This way on subsequent lookups it will simply extract NULL, see it, and return null rather than continuing the lookup procedure. | |
| painter | back to summary |
|---|---|
| private SynthPainter painter The SynthPainter that will be returned from this NimbusStyle. The SynthPainter returned will be a SynthPainterImpl, which will in turn delegate back to this NimbusStyle for the proper Painter (not SynthPainter) to use for painting the foreground, background, or border. | |
| prefix | back to summary |
|---|---|
| private String prefix The prefix for the component or region that this NimbusStyle represents. This prefix is used to lookup state in the UIManager. It should be something like Button or Slider.Thumb or "MyButton" or ComboBox."ComboBox.arrowButton" or "MyComboBox"."ComboBox.arrowButton" | |
| SMALL_KEY | back to summary |
|---|---|
| public static final String SMALL_KEY Small key | |
| SMALL_SCALE | back to summary |
|---|---|
| public static final double SMALL_SCALE Small scale | |
| STATE_COMPARATOR | back to summary |
|---|---|
| private static final Comparator<NimbusStyle. Simple Comparator for ordering the RuntimeStates according to their rank. | |
| tmpKey | back to summary |
|---|---|
| private NimbusStyle. A temporary CacheKey used to perform lookups. This pattern avoids creating useless garbage keys, or concatenating strings, etc. | |
| values | back to summary |
|---|---|
| private NimbusStyle. Data structure containing all of the defaults, insets, states, and other values associated with this style. This instance refers to default values, and are used when no overrides are discovered in the client properties of a component. These values are lazily created on first access. | |
| NimbusStyle | back to summary |
|---|---|
| pack-priv NimbusStyle(String prefix, JComponent c) Create a new NimbusStyle. Only the prefix must be supplied. At the appropriate time, installDefaults will be called. At that point, all of the state information will be pulled from UIManager and stored locally within this style.
| |
| contains | back to summary |
|---|---|
| private boolean contains(String[] names, String name) Simple utility method that searches the given array of Strings for the given string. This method is only called from getExtendedState if the developer has specified a specific state for the component to be in (ie, has "wedged" the component in that state) by specifying they client property "Nimbus.State". | |
| get | back to summary |
|---|---|
| public Object get(SynthContext ctx, Object key) Overrides javax. Doc from javax. Getter for a region specific style property. Overridden to cause this style to populate itself with data from UIDefaults, if necessary. Properties in UIDefaults may be specified in a chained manner. For example: background Button.opacity Button.Enabled.foreground Button.Enabled+Selected.background In this example, suppose you were in the Enabled+Selected state and searched for "foreground". In this case, we first check for Button.Enabled+Selected.foreground, but no such color exists. We then fall back to the next valid state, in this case, Button.Enabled.foreground, and have a match. So we return it. Again, if we were in the state Enabled and looked for "background", we wouldn't find it in Button.Enabled, or in Button, but would at the top level in UIManager. So we return that value. One special note: the "key" passed to this method could be of the form "background" or "Button.background" where "Button" equals the prefix passed to the NimbusStyle constructor. In either case, it looks for "background".
| |
| getBackgroundPainter | back to summary |
|---|---|
| public Painter Gets the appropriate background Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.
| |
| getBorderPainter | back to summary |
|---|---|
| public Painter Gets the appropriate border Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.
| |
| getColorForState | back to summary |
|---|---|
| protected Color getColorForState(SynthContext ctx, ColorType type) Implements abstract javax. Doc from javax. Returns the color for the specified state. This should NOT call any
methods on the Overridden to cause this style to populate itself with data from UIDefaults, if necessary. In addition, NimbusStyle handles ColorTypes slightly differently from Synth.
| |
| getExtendedState | back to summary |
|---|---|
| private int getExtendedState(SynthContext ctx, NimbusStyle. Gets the extended state for a given synth context. Nimbus supports the ability to define custom states. The algorithm used for choosing what style information to use for a given state requires a single integer bit string where each bit in the integer represents a different state that the component is in. This method uses the componentState as reported in the SynthContext, in addition to custom states, to determine what this extended state is. In addition, this method checks the component in the given context for a client property called "Nimbus.State". If one exists, then it will decompose the String associated with that property to determine what state to return. In this way, the developer can force a component to be in a specific state, regardless of what the "real" state of the component is. The string associated with "Nimbus.State" would be of the form: Enabled+CustomState+MouseOver
| |
| getFontForState | back to summary |
|---|---|
| protected Font getFontForState(SynthContext ctx) Implements abstract javax. Doc from javax. Returns the font for the specified state. This should NOT call any
method on the
| |
| getForegroundPainter | back to summary |
|---|---|
| public Painter Gets the appropriate foreground Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.
| |
| getInsets | back to summary |
|---|---|
| public Insets getInsets(SynthContext ctx, Insets in) Overrides javax. Doc from javax. Returns the Insets that are used to calculate sizing information. Overridden to cause this style to populate itself with data from UIDefaults, if necessary.
| |
| getNextState | back to summary |
|---|---|
| private NimbusStyle. Gets the RuntimeState that most closely matches the state in the given context, but is less specific than the given "lastState". Essentially, this allows you to search for the next best state. For example, if you had the following three states: Enabled Enabled+Pressed DisabledAnd you wanted to find the state that best represented ENABLED+PRESSED+FOCUSED and lastState was null (or an
empty array, or an array with a single int with index == -1), then
Enabled+Pressed would be returned. If you then call this method again but
pass the index of Enabled+Pressed as the "lastState", then
Enabled would be returned. If you call this method a third time and pass
the index of Enabled in as the lastState, then null would be
returned.
The actual code path for determining the proper state is the same as in Synth.
| |
| getPainter | back to summary |
|---|---|
| private Painter | |
| getPainter | back to summary |
|---|---|
| public SynthPainter getPainter(SynthContext ctx) Overrides javax. Doc from javax. Returns the
| |
| getValues | back to summary |
|---|---|
| private NimbusStyle. Utility method which returns the proper Values based on the given SynthContext. Ensures that parsing of the values has occurred, or reoccurs as necessary.
| |
| installDefaults | back to summary |
|---|---|
| public void installDefaults(SynthContext ctx) Overrides javax. Doc from javax. Installs the necessary state from this Style on the
| |
| isOpaque | back to summary |
|---|---|
| public boolean isOpaque(SynthContext ctx) Overrides javax. Doc from javax. Returns true if the region is opaque. Overridden to cause this style to populate itself with data from UIDefaults, if necessary. If opacity is not specified in UI defaults, then it defaults to being non-opaque.
| |
| paintFilter | back to summary |
|---|---|
private static Painter
| |
| validate | back to summary |
|---|---|
| private void validate() Pulls data out of UIDefaults, if it has not done so already, and sets up the internal state. | |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | |
| pack-priv void |
| CacheKey | back to summary |
|---|---|
| pack-priv CacheKey(Object key, int xstate) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| init | back to summary |
|---|---|
| pack-priv void init(Object key, int xstate) | |
State represents a distinct state that a
component can be in (such as Enabled), this class represents the colors,
fonts, painters, etc associated with some state for this
style.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Painter | |
| pack-priv Painter | |
| pack-priv UIDefaults | |
| pack-priv Painter | |
| pack-priv int | |
| pack-priv String |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public NimbusStyle. | |
| public String |
| backgroundPainter | back to summary |
|---|---|
| pack-priv Painter<Object> backgroundPainter | |
| borderPainter | back to summary |
|---|---|
| pack-priv Painter<Object> borderPainter | |
| defaults | back to summary |
|---|---|
| pack-priv UIDefaults defaults | |
| foregroundPainter | back to summary |
|---|---|
| pack-priv Painter<Object> foregroundPainter | |
| state | back to summary |
|---|---|
| pack-priv int state | |
| stateName | back to summary |
|---|---|
| pack-priv String stateName | |
| RuntimeState | back to summary |
|---|---|
| private RuntimeState(int state, String stateName) | |
| clone | back to summary |
|---|---|
| public NimbusStyle. Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Map | cache
Simple cache. |
| pack-priv Insets | contentMargins
The content margins for this region. |
| pack-priv UIDefaults | defaults
Defaults on the region/component level. |
| pack-priv NimbusStyle. | states
The list of actual runtime state representations. |
| pack-priv State | stateTypes
The list of State types. |
| Access | Constructor and Description |
|---|---|
| private |
| cache | back to summary |
|---|---|
| pack-priv Map<NimbusStyle. Simple cache. After a value has been looked up, it is stored in this cache for later retrieval. The key is a concatenation of the property being looked up, two dollar signs, and the extended state. So for example: foo.bar$$2353 | |
| contentMargins | back to summary |
|---|---|
| pack-priv Insets contentMargins The content margins for this region. | |
| defaults | back to summary |
|---|---|
| pack-priv UIDefaults defaults Defaults on the region/component level. | |
| states | back to summary |
|---|---|
| pack-priv NimbusStyle. The list of actual runtime state representations. These can represent things such as Enabled + Focused. Thus, they differ from States in that they contain several states together, and have associated properties, data, etc. | |
| stateTypes | back to summary |
|---|---|
| pack-priv State<?>[] stateTypes The list of State types. A State represents a type of state, such as Enabled, Default, WindowFocused, etc. These can be custom states. | |
| Values | back to summary |
|---|---|
| private Values() | |