7124375: [macosx] Focus isn't transfered as expected between components
Reviewed-by: art, ant, serb
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -40,6 +40,7 @@
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
+import java.awt.peer.KeyboardFocusManagerPeer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.lang.reflect.Field;
import java.security.AccessController;
@@ -894,15 +895,15 @@
", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed +
", time= " + time + ", cause=" + cause);
}
- if (LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
- processSynchronousLightweightTransfer(getTarget(), lightweightChild, temporary,
- focusedWindowChangeAllowed, time)) {
+ if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer(
+ getTarget(), lightweightChild, temporary,
+ focusedWindowChangeAllowed, time)) {
return true;
}
- int result = LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
- shouldNativelyFocusHeavyweight(getTarget(), lightweightChild, temporary,
- focusedWindowChangeAllowed, time, cause);
+ int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight(
+ getTarget(), lightweightChild, temporary,
+ focusedWindowChangeAllowed, time, cause);
switch (result) {
case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
return false;
@@ -951,14 +952,13 @@
return false;
}
- LWComponentPeer focusOwnerPeer =
- LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
- getFocusOwner();
- Component focusOwner = (focusOwnerPeer != null) ? focusOwnerPeer.getTarget() : null;
+ KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
+ Component focusOwner = kfmPeer.getCurrentFocusOwner();
return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
getTarget(), temporary,
focusedWindowChangeAllowed,
time, cause, focusOwner);
+
case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
return true;
}
@@ -1263,8 +1263,8 @@
protected void handleJavaFocusEvent(FocusEvent e) {
// Note that the peer receives all the FocusEvents from
// its lightweight children as well
- LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
- setFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? this : null);
+ KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
+ kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null);
}
/**
--- a/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -26,85 +26,47 @@
package sun.lwawt;
import java.awt.Component;
-import java.awt.KeyboardFocusManager;
import java.awt.Window;
-
-import java.util.Map;
-import java.util.HashMap;
-
-import sun.awt.AWTAccessor;
-import sun.awt.AppContext;
import sun.awt.KeyboardFocusManagerPeerImpl;
public class LWKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
-
- private Object lock = new Object();
- private LWWindowPeer focusedWindow;
- private LWComponentPeer focusOwner;
+ private static final LWKeyboardFocusManagerPeer inst = new LWKeyboardFocusManagerPeer();
- private static Map<KeyboardFocusManager, LWKeyboardFocusManagerPeer> instances =
- new HashMap<KeyboardFocusManager, LWKeyboardFocusManagerPeer>();
+ private Window focusedWindow;
+ private Component focusOwner;
- public static synchronized LWKeyboardFocusManagerPeer getInstance(AppContext ctx) {
- return getInstance(AWTAccessor.getKeyboardFocusManagerAccessor().
- getCurrentKeyboardFocusManager(ctx));
+ public static LWKeyboardFocusManagerPeer getInstance() {
+ return inst;
}
- public static synchronized LWKeyboardFocusManagerPeer getInstance(KeyboardFocusManager manager) {
- LWKeyboardFocusManagerPeer instance = instances.get(manager);
- if (instance == null) {
- instance = new LWKeyboardFocusManagerPeer(manager);
- instances.put(manager, instance);
- }
- return instance;
+ private LWKeyboardFocusManagerPeer() {
}
- public LWKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
- super(manager);
+ @Override
+ public void setCurrentFocusedWindow(Window win) {
+ synchronized (this) {
+ focusedWindow = win;
+ }
}
@Override
public Window getCurrentFocusedWindow() {
- synchronized (lock) {
- return (focusedWindow != null) ? (Window)focusedWindow.getTarget() : null;
+ synchronized (this) {
+ return focusedWindow;
}
}
@Override
public Component getCurrentFocusOwner() {
- synchronized (lock) {
- return (focusOwner != null) ? focusOwner.getTarget() : null;
+ synchronized (this) {
+ return focusOwner;
}
}
@Override
public void setCurrentFocusOwner(Component comp) {
- synchronized (lock) {
- focusOwner = (comp != null) ? (LWComponentPeer)comp.getPeer() : null;
- }
- }
-
- void setFocusedWindow(LWWindowPeer peer) {
- synchronized (lock) {
- focusedWindow = peer;
- }
- }
-
- LWWindowPeer getFocusedWindow() {
- synchronized (lock) {
- return focusedWindow;
- }
- }
-
- void setFocusOwner(LWComponentPeer peer) {
- synchronized (lock) {
- focusOwner = peer;
- }
- }
-
- LWComponentPeer getFocusOwner() {
- synchronized (lock) {
- return focusOwner;
+ synchronized (this) {
+ focusOwner = comp;
}
}
}
--- a/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -415,8 +415,8 @@
}
@Override
- public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
- return LWKeyboardFocusManagerPeer.getInstance(manager);
+ public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
+ return LWKeyboardFocusManagerPeer.getInstance();
}
@Override
--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -238,8 +238,7 @@
// TODO: update graphicsConfig, see 4868278
platformWindow.setVisible(visible);
if (isSimpleWindow()) {
- LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
- getInstance(getAppContext());
+ KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
if (visible) {
if (!getTarget().isAutoRequestFocus()) {
@@ -248,7 +247,7 @@
requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
}
// Focus the owner in case this window is focused.
- } else if (manager.getCurrentFocusedWindow() == getTarget()) {
+ } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
// Transfer focus to the owner.
LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
if (owner != null) {
@@ -915,9 +914,8 @@
public void dispatchKeyEvent(int id, long when, int modifiers,
int keyCode, char keyChar, int keyLocation)
{
- LWComponentPeer focusOwner =
- LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
- getFocusOwner();
+ KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
+ Component focusOwner = kfmPeer.getCurrentFocusOwner();
// Null focus owner may receive key event when
// application hides the focused window upon ESC press
@@ -925,9 +923,10 @@
// may come to already hidden window. This check eliminates NPE.
if (focusOwner != null) {
KeyEvent event =
- new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
+ new KeyEvent(focusOwner, id, when, modifiers,
keyCode, keyChar, keyLocation);
- focusOwner.postEvent(event);
+ LWComponentPeer peer = (LWComponentPeer)focusOwner.getPeer();
+ peer.postEvent(event);
}
}
@@ -1244,10 +1243,8 @@
}
}
- LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
- getInstance(getAppContext());
-
- Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
+ KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
+ Window oppositeWindow = becomesFocused ? kfmPeer.getCurrentFocusedWindow() : null;
// Note, the method is not called:
// - when the opposite (gaining focus) window is an owned/owner window.
@@ -1260,7 +1257,7 @@
grabbingWindow.ungrab();
}
- manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
+ kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
--- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Wed Aug 29 19:53:35 2012 +0400
@@ -56,7 +56,6 @@
import sun.util.logging.PlatformLogger;
import sun.awt.AppContext;
-import sun.awt.HeadlessToolkit;
import sun.awt.SunToolkit;
import sun.awt.CausedFocusEvent;
import sun.awt.KeyboardFocusManagerPeerProvider;
@@ -443,7 +442,7 @@
private void initPeer() {
Toolkit tk = Toolkit.getDefaultToolkit();
KeyboardFocusManagerPeerProvider peerProvider = (KeyboardFocusManagerPeerProvider)tk;
- peer = peerProvider.createKeyboardFocusManagerPeer(this);
+ peer = peerProvider.getKeyboardFocusManagerPeer();
}
/**
--- a/jdk/src/share/classes/java/awt/peer/KeyboardFocusManagerPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/java/awt/peer/KeyboardFocusManagerPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -34,6 +34,14 @@
public interface KeyboardFocusManagerPeer {
/**
+ * Sets the window that should become the focused window.
+ *
+ * @param win the window that should become the focused window
+ *
+ */
+ void setCurrentFocusedWindow(Window win);
+
+ /**
* Returns the currently focused window.
*
* @return the currently focused window
--- a/jdk/src/share/classes/sun/awt/HToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/HToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -44,6 +44,14 @@
public class HToolkit extends SunToolkit
implements ComponentFactory {
+ private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
+ public void setCurrentFocusedWindow(Window win) {}
+ public Window getCurrentFocusedWindow() { return null; }
+ public void setCurrentFocusOwner(Component comp) {}
+ public Component getCurrentFocusOwner() { return null; }
+ public void clearGlobalFocusOwner(Window activeWindow) {}
+ };
+
public HToolkit() {
}
@@ -152,15 +160,9 @@
throw new HeadlessException();
}
- public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
+ public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
// See 6833019.
- return
- new KeyboardFocusManagerPeer() {
- public Window getCurrentFocusedWindow() { return null; }
- public void setCurrentFocusOwner(Component comp) {}
- public Component getCurrentFocusOwner() { return null; }
- public void clearGlobalFocusOwner(Window activeWindow) {}
- };
+ return kfmPeer;
}
public TrayIconPeer createTrayIcon(TrayIcon target)
--- a/jdk/src/share/classes/sun/awt/HeadlessToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/HeadlessToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -30,22 +30,25 @@
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.event.*;
import java.awt.im.InputMethodHighlight;
-import java.awt.im.spi.InputMethodDescriptor;
import java.awt.image.*;
import java.awt.datatransfer.Clipboard;
import java.awt.peer.*;
import java.beans.PropertyChangeListener;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
-import sun.awt.im.InputContext;
-import sun.awt.image.ImageRepresentation;
public class HeadlessToolkit extends Toolkit
implements ComponentFactory, KeyboardFocusManagerPeerProvider {
+ private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
+ public void setCurrentFocusedWindow(Window win) {}
+ public Window getCurrentFocusedWindow() { return null; }
+ public void setCurrentFocusOwner(Component comp) {}
+ public Component getCurrentFocusOwner() { return null; }
+ public void clearGlobalFocusOwner(Window activeWindow) {}
+ };
+
private Toolkit tk;
private ComponentFactory componentFactory;
@@ -179,15 +182,9 @@
throw new HeadlessException();
}
- public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
+ public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
// See 6833019.
- return
- new KeyboardFocusManagerPeer() {
- public Window getCurrentFocusedWindow() { return null; }
- public void setCurrentFocusOwner(Component comp) {}
- public Component getCurrentFocusOwner() { return null; }
- public void clearGlobalFocusOwner(Window activeWindow) {}
- };
+ return kfmPeer;
}
public TrayIconPeer createTrayIcon(TrayIcon target)
--- a/jdk/src/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java Wed Aug 29 19:53:35 2012 +0400
@@ -53,12 +53,6 @@
public static final int SNFH_SUCCESS_HANDLED = 1;
public static final int SNFH_SUCCESS_PROCEED = 2;
- protected KeyboardFocusManager manager;
-
- public KeyboardFocusManagerPeerImpl(KeyboardFocusManager manager) {
- this.manager = manager;
- }
-
@Override
public void clearGlobalFocusOwner(Window activeWindow) {
if (activeWindow != null) {
--- a/jdk/src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java Wed Aug 29 19:53:35 2012 +0400
@@ -25,20 +25,19 @@
package sun.awt;
-import java.awt.KeyboardFocusManager;
import java.awt.peer.KeyboardFocusManagerPeer;
/**
* {@link KeyboardFocusManagerPeerProvider} is required to be implemented by
* the currently used {@link java.awt.Toolkit} instance. In order to initialize
- * {@link java.awt.KeyboardFocusManager}, an instance of {@link KeyboardFocusManagerPeer}
- * is needed. To create that instance, the {@link #createKeyboardFocusManagerPeer}
+ * {@link java.awt.KeyboardFocusManager}, a singleton instance of {@link KeyboardFocusManagerPeer}
+ * is needed. To obtain that instance, the {@link #getKeyboardFocusManagerPeer}
* method of the current toolkit is called.
*/
public interface KeyboardFocusManagerPeerProvider {
/**
- * Creates a KeyboardFocusManagerPeer for the specified KeyboardFocusManager.
+ * Gets a singleton KeyboardFocusManagerPeer instance.
*/
- KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager);
+ KeyboardFocusManagerPeer getKeyboardFocusManagerPeer();
}
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -53,7 +53,6 @@
import sun.security.action.GetBooleanAction;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -204,7 +203,7 @@
public abstract RobotPeer createRobot(Robot target, GraphicsDevice screen)
throws AWTException;
- public abstract KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
+ public abstract KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
throws HeadlessException;
/**
--- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -601,7 +601,7 @@
final XWindowPeer parentXWindow = getParentTopLevel();
Window parentWindow = (Window)parentXWindow.getTarget();
if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
- XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
+ XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() != parentWindow)
{
postEvent(new InvocationEvent(parentWindow, new Runnable() {
public void run() {
--- a/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -1108,7 +1108,7 @@
focusLog.fine("Request for decorated window focus");
// If this is Frame or Dialog we can't assure focus request success - but we still can try
// If this is Window and its owner Frame is active we can be sure request succedded.
- Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
+ Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
focusLog.finer("Current window is: active={0}, focused={1}",
@@ -1201,7 +1201,7 @@
}
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
- Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
+ Window actualFocusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
// If the actual focused window is not this decorated window then retain it.
if (actualFocusedWindow != null && actualFocusedWindow != target) {
--- a/jdk/src/solaris/classes/sun/awt/X11/XDialogPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XDialogPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -135,7 +135,7 @@
* Thus we don't have to perform any transitive (a blocker of a blocker) checks.
*/
boolean isFocusedWindowModalBlocker() {
- Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
+ Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
XWindowPeer focusedWindowPeer = null;
if (focusedWindow != null) {
--- a/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -96,11 +96,11 @@
public void handleEvent(AWTEvent e) {
switch (e.getID()) {
case FocusEvent.FOCUS_GAINED:
- XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(proxy);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(proxy);
container.focusGained(handle);
break;
case FocusEvent.FOCUS_LOST:
- XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
container.focusLost(handle);
break;
case KeyEvent.KEY_PRESSED:
@@ -172,7 +172,7 @@
if (lightweightChild == null) {
lightweightChild = (Component)proxy;
}
- Component currentOwner = XKeyboardFocusManagerPeer.getCurrentNativeFocusOwner();
+ Component currentOwner = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusOwner();
if (currentOwner != null && currentOwner.getPeer() == null) {
currentOwner = null;
}
@@ -224,7 +224,8 @@
if (parent != null) {
Window parentWindow = (Window)parent;
// and check that it is focused
- if (!parentWindow.isFocused() && XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == parentWindow) {
+ if (!parentWindow.isFocused() &&
+ XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == parentWindow) {
// if it is not - skip requesting focus on Solaris
// but return true for compatibility.
return true;
--- a/jdk/src/solaris/classes/sun/awt/X11/XEmbedClientHelper.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XEmbedClientHelper.java Wed Aug 29 19:53:35 2012 +0400
@@ -204,7 +204,7 @@
// XEMBED_FOCUS_OUT client messages), so we first need to check if
// embedded is an active window before sending WINDOW_LOST_FOCUS
// to shared code
- if (XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == embedded.target) {
+ if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == embedded.target) {
embedded.handleWindowFocusOut(null, 0);
}
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -25,66 +25,48 @@
package sun.awt.X11;
import java.awt.Component;
-import java.awt.KeyboardFocusManager;
import java.awt.Window;
-
-import java.awt.event.FocusEvent;
-
-import java.awt.peer.KeyboardFocusManagerPeer;
-import java.awt.peer.ComponentPeer;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
import sun.util.logging.PlatformLogger;
-
import sun.awt.CausedFocusEvent;
-import sun.awt.SunToolkit;
import sun.awt.KeyboardFocusManagerPeerImpl;
public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XKeyboardFocusManagerPeer");
+ private static final XKeyboardFocusManagerPeer inst = new XKeyboardFocusManagerPeer();
- private static Object lock = new Object() {};
- private static Component currentFocusOwner;
- private static Window currentFocusedWindow;
+ private Component currentFocusOwner;
+ private Window currentFocusedWindow;
- XKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
- super(manager);
+ public static XKeyboardFocusManagerPeer getInstance() {
+ return inst;
+ }
+
+ private XKeyboardFocusManagerPeer() {
}
@Override
public void setCurrentFocusOwner(Component comp) {
- setCurrentNativeFocusOwner(comp);
+ synchronized (this) {
+ currentFocusOwner = comp;
+ }
}
@Override
public Component getCurrentFocusOwner() {
- return getCurrentNativeFocusOwner();
- }
-
- @Override
- public Window getCurrentFocusedWindow() {
- return getCurrentNativeFocusedWindow();
- }
-
- public static void setCurrentNativeFocusOwner(Component comp) {
- synchronized (lock) {
- currentFocusOwner = comp;
- }
- }
-
- public static Component getCurrentNativeFocusOwner() {
- synchronized(lock) {
+ synchronized(this) {
return currentFocusOwner;
}
}
- public static void setCurrentNativeFocusedWindow(Window win) {
- if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Setting current native focused window " + win);
+ @Override
+ public void setCurrentFocusedWindow(Window win) {
+ if (focusLog.isLoggable(PlatformLogger.FINER)) {
+ focusLog.finer("Setting current focused window " + win);
+ }
+
XWindowPeer from = null, to = null;
- synchronized(lock) {
+ synchronized(this) {
if (currentFocusedWindow != null) {
from = (XWindowPeer)currentFocusedWindow.getPeer();
}
@@ -104,8 +86,9 @@
}
}
- public static Window getCurrentNativeFocusedWindow() {
- synchronized(lock) {
+ @Override
+ public Window getCurrentFocusedWindow() {
+ synchronized(this) {
return currentFocusedWindow;
}
}
@@ -124,6 +107,6 @@
focusedWindowChangeAllowed,
time,
cause,
- getCurrentNativeFocusOwner());
+ getInstance().getCurrentFocusOwner());
}
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -50,7 +50,6 @@
import javax.swing.UIDefaults;
import sun.awt.*;
import sun.font.FontConfigManager;
-import sun.font.FontManager;
import sun.java2d.SunGraphicsEnvironment;
import sun.misc.PerformanceLogger;
import sun.print.PrintJob2D;
@@ -667,7 +666,7 @@
long w = 0;
if (windowToXWindow(ev.get_xany().get_window()) != null) {
Component owner =
- XKeyboardFocusManagerPeer.getCurrentNativeFocusOwner();
+ XKeyboardFocusManagerPeer.getInstance().getCurrentFocusOwner();
if (owner != null) {
XWindow ownerWindow = (XWindow) AWTAccessor.getComponentAccessor().getPeer(owner);
if (ownerWindow != null) {
@@ -1159,9 +1158,8 @@
return peer;
}
- public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) throws HeadlessException {
- XKeyboardFocusManagerPeer peer = new XKeyboardFocusManagerPeer(manager);
- return peer;
+ public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() throws HeadlessException {
+ return XKeyboardFocusManagerPeer.getInstance();
}
/**
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -617,7 +617,7 @@
public void handleWindowFocusIn_Dispatch() {
if (EventQueue.isDispatchThread()) {
- XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
SunToolkit.setSystemGenerated(we);
target.dispatchEvent(we);
@@ -626,7 +626,7 @@
public void handleWindowFocusInSync(long serial) {
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
- XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
sendEvent(we);
}
// NOTE: This method may be called by privileged threads.
@@ -634,7 +634,7 @@
public void handleWindowFocusIn(long serial) {
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
/* wrap in Sequenced, then post*/
- XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
postEvent(wrapInSequenced((AWTEvent) we));
}
@@ -642,15 +642,15 @@
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
- XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
- XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
/* wrap in Sequenced, then post*/
postEvent(wrapInSequenced((AWTEvent) we));
}
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
- XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
- XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
+ XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
sendEvent(we);
}
@@ -1138,7 +1138,7 @@
// getWMState() always returns 0 (Withdrawn) for simple windows. Hence
// we ignore the state for such windows.
if (isVisible() && (state == XUtilConstants.NormalState || isSimpleWindow())) {
- if (XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() ==
+ if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() ==
getTarget())
{
show = true;
@@ -1185,7 +1185,7 @@
* receive WM_TAKE_FOCUS.
*/
if (isSimpleWindow()) {
- if (target == XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow()) {
+ if (target == XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow()) {
Window owner = getDecoratedOwner((Window)target);
((XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(owner)).requestWindowFocus();
}
@@ -1825,7 +1825,7 @@
// If this is Frame or Dialog we can't assure focus request success - but we still can try
// If this is Window and its owner Frame is active we can be sure request succedded.
Window ownerWindow = XWindowPeer.getDecoratedOwner((Window)target);
- Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
+ Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
if (isWMStateNetHidden()) {
--- a/jdk/src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java Wed Aug 29 19:53:35 2012 +0400
@@ -25,7 +25,6 @@
package sun.awt.windows;
-import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.awt.Component;
import java.awt.peer.ComponentPeer;
@@ -37,8 +36,13 @@
static native Component getNativeFocusOwner();
static native Window getNativeFocusedWindow();
- WKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
- super(manager);
+ private static final WKeyboardFocusManagerPeer inst = new WKeyboardFocusManagerPeer();
+
+ public static WKeyboardFocusManagerPeer getInstance() {
+ return inst;
+ }
+
+ private WKeyboardFocusManagerPeer() {
}
@Override
@@ -52,6 +56,12 @@
}
@Override
+ public void setCurrentFocusedWindow(Window win) {
+ // Not used on Windows
+ throw new RuntimeException("not implemented");
+ }
+
+ @Override
public Window getCurrentFocusedWindow() {
return getNativeFocusedWindow();
}
--- a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java Wed Aug 29 15:54:28 2012 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java Wed Aug 29 19:53:35 2012 +0400
@@ -506,10 +506,10 @@
return true;
}
- public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
+ public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
throws HeadlessException
{
- return new WKeyboardFocusManagerPeer(manager);
+ return WKeyboardFocusManagerPeer.getInstance();
}
protected native void setDynamicLayoutNative(boolean b);