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             if (focusOwner != null) {
  63                 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
  64                                                      CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
  65                 SunToolkit.postPriorityEvent(fl);
  66             }
  67         }
  68     }
  69 
  70     /*
  71      * WARNING: Don't call it on the Toolkit thread.
  72      *
  73      * Checks if the component:
  74      * 1) accepts focus on click (in general)
  75      * 2) may be a focus owner (in particular)
  76      */
  77     @SuppressWarnings("deprecation")
  78     public static boolean shouldFocusOnClick(Component component) {
  79         boolean acceptFocusOnClick = false;
  80 
  81         // A component is generally allowed to accept focus on click


 109     public static boolean deliverFocus(Component lightweightChild,
 110                                        Component target,
 111                                        boolean temporary,
 112                                        boolean focusedWindowChangeAllowed,
 113                                        long time,
 114                                        CausedFocusEvent.Cause cause,
 115                                        Component currentFocusOwner) // provided by the descendant peers
 116     {
 117         if (lightweightChild == null) {
 118             lightweightChild = target;
 119         }
 120 
 121         Component currentOwner = currentFocusOwner;
 122         if (currentOwner != null && currentOwner.getPeer() == null) {
 123             currentOwner = null;
 124         }
 125         if (currentOwner != null) {
 126             FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
 127                                                  false, lightweightChild, cause);
 128 
 129             if (focusLog.isLoggable(PlatformLogger.FINER))
 130                 focusLog.finer("Posting focus event: " + fl);

 131             SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
 132         }
 133 
 134         FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
 135                                              false, currentOwner, cause);
 136 
 137         if (focusLog.isLoggable(PlatformLogger.FINER))
 138             focusLog.finer("Posting focus event: " + fg);

 139         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 140         return true;
 141     }
 142 
 143     // WARNING: Don't call it on the Toolkit thread.
 144     public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
 145         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 146     }
 147 
 148     // WARNING: Don't call it on the Toolkit thread.
 149     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 150                                                      Component descendant,
 151                                                      boolean temporary,
 152                                                      boolean focusedWindowChangeAllowed,
 153                                                      long time,
 154                                                      CausedFocusEvent.Cause cause)
 155     {
 156         return kfmAccessor.shouldNativelyFocusHeavyweight(
 157             heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
 158     }


  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;
  81 
  82         // A component is generally allowed to accept focus on click


 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(
 160             heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
 161     }