src/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java

Print this page




  40 import java.lang.reflect.Method;
  41 
  42 import sun.util.logging.PlatformLogger;
  43 
  44 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer {
  45 
  46     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
  47 
  48     private static AWTAccessor.KeyboardFocusManagerAccessor kfmAccessor =
  49         AWTAccessor.getKeyboardFocusManagerAccessor();
  50 
  51     // The constants are copied from java.awt.KeyboardFocusManager
  52     public static final int SNFH_FAILURE         = 0;
  53     public static final int SNFH_SUCCESS_HANDLED = 1;
  54     public static final int SNFH_SUCCESS_PROCEED = 2;
  55 
  56     @Override
  57     public void clearGlobalFocusOwner(Window activeWindow) {
  58         if (activeWindow != null) {
  59             Component focusOwner = activeWindow.getFocusOwner();
  60             if (focusLog.isLoggable(PlatformLogger.FINE)) {
  61                 focusLog.fine("Clearing global focus owner " + focusOwner);
  62             }
  63             if (focusOwner != null) {
  64                 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
  65                                                      CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
  66                 SunToolkit.postPriorityEvent(fl);
  67             }
  68         }
  69     }
  70 
  71     /*
  72      * WARNING: Don't call it on the Toolkit thread.
  73      *
  74      * Checks if the component:
  75      * 1) accepts focus on click (in general)
  76      * 2) may be a focus owner (in particular)
  77      */
  78     @SuppressWarnings("deprecation")
  79     public static boolean shouldFocusOnClick(Component component) {
  80         boolean acceptFocusOnClick = false;


 110     public static boolean deliverFocus(Component lightweightChild,
 111                                        Component target,
 112                                        boolean temporary,
 113                                        boolean focusedWindowChangeAllowed,
 114                                        long time,
 115                                        CausedFocusEvent.Cause cause,
 116                                        Component currentFocusOwner) // provided by the descendant peers
 117     {
 118         if (lightweightChild == null) {
 119             lightweightChild = target;
 120         }
 121 
 122         Component currentOwner = currentFocusOwner;
 123         if (currentOwner != null && currentOwner.getPeer() == null) {
 124             currentOwner = null;
 125         }
 126         if (currentOwner != null) {
 127             FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
 128                                                  false, lightweightChild, cause);
 129 
 130             if (focusLog.isLoggable(PlatformLogger.FINER)) {
 131                 focusLog.finer("Posting focus event: " + fl);
 132             }
 133             SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
 134         }
 135 
 136         FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
 137                                              false, currentOwner, cause);
 138 
 139         if (focusLog.isLoggable(PlatformLogger.FINER)) {
 140             focusLog.finer("Posting focus event: " + fg);
 141         }
 142         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 143         return true;
 144     }
 145 
 146     // WARNING: Don't call it on the Toolkit thread.
 147     public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
 148         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 149     }
 150 
 151     // WARNING: Don't call it on the Toolkit thread.
 152     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 153                                                      Component descendant,
 154                                                      boolean temporary,
 155                                                      boolean focusedWindowChangeAllowed,
 156                                                      long time,
 157                                                      CausedFocusEvent.Cause cause)
 158     {
 159         return kfmAccessor.shouldNativelyFocusHeavyweight(


  40 import java.lang.reflect.Method;
  41 
  42 import sun.util.logging.PlatformLogger;
  43 
  44 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer {
  45 
  46     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
  47 
  48     private static AWTAccessor.KeyboardFocusManagerAccessor kfmAccessor =
  49         AWTAccessor.getKeyboardFocusManagerAccessor();
  50 
  51     // The constants are copied from java.awt.KeyboardFocusManager
  52     public static final int SNFH_FAILURE         = 0;
  53     public static final int SNFH_SUCCESS_HANDLED = 1;
  54     public static final int SNFH_SUCCESS_PROCEED = 2;
  55 
  56     @Override
  57     public void clearGlobalFocusOwner(Window activeWindow) {
  58         if (activeWindow != null) {
  59             Component focusOwner = activeWindow.getFocusOwner();
  60             if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
  61                 focusLog.fine("Clearing global focus owner " + focusOwner);
  62             }
  63             if (focusOwner != null) {
  64                 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
  65                                                      CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
  66                 SunToolkit.postPriorityEvent(fl);
  67             }
  68         }
  69     }
  70 
  71     /*
  72      * WARNING: Don't call it on the Toolkit thread.
  73      *
  74      * Checks if the component:
  75      * 1) accepts focus on click (in general)
  76      * 2) may be a focus owner (in particular)
  77      */
  78     @SuppressWarnings("deprecation")
  79     public static boolean shouldFocusOnClick(Component component) {
  80         boolean acceptFocusOnClick = false;


 110     public static boolean deliverFocus(Component lightweightChild,
 111                                        Component target,
 112                                        boolean temporary,
 113                                        boolean focusedWindowChangeAllowed,
 114                                        long time,
 115                                        CausedFocusEvent.Cause cause,
 116                                        Component currentFocusOwner) // provided by the descendant peers
 117     {
 118         if (lightweightChild == null) {
 119             lightweightChild = target;
 120         }
 121 
 122         Component currentOwner = currentFocusOwner;
 123         if (currentOwner != null && currentOwner.getPeer() == null) {
 124             currentOwner = null;
 125         }
 126         if (currentOwner != null) {
 127             FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
 128                                                  false, lightweightChild, cause);
 129 
 130             if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 131                 focusLog.finer("Posting focus event: " + fl);
 132             }
 133             SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
 134         }
 135 
 136         FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
 137                                              false, currentOwner, cause);
 138 
 139         if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 140             focusLog.finer("Posting focus event: " + fg);
 141         }
 142         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 143         return true;
 144     }
 145 
 146     // WARNING: Don't call it on the Toolkit thread.
 147     public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
 148         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 149     }
 150 
 151     // WARNING: Don't call it on the Toolkit thread.
 152     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 153                                                      Component descendant,
 154                                                      boolean temporary,
 155                                                      boolean focusedWindowChangeAllowed,
 156                                                      long time,
 157                                                      CausedFocusEvent.Cause cause)
 158     {
 159         return kfmAccessor.shouldNativelyFocusHeavyweight(