Top Description Inners Fields Constructors Methods
javax.swing.plaf.nimbus

public abstract Class State<T extends JComponent>

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.nimbus.State.StandardState, javax.swing.plaf.nimbus.ComboBoxArrowButtonEditableState, javax.swing.plaf.nimbus.ComboBoxEditableState, javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonWindowNotFocusedState, javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonWindowMaximizedState, javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonWindowNotFocusedState, javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonWindowNotFocusedState, javax.swing.plaf.nimbus.InternalFrameTitlePaneWindowFocusedState, javax.swing.plaf.nimbus.InternalFrameWindowFocusedState, javax.swing.plaf.nimbus.ProgressBarFinishedState, javax.swing.plaf.nimbus.ProgressBarIndeterminateState, javax.swing.plaf.nimbus.SliderArrowShapeState, javax.swing.plaf.nimbus.SliderThumbArrowShapeState, javax.swing.plaf.nimbus.SliderTrackArrowShapeState, javax.swing.plaf.nimbus.SplitPaneDividerVerticalState, javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonWindowNotFocusedState, javax.swing.plaf.nimbus.SplitPaneVerticalState, javax.swing.plaf.nimbus.TableHeaderRendererSortedState, javax.swing.plaf.nimbus.TextAreaNotInScrollPaneState, javax.swing.plaf.nimbus.ToolBarEastState, javax.swing.plaf.nimbus.ToolBarNorthState, javax.swing.plaf.nimbus.ToolBarSouthState, javax.swing.plaf.nimbus.ToolBarWestState
Type Parameters
<T>
type of component whose state is to be queried
Imports
java.util.HashMap, .Map, javax.swing.JComponent, javax.swing.plaf.synth.SynthConstants

Represents a built in, or custom, state in Nimbus.

Synth provides several built in states, which are:

However, there are many more states that could be described in a LookAndFeel, and it would be nice to style components differently based on these different states. For example, a progress bar could be "indeterminate". It would be very convenient to allow this to be defined as a "state".

This class, State, is intended to be used for such situations. Simply implement the abstract #isInState method. It returns true if the given JComponent is "in this state", false otherwise. This method will be called many times in performance sensitive loops. It must execute very quickly.

For example, the following might be an implementation of a custom "Indeterminate" state for JProgressBars:


    public final class IndeterminateState extends State<JProgressBar> {
        public IndeterminateState() {
            super("Indeterminate");
        }

        @Override
        protected boolean isInState(JProgressBar c) {
            return c.isIndeterminate();
        }
    }

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final State<JComponent>
pack-priv static final State<JComponent>
pack-priv static final State<JComponent>
pack-priv static final State<JComponent>
pack-priv static final State<JComponent>
private String
pack-priv static final State<JComponent>
pack-priv static final State<JComponent>
pack-priv static final Map<String, State.StandardState>

Constructor Summary

AccessConstructor and Description
protected
State(String
a simple user friendly name for the state, such as "Indeterminate" or "EmbeddedPanel" or "Blurred". It is customary to use camel case, with the first letter capitalized.
name
)

Create a new custom State.

Method Summary

Modifier and TypeMethod and Description
pack-priv String
pack-priv static State.StandardState
pack-priv boolean
isInState(T c, int s)

This is the main entry point, called by NimbusStyle.

protected abstract boolean

Returns:

true if c is in the custom state represented by this State instance
isInState
(T
the JComponent to test. This will never be null.
c
)

Gets whether the specified JComponent is in the custom state represented by this class.

pack-priv static boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

Defaultback to summary
pack-priv static final State<JComponent> Default
Disabledback to summary
pack-priv static final State<JComponent> Disabled
Enabledback to summary
pack-priv static final State<JComponent> Enabled
Focusedback to summary
pack-priv static final State<JComponent> Focused
MouseOverback to summary
pack-priv static final State<JComponent> MouseOver
nameback to summary
private String name
Pressedback to summary
pack-priv static final State<JComponent> Pressed
Selectedback to summary
pack-priv static final State<JComponent> Selected
standardStatesback to summary
pack-priv static final Map<String, State.StandardState> standardStates

Constructor Detail

Stateback to summary
protected State(String name)

Create a new custom State. Specify the name for the state. The name should be unique within the states set for any one particular component. The name of the state should coincide with the name used in UIDefaults.

For example, the following would be correct:


    defaults.put("Button.States", "Enabled, Foo, Disabled");
    defaults.put("Button.Foo", new FooState("Foo"));
Parameters
name:String

a simple user friendly name for the state, such as "Indeterminate" or "EmbeddedPanel" or "Blurred". It is customary to use camel case, with the first letter capitalized.

Method Detail

getNameback to summary
pack-priv String getName()
getStandardStateback to summary
pack-priv static State.StandardState getStandardState(String name)
isInStateback to summary
pack-priv boolean isInState(T c, int s)

This is the main entry point, called by NimbusStyle.

There are both custom states and standard states. Standard states correlate to the states defined in SynthConstants. When a UI delegate constructs a SynthContext, it specifies the state that the component is in according to the states defined in SynthConstants. Our NimbusStyle will then take this state, and query each State instance in the style asking whether isInState(c, s).

Now, only the standard states care about the "s" param. So we have this odd arrangement:

  • NimbusStyle calls State.isInState(c, s)
  • State.isInState(c, s) simply delegates to State.isInState(c)
  • EXCEPT, StandardState overrides State.isInState(c, s) and returns directly from that method after checking its state, and does not call isInState(c) (since it is not needed for standard states).
isInStateback to summary
protected abstract boolean isInState(T c)

Gets whether the specified JComponent is in the custom state represented by this class. This is an extremely performance sensitive loop. Please take proper precautions to ensure that it executes quickly.

Nimbus uses this method to help determine what state a JComponent is in. For example, a custom State could exist for JProgressBar such that it would return true when the progress bar is indeterminate. Such an implementation of this method would simply be:

 return c.isIndeterminate();
Parameters
c:T

the JComponent to test. This will never be null.

Returns:boolean

true if c is in the custom state represented by this State instance

isStandardStateNameback to summary
pack-priv static boolean isStandardStateName(String name)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

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

pack-priv final Class State.StandardState

extends State<JComponent>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
Inherited from javax.swing.plaf.nimbus.State:
DefaultDisabledEnabledFocusedMouseOverPressedSelectedstandardStates

Constructor Summary

AccessConstructor and Description
private
StandardState(int state)

Method Summary

Modifier and TypeMethod and Description
public int
pack-priv boolean
isInState(JComponent c, int s)

Overrides javax.swing.plaf.nimbus.State.isInState.

This is the main entry point, called by NimbusStyle.

protected boolean
isInState(JComponent
the JComponent to test. This will never be null.
c
)

Implements abstract javax.swing.plaf.nimbus.State.isInState.

Gets whether the specified JComponent is in the custom state represented by this class.

private static String
toString(int state)

Inherited from javax.swing.plaf.nimbus.State:
getNamegetStandardStateisStandardStateNametoString

Field Detail

stateback to summary
private int state

Constructor Detail

StandardStateback to summary
private StandardState(int state)

Method Detail

getStateback to summary
public int getState()
isInStateback to summary
pack-priv boolean isInState(JComponent c, int s)

Overrides javax.swing.plaf.nimbus.State.isInState.

Doc from javax.swing.plaf.nimbus.State.isInState.

This is the main entry point, called by NimbusStyle.

There are both custom states and standard states. Standard states correlate to the states defined in SynthConstants. When a UI delegate constructs a SynthContext, it specifies the state that the component is in according to the states defined in SynthConstants. Our NimbusStyle will then take this state, and query each State instance in the style asking whether isInState(c, s).

Now, only the standard states care about the "s" param. So we have this odd arrangement:

  • NimbusStyle calls State.isInState(c, s)
  • State.isInState(c, s) simply delegates to State.isInState(c)
  • EXCEPT, StandardState overrides State.isInState(c, s) and returns directly from that method after checking its state, and does not call isInState(c) (since it is not needed for standard states).
Annotations
@Override
isInStateback to summary
protected boolean isInState(JComponent c)

Implements abstract javax.swing.plaf.nimbus.State.isInState.

Doc from javax.swing.plaf.nimbus.State.isInState.

Gets whether the specified JComponent is in the custom state represented by this class. This is an extremely performance sensitive loop. Please take proper precautions to ensure that it executes quickly.

Nimbus uses this method to help determine what state a JComponent is in. For example, a custom State could exist for JProgressBar such that it would return true when the progress bar is indeterminate. Such an implementation of this method would simply be:

 return c.isIndeterminate();
Parameters
c:JComponent

the JComponent to test. This will never be null.

Returns:boolean

true if c is in the custom state represented by this State instance

Annotations
@Override
toStringback to summary
private static String toString(int state)