Class CapsLockSupport
java.lang.Object
org.jdesktop.beans.AbstractBean
org.jdesktop.swingx.plaf.basic.CapsLockSupport
- All Implemented Interfaces:
KeyEventDispatcher
A class for determining the state of the
. It also supports notification when the locking state changes.
invalid reference
CAPS LOCK
key
Although it is possible to use Toolkit.getLockingKeyState(int) to determine the current
state of the CAPS LOCK key, that method is not guaranteed to work on all platforms. This class
attempts to handle those shortfalls and provide an easy mechanism for listening to state changes.
CapsLockSupport cls = CapsLockSupport.getInstance();
// for get the current state of the caps lock key
boolean currentState = cls.isCapsLockEnabled();
// for listening to changes in the caps lock state
cls.addPropertyChangeListener("capsLockEnabled", myListener);
There is one special case to be aware of. If CapsLockSupport is not able to determine the
state of the CAPS LOCK key, then isInitialized() will return false until it is
able to introspect a KeyEvent and determine the current locking state. If
CapsLockSupport must use delayed initialization, it will fire a property change to notify
listeners that it is now in an accurate state.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis is an implementation detail and should not be considered public.static CapsLockSupportGets the only instance ofCapsLockSupport.booleanDetermines the current state of the.invalid reference
CAPS LOCK keybooleanDetermines ifCapsLockSupportis accurately synchronized with the state of the CAPS LOCK key.(package private) voidsetCapsLockEnabled(boolean capsLockEnabled) Methods inherited from class AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
useToolkit
private boolean useToolkit -
capsLockeEnabled
private boolean capsLockeEnabled -
updateViaKeyEvent
private boolean updateViaKeyEvent
-
-
Constructor Details
-
CapsLockSupport
private CapsLockSupport()
-
-
Method Details
-
getInstance
Gets the only instance ofCapsLockSupport.- Returns:
- the
CapsLockSupportinstance
-
isInitialized
public boolean isInitialized()Determines ifCapsLockSupportis accurately synchronized with the state of the CAPS LOCK key. When not initialized,isCapsLockEnabled()will always returnfalse.CapsLockSupportwill fail to initialize only ifToolkit#getLockingKeyState(int)throws an exception; in that case, it will initialize as soon as it receives a valid key event (that can be used to determine the current locking state).- Returns:
trueifCapsLockSupportaccurately knows the state of the CAPS LOCK key
-
isCapsLockEnabled
public boolean isCapsLockEnabled()Determines the current state of the.invalid reference
CAPS LOCK key- Returns:
trueif CAPS LOCK is enabled;falseotherwise
-
setCapsLockEnabled
void setCapsLockEnabled(boolean capsLockEnabled) -
dispatchKeyEvent
This is an implementation detail and should not be considered public.- Specified by:
dispatchKeyEventin interfaceKeyEventDispatcher
-