diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-04-14 06:50:23 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-04-14 06:50:23 +0000 |
commit | fe67a5ac72d12dd8faf471d1c612492fed829a4b (patch) | |
tree | e63047006842dfddf0388368324211987cc15509 /java/awt/Component.java | |
parent | 71fa4db0b20e97806bd5b11d96370695112f21b4 (diff) | |
download | classpath-fe67a5ac72d12dd8faf471d1c612492fed829a4b.tar.gz |
2006-04-13 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics-branch from 2006/03/26 to 2006/04/13.
Diffstat (limited to 'java/awt/Component.java')
-rw-r--r-- | java/awt/Component.java | 152 |
1 files changed, 128 insertions, 24 deletions
diff --git a/java/awt/Component.java b/java/awt/Component.java index 588b43548..8dbcc0696 100644 --- a/java/awt/Component.java +++ b/java/awt/Component.java @@ -1075,8 +1075,6 @@ public abstract class Component Component p = parent; if (p != null) return p.getFont(); - if (peer != null) - return peer.getGraphics().getFont(); return null; } @@ -2315,6 +2313,10 @@ public abstract class Component if (oldEvent != null) postEvent (oldEvent); + // Give toolkit a chance to dispatch the event + // to globally registered listeners. + Toolkit.getDefaultToolkit().globalDispatchEvent(e); + // Some subclasses in the AWT package need to override this behavior, // hence the use of dispatchEventImpl(). dispatchEventImpl(e); @@ -4079,14 +4081,9 @@ public abstract class Component */ public Container getFocusCycleRootAncestor () { - if (this instanceof Window - && ((Container) this).isFocusCycleRoot ()) - return (Container) this; - Container parent = getParent (); - while (parent != null - && !parent.isFocusCycleRoot ()) + while (parent != null && !parent.isFocusCycleRoot()) parent = parent.getParent (); return parent; @@ -4114,9 +4111,32 @@ public abstract class Component */ public void nextFocus () { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + // Find the nearest valid (== showing && focusable && enabled) focus + // cycle root ancestor and the focused component in it. + Container focusRoot = getFocusCycleRootAncestor(); + Component focusComp = this; + while (focusRoot != null + && ! (focusRoot.isShowing() && focusRoot.isFocusable() + && focusRoot.isEnabled())) + { + focusComp = focusRoot; + focusRoot = focusComp.getFocusCycleRootAncestor(); + } + + if (focusRoot != null) + { + // First try to get the componentBefore from the policy. + FocusTraversalPolicy policy = focusRoot.getFocusTraversalPolicy(); + Component nextFocus = policy.getComponentAfter(focusRoot, focusComp); - manager.focusNextComponent (this); + // If this fails, then ask for the defaultComponent. + if (nextFocus == null) + nextFocus = policy.getDefaultComponent(focusRoot); + + // Request focus on this component, if not null. + if (nextFocus != null) + nextFocus.requestFocus(); + } } /** @@ -4128,9 +4148,32 @@ public abstract class Component */ public void transferFocusBackward () { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + // Find the nearest valid (== showing && focusable && enabled) focus + // cycle root ancestor and the focused component in it. + Container focusRoot = getFocusCycleRootAncestor(); + Component focusComp = this; + while (focusRoot != null + && ! (focusRoot.isShowing() && focusRoot.isFocusable() + && focusRoot.isEnabled())) + { + focusComp = focusRoot; + focusRoot = focusComp.getFocusCycleRootAncestor(); + } - manager.focusPreviousComponent (this); + if (focusRoot != null) + { + // First try to get the componentBefore from the policy. + FocusTraversalPolicy policy = focusRoot.getFocusTraversalPolicy(); + Component nextFocus = policy.getComponentBefore(focusRoot, focusComp); + + // If this fails, then ask for the defaultComponent. + if (nextFocus == null) + nextFocus = policy.getDefaultComponent(focusRoot); + + // Request focus on this component, if not null. + if (nextFocus != null) + nextFocus.requestFocus(); + } } /** @@ -4144,9 +4187,63 @@ public abstract class Component */ public void transferFocusUpCycle () { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + // Find the nearest focus cycle root ancestor that is itself + // focusable, showing and enabled. + Container focusCycleRoot = getFocusCycleRootAncestor(); + while (focusCycleRoot != null && + ! (focusCycleRoot.isShowing() && focusCycleRoot.isFocusable() + && focusCycleRoot.isEnabled())) + { + focusCycleRoot = focusCycleRoot.getFocusCycleRootAncestor(); + } + + KeyboardFocusManager fm = + KeyboardFocusManager.getCurrentKeyboardFocusManager(); + + if (focusCycleRoot != null) + { + // If we found a focus cycle root, then we make this the new + // focused component, and make it's focus cycle root the new + // global focus cycle root. If the found root has no focus cycle + // root ancestor itself, then the component will be both the focused + // component and the new global focus cycle root. + Container focusCycleAncestor = + focusCycleRoot.getFocusCycleRootAncestor(); + Container globalFocusCycleRoot; + if (focusCycleAncestor == null) + globalFocusCycleRoot = focusCycleRoot; + else + globalFocusCycleRoot = focusCycleAncestor; + + fm.setGlobalCurrentFocusCycleRoot(globalFocusCycleRoot); + focusCycleRoot.requestFocus(); + } + else + { + // If this component has no applicable focus cycle root, we try + // find the nearest window and set this as the new global focus cycle + // root and the default focus component of this window the new focused + // component. + Container cont; + if (this instanceof Container) + cont = (Container) this; + else + cont = getParent(); + + while (cont != null && !(cont instanceof Window)) + cont = cont.getParent(); - manager.upFocusCycle (this); + if (cont != null) + { + FocusTraversalPolicy policy = cont.getFocusTraversalPolicy(); + Component focusComp = policy.getDefaultComponent(cont); + if (focusComp != null) + { + fm.setGlobalCurrentFocusCycleRoot(cont); + focusComp.requestFocus(); + } + } + } } /** @@ -4876,7 +4973,7 @@ p * <li>the set of backward traversal keys oldKey = Event.UP; break; default: - oldKey = newKey; + oldKey = (int) ((KeyEvent) e).getKeyChar(); } translated = new Event (target, when, oldID, @@ -4922,10 +5019,6 @@ p * <li>the set of backward traversal keys void dispatchEventImpl(AWTEvent e) { - // Give toolkit a chance to dispatch the event - // to globally registered listeners. - Toolkit.getDefaultToolkit().globalDispatchEvent(e); - // This boolean tells us not to process focus events when the focus // opposite component is the same as the focus component. boolean ignoreFocus = @@ -4979,6 +5072,15 @@ p * <li>the set of backward traversal keys switch (type) { + case HierarchyEvent.HIERARCHY_CHANGED: + return (hierarchyListener != null + || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0); + + case HierarchyEvent.ANCESTOR_MOVED: + case HierarchyEvent.ANCESTOR_RESIZED: + return (hierarchyBoundsListener != null + || (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0); + case ComponentEvent.COMPONENT_HIDDEN: case ComponentEvent.COMPONENT_MOVED: case ComponentEvent.COMPONENT_RESIZED: @@ -5333,8 +5435,10 @@ p * <li>the set of backward traversal keys s.add(AccessibleState.FOCUSABLE); if (isFocusOwner()) s.add(AccessibleState.FOCUSED); - if (isOpaque()) - s.add(AccessibleState.OPAQUE); + // Note: While the java.awt.Component has an 'opaque' property, it + // seems that it is not added to the accessible state set here, even + // if this property is true. However, it is handled for + // javax.swing.JComponent, so we add it there. if (Component.this.isShowing()) s.add(AccessibleState.SHOWING); if (Component.this.isVisible()) @@ -5618,7 +5722,7 @@ p * <li>the set of backward traversal keys */ public Point getLocation() { - return Component.this.isShowing() ? Component.this.getLocation() : null; + return Component.this.getLocation(); } /** @@ -5642,7 +5746,7 @@ p * <li>the set of backward traversal keys */ public Rectangle getBounds() { - return Component.this.isShowing() ? Component.this.getBounds() : null; + return Component.this.getBounds(); } /** @@ -5665,7 +5769,7 @@ p * <li>the set of backward traversal keys */ public Dimension getSize() { - return Component.this.isShowing() ? Component.this.getSize() : null; + return Component.this.getSize(); } /** |