summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/awt/DefaultKeyboardFocusManager.java
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
commitffde862e033a0825e1e9972a89c0f1f80b261a8e (patch)
tree97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/java/awt/DefaultKeyboardFocusManager.java
parentb415ff10527e977c3758234fd930e2c027bfa17d (diff)
downloadppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.tar.gz
ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.zip
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92 * HACKING: Add more importing hints. Update automake version requirement. * configure.ac (gconf-peer): New enable AC argument. Add --disable-gconf-peer and --enable-default-preferences-peer to classpath configure when gconf is disabled. * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and gnu/java/awt/dnd/peer/gtk to bc. Classify gnu/java/security/Configuration.java as generated source file. * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java, gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java, gnu/java/lang/management/VMClassLoadingMXBeanImpl.java, gnu/java/lang/management/VMRuntimeMXBeanImpl.java, gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java, gnu/java/lang/management/VMThreadMXBeanImpl.java, gnu/java/lang/management/VMMemoryMXBeanImpl.java, gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub classes. * java/lang/management/VMManagementFactory.java: Likewise. * java/net/VMURLConnection.java: Likewise. * gnu/java/nio/VMChannel.java: Likewise. * java/lang/Thread.java (getState): Add stub implementation. * java/lang/Class.java (isEnum): Likewise. * java/lang/Class.h (isEnum): Likewise. * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed. * javax/naming/spi/NamingManager.java: New override for StackWalker functionality. * configure, sources.am, Makefile.in, gcj/Makefile.in, include/Makefile.in, testsuite/Makefile.in: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/awt/DefaultKeyboardFocusManager.java')
-rw-r--r--libjava/classpath/java/awt/DefaultKeyboardFocusManager.java140
1 files changed, 101 insertions, 39 deletions
diff --git a/libjava/classpath/java/awt/DefaultKeyboardFocusManager.java b/libjava/classpath/java/awt/DefaultKeyboardFocusManager.java
index 037cb834c40..9fea99b7839 100644
--- a/libjava/classpath/java/awt/DefaultKeyboardFocusManager.java
+++ b/libjava/classpath/java/awt/DefaultKeyboardFocusManager.java
@@ -163,7 +163,13 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
if (e.id == WindowEvent.WINDOW_ACTIVATED)
setGlobalActiveWindow (target);
else if (e.id == WindowEvent.WINDOW_GAINED_FOCUS)
- setGlobalFocusedWindow (target);
+ {
+ setGlobalFocusedWindow (target);
+ FocusTraversalPolicy p = target.getFocusTraversalPolicy();
+ Component toFocus = p.getInitialComponent(target);
+ if (toFocus != null)
+ toFocus.requestFocusInWindow();
+ }
else if (e.id != WindowEvent.WINDOW_LOST_FOCUS
&& e.id != WindowEvent.WINDOW_DEACTIVATED)
return false;
@@ -173,51 +179,18 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
}
else if (e instanceof FocusEvent)
{
- Component target = (Component) e.getSource ();
+ FocusEvent fe = (FocusEvent) e;
+ Component target = fe.getComponent ();
+ boolean retval = false;
if (e.id == FocusEvent.FOCUS_GAINED)
{
- if (! (target instanceof Window))
- {
- if (((FocusEvent) e).isTemporary ())
- setGlobalFocusOwner (target);
- else
- setGlobalPermanentFocusOwner (target);
- }
-
- // Keep track of this window's focus owner.
-
- // Find the target Component's top-level ancestor. target
- // may be a window.
- Container parent = target.getParent ();
-
- while (parent != null
- && !(parent instanceof Window))
- parent = parent.getParent ();
-
- // If the parent is null and target is not a window, then target is an
- // unanchored component and so we don't want to set the focus owner.
- if (! (parent == null && ! (target instanceof Window)))
- {
- Window toplevel = parent == null ?
- (Window) target : (Window) parent;
-
- Component focusOwner = getFocusOwner ();
- if (focusOwner != null
- && ! (focusOwner instanceof Window))
- toplevel.setFocusOwner (focusOwner);
- }
+ retval = handleFocusGained(fe);
}
else if (e.id == FocusEvent.FOCUS_LOST)
{
- if (((FocusEvent) e).isTemporary ())
- setGlobalFocusOwner (null);
- else
- setGlobalPermanentFocusOwner (null);
+ retval = handleFocusLost(fe);
}
-
- redispatchEvent(target, e);
-
return true;
}
else if (e instanceof KeyEvent)
@@ -256,6 +229,95 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
return false;
}
+ /**
+ * Handles FOCUS_GAINED events in {@link #dispatchEvent(AWTEvent)}.
+ *
+ * @param fe the focus event
+ */
+ private boolean handleFocusGained(FocusEvent fe)
+ {
+ Component target = fe.getComponent ();
+
+ // If old focus owner != new focus owner, notify old focus
+ // owner that it has lost focus.
+ Component oldFocusOwner = getGlobalFocusOwner();
+ if (oldFocusOwner != null && oldFocusOwner != target)
+ {
+ FocusEvent lost = new FocusEvent(oldFocusOwner,
+ FocusEvent.FOCUS_LOST,
+ fe.isTemporary(), target);
+ oldFocusOwner.dispatchEvent(lost);
+ }
+
+ setGlobalFocusOwner (target);
+ if (target != getGlobalFocusOwner())
+ {
+ // Focus transfer was rejected, like when the target is not
+ // focusable.
+ dequeueKeyEvents(-1, target);
+ // FIXME: Restore focus somehow.
+ }
+ else
+ {
+ if (! fe.isTemporary())
+ {
+ setGlobalPermanentFocusOwner (target);
+ if (target != getGlobalPermanentFocusOwner())
+ {
+ // Focus transfer was rejected, like when the target is not
+ // focusable.
+ dequeueKeyEvents(-1, target);
+ // FIXME: Restore focus somehow.
+ }
+ else
+ {
+ redispatchEvent(target, fe);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Handles FOCUS_LOST events for {@link #dispatchEvent(AWTEvent)}.
+ *
+ * @param fe the focus event
+ *
+ * @return if the event has been handled
+ */
+ private boolean handleFocusLost(FocusEvent fe)
+ {
+ Component currentFocus = getGlobalFocusOwner();
+ if (currentFocus != fe.getOppositeComponent())
+ {
+ setGlobalFocusOwner(null);
+ if (getGlobalFocusOwner() != null)
+ {
+ // TODO: Is this possible? If so, then we should try to restore
+ // the focus.
+ }
+ else
+ {
+ if (! fe.isTemporary())
+ {
+ setGlobalPermanentFocusOwner(null);
+ if (getGlobalPermanentFocusOwner() != null)
+ {
+ // TODO: Is this possible? If so, then we should try to
+ // restore the focus.
+ }
+ else
+ {
+ fe.setSource(currentFocus);
+ redispatchEvent(currentFocus, fe);
+ }
+ }
+ }
+ }
+ return true;
+ }
+
private boolean enqueueKeyEvent (KeyEvent e)
{
Iterator i = delayRequests.iterator ();
OpenPOWER on IntegriCloud