public class FocusManager
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.ref.WeakReference<java.awt.Component> |
focusOwner
Reference to currently focused component.
|
protected static java.util.List<GlobalFocusListener> |
globalFocusListeners
Global focus listeners list.
|
protected static boolean |
initialized
Whether manager is initialized or not.
|
protected static java.lang.Object |
listenersLock
Global focus listeners lock.
|
protected static java.lang.ref.WeakReference<java.awt.Component> |
oldFocusOwner
Reference to previously focused component.
|
protected static java.util.Map<java.awt.Component,java.util.Map<FocusTracker,java.lang.Boolean>> |
trackers
Focus trackers list.
|
protected static java.lang.Object |
trackersLock
Tracker list and cache lock.
|
| Constructor and Description |
|---|
FocusManager() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addFocusTracker(java.awt.Component component,
FocusTracker focusTracker)
Registers focus tracker.
|
protected static void |
fireGlobalFocusChanged(java.awt.Component oldComponent,
java.awt.Component newComponent)
Fires about global focus change.
|
static java.awt.Component |
getFocusOwner()
Returns currently focused component.
|
static java.awt.Component |
getOldFocusOwner()
Returns previously focused component.
|
protected static java.util.Map<java.awt.Component,java.util.Map<FocusTracker,java.lang.Boolean>> |
getTrackersCopy()
Returns trackers map copy.
|
static void |
initialize()
Initializes manager if it wasn't already initialized.
|
static void |
registerGlobalFocusListener(GlobalFocusListener listener)
Registers global focus listener.
|
static void |
removeFocusTracker(FocusTracker focusTracker)
Unregisters specified focus tracker.
|
static void |
removeFocusTrackers(java.awt.Component component)
Unregisters all focus trackers from the specified component.
|
static void |
unregisterGlobalFocusListener(GlobalFocusListener listener)
Unregisters global focus listener.
|
protected static final java.lang.Object trackersLock
protected static final java.util.Map<java.awt.Component,java.util.Map<FocusTracker,java.lang.Boolean>> trackers
protected static final java.lang.Object listenersLock
protected static final java.util.List<GlobalFocusListener> globalFocusListeners
protected static java.lang.ref.WeakReference<java.awt.Component> oldFocusOwner
protected static java.lang.ref.WeakReference<java.awt.Component> focusOwner
protected static boolean initialized
public static void initialize()
protected static java.util.Map<java.awt.Component,java.util.Map<FocusTracker,java.lang.Boolean>> getTrackersCopy()
public static java.awt.Component getFocusOwner()
public static java.awt.Component getOldFocusOwner()
public static void registerGlobalFocusListener(GlobalFocusListener listener)
listener - new global focus listenerpublic static void unregisterGlobalFocusListener(GlobalFocusListener listener)
listener - global focus listener to unregisterprotected static void fireGlobalFocusChanged(java.awt.Component oldComponent,
java.awt.Component newComponent)
oldComponent - previously focused componentnewComponent - currently focused componentpublic static void addFocusTracker(java.awt.Component component,
FocusTracker focusTracker)
Be aware that when all links to either component or focus tracker (outside of the FocusManager) are lost all component focus trackers or specific focus tracker will be disposed. So make sure you keep strong references to whatever you pass here.
focusTracker - new focus trackerpublic static void removeFocusTracker(FocusTracker focusTracker)
focusTracker - focus tracker to unregisterpublic static void removeFocusTrackers(java.awt.Component component)
component - component to unregister all focus trackers from