diff options
Diffstat (limited to 'libjava/classpath/java/awt/KeyboardFocusManager.java')
-rw-r--r-- | libjava/classpath/java/awt/KeyboardFocusManager.java | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/libjava/classpath/java/awt/KeyboardFocusManager.java b/libjava/classpath/java/awt/KeyboardFocusManager.java index 371ea9bdf8a..eacbceb7d50 100644 --- a/libjava/classpath/java/awt/KeyboardFocusManager.java +++ b/libjava/classpath/java/awt/KeyboardFocusManager.java @@ -304,10 +304,7 @@ public abstract class KeyboardFocusManager */ public Component getFocusOwner () { - Component owner = (Component) getObject (currentFocusOwners); - if (owner == null) - owner = (Component) getObject (currentPermanentFocusOwners); - return owner; + return (Component) getObject (currentFocusOwners); } /** @@ -323,10 +320,7 @@ public abstract class KeyboardFocusManager */ protected Component getGlobalFocusOwner () { - // Check if there is a temporary focus owner. - Component focusOwner = (Component) getGlobalObject (currentFocusOwners); - - return (focusOwner == null) ? getGlobalPermanentFocusOwner () : focusOwner; + return (Component) getGlobalObject(currentFocusOwners, true); } /** @@ -409,7 +403,7 @@ public abstract class KeyboardFocusManager */ protected Component getGlobalPermanentFocusOwner () { - return (Component) getGlobalObject (currentPermanentFocusOwners); + return (Component) getGlobalObject (currentPermanentFocusOwners, true); } /** @@ -455,7 +449,7 @@ public abstract class KeyboardFocusManager */ protected Window getGlobalFocusedWindow () { - return (Window) getGlobalObject (currentFocusedWindows); + return (Window) getGlobalObject (currentFocusedWindows, true); } /** @@ -497,7 +491,7 @@ public abstract class KeyboardFocusManager */ protected Window getGlobalActiveWindow() { - return (Window) getGlobalObject (currentActiveWindows); + return (Window) getGlobalObject (currentActiveWindows, true); } /** @@ -663,7 +657,7 @@ public abstract class KeyboardFocusManager */ protected Container getGlobalCurrentFocusCycleRoot () { - return (Container) getGlobalObject (currentFocusCycleRoots); + return (Container) getGlobalObject (currentFocusCycleRoots, true); } /** @@ -1105,11 +1099,9 @@ public abstract class KeyboardFocusManager */ public final void redispatchEvent (Component target, AWTEvent e) { - synchronized (e) - { - e.setSource (target); - target.dispatchEvent (e); - } + e.isFocusManagerEvent = true; + target.dispatchEvent (e); + e.isFocusManagerEvent = false; } /** @@ -1355,17 +1347,19 @@ public abstract class KeyboardFocusManager * @see #getGlobalActiveWindow() * @see #getGlobalCurrentFocusCycleRoot() */ - private Object getGlobalObject (Map globalMap) + private Object getGlobalObject (Map globalMap, boolean checkThread) { - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - KeyboardFocusManager managerForCallingThread - = (KeyboardFocusManager) currentKeyboardFocusManagers.get (currentGroup); - - if (this != managerForCallingThread) - throw new SecurityException ("Attempted to retrieve an object from a " - + "keyboard focus manager that isn't " - + "associated with the current thread group."); + if (checkThread) + { + ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); + KeyboardFocusManager managerForCallingThread = + (KeyboardFocusManager) currentKeyboardFocusManagers.get(currentGroup); + if (this != managerForCallingThread) + throw new SecurityException ("Attempted to retrieve an object from a " + + "keyboard focus manager that isn't " + + "associated with the current thread group."); + } synchronized (globalMap) { Collection globalObjects = globalMap.values (); @@ -1406,7 +1400,7 @@ public abstract class KeyboardFocusManager synchronized (globalMap) { // Save old object. - Object oldObject = getGlobalObject (globalMap); + Object oldObject = getGlobalObject(globalMap, false); // Nullify old object. Collection threadGroups = globalMap.keySet (); @@ -1436,4 +1430,48 @@ public abstract class KeyboardFocusManager } } } + + + /** + * Maps focus requests from heavyweight to lightweight components. + */ + private static HashMap focusRequests = new HashMap(); + + /** + * Retargets focus events that come from the peer (which only know about + * heavyweight components) to go to the correct lightweight component + * if appropriate. + * + * @param ev the event to check + * + * @return the retargetted event + */ + static AWTEvent retargetFocusEvent(AWTEvent ev) + { + if (ev instanceof FocusEvent) + { + FocusEvent fe = (FocusEvent) ev; + Component target = fe.getComponent(); + if (focusRequests.containsKey(target)) + { + Component lightweight = (Component) focusRequests.get(target); + ev = new FocusEvent(lightweight, fe.id, fe.isTemporary()); + focusRequests.remove(target); + } + } + return ev; + } + + /** + * Adds a lightweight focus request for a heavyweight component. + * + * @param heavyweight the heavyweight from which we will receive a focus + * event soon + * @param lightweight the lightweight that ultimately receives the request + */ + static void addLightweightFocusRequest(Component heavyweight, + Component lightweight) + { + focusRequests.put(heavyweight, lightweight); + } } |