public final class ComponentState
extends java.lang.Object
Instances of this class correspond to states of Swing core and custom controls. This class provides a number of predefined static instances to cover most action-based controls such as buttons, check boxes and menu items. In addition, application code can define custom component states that create fine grained mapping between arbitrary states of controls and specific color scheme bundles in custom skins.
Each component state is defined by two arrays of component state facets
(available in SubstanceSlices.ComponentStateFacet class). The first array specifies
the facets that are on, and the second array specifies the facets that
are off. For example, when a selected toggle button is pressed, it
transitions to PRESSED_SELECTED state. This state has
SubstanceSlices.ComponentStateFacet.ENABLE, SubstanceSlices.ComponentStateFacet.SELECTION and
SubstanceSlices.ComponentStateFacet.PRESS as its on facets. If a selected
toggle button is disabled, it has SubstanceSlices.ComponentStateFacet.SELECTION in
its on facets and SubstanceSlices.ComponentStateFacet.ENABLE in its off
facets.
The SubstanceSlices.ComponentStateFacet class defines a number of core facets. The
SubstanceSlices.ComponentStateFacet.ENABLE facet is universal - it is relevant for
all Swing controls. Some facets apply to a wider range of controls. For
example, SubstanceSlices.ComponentStateFacet.ROLLOVER facet applies to all controls
that can show rollover effects - including buttons, menu items, comboboxes,
sliders, scrollbars and many more. Some facets apply to a very narrow range
of controls. For example, SubstanceSlices.ComponentStateFacet.EDITABLE is only
relevant for editable controls, such as text components, editable comboboxes
or spinners.
The static instances of ComponentState defined in this class do not
aim to cover all possible combinations of on and off facets. In addition to
making this class too unwieldy, it is not possible to do since application
code can define its own facets. Instead, Substance provides three ways to
fine-tune the mapping between the component states and the color schemes used
to paint the components.
PRESSED_SELECTED - the
skinning layer first looks for the exact state (as passed to
SubstanceColorSchemeBundle.registerColorScheme(SubstanceColorScheme, SubstanceSlices.ColorSchemeAssociationKind, ComponentState...)
or similar APIs). If the exact match is found, it is used. If there is no
exact match, the skinning layer will look at all color schemes registered for
the specific color scheme association kind in the matching color scheme
bundle. The decision is made based on how "close" the registered component
state is to the component state of the currently painted component. For
example, PRESSED_SELECTED is a better match for
PRESSED_UNSELECTED than
ROLLOVER_SELECTED - since the
SubstanceSlices.ComponentStateFacet.PRESS has more weight than the
SubstanceSlices.ComponentStateFacet.ROLLOVER in the decision process. The skinning
layer will choose the "closest" registered component state that is
sufficiently close. For example, DISABLED_SELECTED
will never be chosen for SELECTED, even if there are
no other registered component states. This way the application code can
register a few color schemes in the specific bundle, and have all other
states "fall back" to the smaller subset of states.SubstanceSlices.ComponentStateFacet.DETERMINATE, or
SubstanceSlices.ComponentStateFacet.EDITABLE are relevant only for a small subset of
controls. In order to simplify the API signature of ComponentState,
these facets are not part of any of the predefined static states in this
class. Instead, they are used internally in the matching UI delegates (such
as for progress bar or text components) to find the best match among all the
registered states of the current skin. The specific skin can define its own
ComponentState instances that use these facets. For example,
NebulaAccentedSkin defines a number of component states that use the
SubstanceSlices.ComponentStateFacet.DETERMINATE facet, and maps the matching color
schemes. At runtime, the procedure described in the previous item will match
the state of the specific progress bar to the states defined in this skin,
and use the matching color schemes.SubstanceSlices.ComponentStateFacet class. In this
case, the application code can create its own facet instances, and its own
component states that use those facets in the on and off lists. Part of the
custom code will be in the UI delegates that compute the current state of the
custom component using the new facets. Other part of the custom code will be
in the skin definition that maps the component states defined with the new
facets to the specific color schemes.Note that you do not have to create explicit dependency between custom component states used in the skin definition and custom component states used in the painting routines (in the UI delegates). In fact, the custom component states defined in the Substance UI delegate for progress bar are not accessible to the application code. The recommended way to separate the skin definition from the model lookups in the painting is:
SubstanceSlices.ComponentStateFacet class.
When this (perhaps elaborate) state is passed to
SubstanceColorSchemeBundle.getColorScheme(SubstanceSlices.ColorSchemeAssociationKind, ComponentState, boolean)
API, the the procedure described above will match the this state to one of
the "base" states defined in your skin, and use the matching color scheme.Note that the matching algorithm only looks at the facets in the on and off lists, and ignores the component state name. This allows you to create a broad component state in your skin, and a number of narrow component states during the painting - and have the Substance skinning layer find the best match.
When the matching algorithm cannot find a sufficiently close match, the
skinning layer will fall back on one of the three base color schemes passed
to the
SubstanceColorSchemeBundle(SubstanceColorScheme, SubstanceColorScheme, SubstanceColorScheme)
constructor. States with SubstanceSlices.ComponentStateFacet.ENABLE in their off list
will fall back to the disabled color scheme. The
ENABLED will fall back to the enabled color scheme.
The rest of the states will fall back to the active color scheme. To change
the fallback behavior pass a non-null fallback color scheme to the
ComponentState(String, ComponentState, SubstanceSlices.ComponentStateFacet[], SubstanceSlices.ComponentStateFacet[])
constructor as the second parameter.
| Modifier and Type | Field | Description |
|---|---|---|
static ComponentState |
ARMED |
Armed.
|
static ComponentState |
DEFAULT |
Default.
|
static ComponentState |
DISABLED_DEFAULT |
Disabled default.
|
static ComponentState |
DISABLED_SELECTED |
Disabled selected.
|
static ComponentState |
DISABLED_UNSELECTED |
Disabled and not selected.
|
static ComponentState |
ENABLED |
Enabled state.
|
static ComponentState |
PRESSED_SELECTED |
Pressed selected.
|
static ComponentState |
PRESSED_UNSELECTED |
Pressed and not selected.
|
static ComponentState |
ROLLOVER_ARMED |
Armed and rolled over.
|
static ComponentState |
ROLLOVER_SELECTED |
Selected and rolled over.
|
static ComponentState |
ROLLOVER_UNSELECTED |
Not selected and rolled over.
|
static ComponentState |
SELECTED |
Selected.
|
| Constructor | Description |
|---|---|
ComponentState(java.lang.String name,
ComponentState hardFallback,
SubstanceSlices.ComponentStateFacet[] facetsOn,
SubstanceSlices.ComponentStateFacet[] facetsOff) |
Creates a new component state.
|
ComponentState(java.lang.String name,
SubstanceSlices.ComponentStateFacet[] facetsOn,
SubstanceSlices.ComponentStateFacet[] facetsOff) |
Creates a new component state.
|
| Modifier and Type | Method | Description |
|---|---|---|
ComponentState |
bestFit(java.util.Collection<ComponentState> states) |
|
boolean |
equals(java.lang.Object obj) |
|
static ComponentState[] |
getActiveStates() |
Returns all active component states.
|
static ComponentState[] |
getAllStates() |
Returns all component states.
|
ComponentState |
getHardFallback() |
|
static ComponentState |
getState(boolean isEnabled,
boolean isRollover,
boolean isSelected) |
Returns the component state that matches the specified parameters.
|
static ComponentState |
getState(javax.swing.AbstractButton button) |
Returns the state of the specified button.
|
static ComponentState |
getState(javax.swing.ButtonModel model,
javax.swing.JComponent component) |
Retrieves component state based on the button model (required parameter)
and component itself (optional parameter).
|
static ComponentState |
getState(javax.swing.ButtonModel model,
javax.swing.JComponent component,
boolean toIgnoreSelection) |
Retrieves component state based on the button model (required parameter)
and button itself (optional parameter).
|
int |
hashCode() |
|
boolean |
isActive() |
|
boolean |
isDisabled() |
Checks whether this state is disabled.
|
boolean |
isFacetActive(SubstanceSlices.ComponentStateFacet stateFacet) |
Returns indication whether
this component state is "active"
under the specified facet. |
java.lang.String |
toString() |
public static final ComponentState DISABLED_DEFAULT
default with JRootPane.setDefaultButton(JButton)
API.public static final ComponentState DEFAULT
default with JRootPane.setDefaultButton(JButton)
API.public static final ComponentState DISABLED_SELECTED
public static final ComponentState DISABLED_UNSELECTED
public static final ComponentState PRESSED_SELECTED
public static final ComponentState PRESSED_UNSELECTED
public static final ComponentState SELECTED
public static final ComponentState ROLLOVER_SELECTED
public static final ComponentState ARMED
public static final ComponentState ROLLOVER_ARMED
public static final ComponentState ROLLOVER_UNSELECTED
public static final ComponentState ENABLED
public ComponentState(java.lang.String name,
SubstanceSlices.ComponentStateFacet[] facetsOn,
SubstanceSlices.ComponentStateFacet[] facetsOff)
name - Component state name. Does not have to be unique. The name is
only used in the toString().facetsOn - Indicates that are turned on for this state. For example,
ROLLOVER_SELECTED should pass both
SubstanceSlices.ComponentStateFacet.ROLLOVER and
SubstanceSlices.ComponentStateFacet.SELECTION.facetsOff - Indicates that are turned on for this state. For example,
DISABLED_UNSELECTED should pass both
SubstanceSlices.ComponentStateFacet.ENABLE and
SubstanceSlices.ComponentStateFacet.SELECTION.public ComponentState(java.lang.String name,
ComponentState hardFallback,
SubstanceSlices.ComponentStateFacet[] facetsOn,
SubstanceSlices.ComponentStateFacet[] facetsOff)
name - Component state name. Does not have to be unique. The name is
only used in the toString().hardFallback - The fallback state that will be used in
SubstanceColorSchemeBundle.getColorScheme(SubstanceSlices.ColorSchemeAssociationKind, ComponentState, boolean)
in case bestFit(Collection) returns nullfacetsOn - Indicates that are turned on for this state. For example,
ROLLOVER_SELECTED should pass both
SubstanceSlices.ComponentStateFacet.ROLLOVER and
SubstanceSlices.ComponentStateFacet.SELECTION.facetsOff - Indicates that are turned on for this state. For example,
DISABLED_UNSELECTED should pass both
SubstanceSlices.ComponentStateFacet.ENABLE and
SubstanceSlices.ComponentStateFacet.SELECTION.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isFacetActive(SubstanceSlices.ComponentStateFacet stateFacet)
this component state is "active"
under the specified facet. For example, ROLLOVER_SELECTED will
return true for both SubstanceSlices.ComponentStateFacet.ROLLOVER
and SubstanceSlices.ComponentStateFacet.SELECTION.stateFacet - State facet.true if this component state is
"active" under the specified facet (for example,
ROLLOVER_SELECTED will return true for both
SubstanceSlices.ComponentStateFacet.ROLLOVER and
SubstanceSlices.ComponentStateFacet.SELECTION), false
otherwise.public boolean isDisabled()
SubstanceSlices.ComponentStateFacet.ENABLE facet in its off set.true if this state is disabled, false
otherwise.public static ComponentState[] getActiveStates()
ENABLED.public static ComponentState[] getAllStates()
public boolean isActive()
public static ComponentState getState(javax.swing.ButtonModel model, javax.swing.JComponent component)
model - Button model (required).component - Component (optional).public static ComponentState getState(javax.swing.AbstractButton button)
button - Button.public static ComponentState getState(javax.swing.ButtonModel model, javax.swing.JComponent component, boolean toIgnoreSelection)
model - Button model (required).component - Component (optional).toIgnoreSelection - If true, the ButtonModel.isSelected()
will not be checked. This can be used for tracking transitions
on menu items that use armed state instead, when
we don't want to use different rollover themes for selected
and unselected checkbox and radio button menu items (to
preserve consistent visual appearence of highlights).public static ComponentState getState(boolean isEnabled, boolean isRollover, boolean isSelected)
isEnabled - Enabled flag.isRollover - Rollover flag.isSelected - Selected flag.public ComponentState bestFit(java.util.Collection<ComponentState> states)
public ComponentState getHardFallback()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object