changeset 554:e05eb7bee1ce

7110683: Issues with some KeyboardFocusManager method 7116384: backout the unallowed changes in the KeyboardFocusManager.java javadoc Reviewed-by: ant
author skoppar
date Thu, 22 Dec 2011 09:39:24 -0800
parents bfaa99d5bef8
children 3c11966c3da3
files src/share/classes/java/awt/KeyboardFocusManager.java
diffstat 1 files changed, 30 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/KeyboardFocusManager.java	Tue Dec 20 12:37:24 2011 -0800
+++ b/src/share/classes/java/awt/KeyboardFocusManager.java	Thu Dec 22 09:39:24 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -476,14 +476,8 @@
      */
     protected Component getGlobalFocusOwner() throws SecurityException {
         synchronized (KeyboardFocusManager.class) {
-            if (this == getCurrentKeyboardFocusManager()) {
-                return focusOwner;
-            } else {
-                if (focusLog.isLoggable(Level.FINER)) {
-                    focusLog.log(Level.FINER, "This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
-                }
-                throw new SecurityException(notPrivileged);
-            }
+            checkCurrentKFMSecurity();
+            return focusOwner;
         }
     }
 
@@ -517,6 +511,7 @@
 
         if (focusOwner == null || focusOwner.isFocusable()) {
             synchronized (KeyboardFocusManager.class) {
+                checkCurrentKFMSecurity();
                 oldFocusOwner = getFocusOwner();
 
                 try {
@@ -566,6 +561,10 @@
      * @see java.awt.event.FocusEvent#FOCUS_LOST
      */
     public void clearGlobalFocusOwner() {
+        synchronized (KeyboardFocusManager.class) {
+             checkCurrentKFMSecurity();
+        } 
+
         if (!GraphicsEnvironment.isHeadless()) {
             // Toolkit must be fully initialized, otherwise
             // _clearGlobalFocusOwner will crash or throw an exception
@@ -645,14 +644,8 @@
         throws SecurityException
     {
         synchronized (KeyboardFocusManager.class) {
-            if (this == getCurrentKeyboardFocusManager()) {
-                return permanentFocusOwner;
-            } else {
-                if (focusLog.isLoggable(Level.FINER)) {
-                    focusLog.log(Level.FINER, "This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
-                }
-                throw new SecurityException(notPrivileged);
-            }
+            checkCurrentKFMSecurity();
+            return permanentFocusOwner;
         }
     }
 
@@ -688,6 +681,7 @@
 
         if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
             synchronized (KeyboardFocusManager.class) {
+                checkCurrentKFMSecurity();
                 oldPermanentFocusOwner = getPermanentFocusOwner();
 
                 try {
@@ -753,14 +747,8 @@
      */
     protected Window getGlobalFocusedWindow() throws SecurityException {
         synchronized (KeyboardFocusManager.class) {
-            if (this == getCurrentKeyboardFocusManager()) {
-               return focusedWindow;
-            } else {
-                if (focusLog.isLoggable(Level.FINER)) {
-                    focusLog.log(Level.FINER, "This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
-                }
-                throw new SecurityException(notPrivileged);
-            }
+            checkCurrentKFMSecurity();
+            return focusedWindow;
         }
     }
 
@@ -791,6 +779,7 @@
 
         if (focusedWindow == null || focusedWindow.isFocusableWindow()) {
             synchronized (KeyboardFocusManager.class) {
+                checkCurrentKFMSecurity();
                 oldFocusedWindow = getFocusedWindow();
 
                 try {
@@ -857,14 +846,8 @@
      */
     protected Window getGlobalActiveWindow() throws SecurityException {
         synchronized (KeyboardFocusManager.class) {
-            if (this == getCurrentKeyboardFocusManager()) {
-               return activeWindow;
-            } else {
-                if (focusLog.isLoggable(Level.FINER)) {
-                    focusLog.log(Level.FINER, "This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
-                }
-                throw new SecurityException(notPrivileged);
-            }
+            checkCurrentKFMSecurity();
+            return activeWindow;
         }
     }
 
@@ -893,6 +876,7 @@
     protected void setGlobalActiveWindow(Window activeWindow) {
         Window oldActiveWindow;
         synchronized (KeyboardFocusManager.class) {
+            checkCurrentKFMSecurity();
             oldActiveWindow = getActiveWindow();
             if (focusLog.isLoggable(Level.FINER)) {
                 focusLog.log(Level.FINER, "Setting global active window to " + activeWindow + ", old active " + oldActiveWindow);
@@ -1187,14 +1171,8 @@
         throws SecurityException
     {
         synchronized (KeyboardFocusManager.class) {
-            if (this == getCurrentKeyboardFocusManager()) {
-                return currentFocusCycleRoot;
-            } else {
-                if (focusLog.isLoggable(Level.FINER)) {
-                    focusLog.log(Level.FINER, "This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
-                }
-                throw new SecurityException(notPrivileged);
-            }
+            checkCurrentKFMSecurity();
+            return currentFocusCycleRoot;
         }
     }
 
@@ -1218,6 +1196,7 @@
         Container oldFocusCycleRoot;
 
         synchronized (KeyboardFocusManager.class) {
+            checkCurrentKFMSecurity();
             oldFocusCycleRoot  = getCurrentFocusCycleRoot();
             currentFocusCycleRoot = newFocusCycleRoot;
         }
@@ -3102,4 +3081,14 @@
                 : null;
         }
     }
+
+     private void checkCurrentKFMSecurity() {
+         if (this != getCurrentKeyboardFocusManager()) {
+             if (focusLog.isLoggable(Level.FINER)) {
+                 focusLog.finer("This manager is " + this +
+                                ", current is " + getCurrentKeyboardFocusManager());
+             }
+             throw new SecurityException(notPrivileged);
+         }
+     }
 }