src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page

        

@@ -230,21 +230,20 @@
     protected void setVisibleImpl(final boolean visible) {
         super.setVisibleImpl(visible);
         // TODO: update graphicsConfig, see 4868278
         platformWindow.setVisible(visible);
         if (isSimpleWindow()) {
-            LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
-                getInstance(getAppContext());
+            KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 
             if (visible) {
                 if (!getTarget().isAutoRequestFocus()) {
                     return;
                 } else {
                     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) {
                     owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
                 }

@@ -851,23 +850,23 @@
      * Called by the delegate when a key is pressed.
      */
     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
         // (AWT transfers/clears the focus owner) and pending ESC release
         // 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);
         }
     }
 
 
     // ---- UTILITY METHODS ---- //

@@ -1180,14 +1179,12 @@
                     return;
                 }
             }
         }
 
-        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.
         // - for a simple window in any case.
         if (!becomesFocused &&

@@ -1196,11 +1193,11 @@
             focusLog.fine("ungrabbing on " + grabbingWindow);
             // ungrab a simple window if its owner looses activation.
             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);
 
         // TODO: wrap in SequencedEvent