< prev index next >

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

Print this page




  43     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
  44 
  45     private static class KfmAccessor {
  46         private static AWTAccessor.KeyboardFocusManagerAccessor instance =
  47                 AWTAccessor.getKeyboardFocusManagerAccessor();
  48     }
  49 
  50     // The constants are copied from java.awt.KeyboardFocusManager
  51     public static final int SNFH_FAILURE         = 0;
  52     public static final int SNFH_SUCCESS_HANDLED = 1;
  53     public static final int SNFH_SUCCESS_PROCEED = 2;
  54 
  55     @Override
  56     public void clearGlobalFocusOwner(Window activeWindow) {
  57         if (activeWindow != null) {
  58             Component focusOwner = activeWindow.getFocusOwner();
  59             if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
  60                 focusLog.fine("Clearing global focus owner " + focusOwner);
  61             }
  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     public static boolean shouldFocusOnClick(Component component) {
  78         boolean acceptFocusOnClick = false;
  79 
  80         // A component is generally allowed to accept focus on click
  81         // if its peer is focusable. There're some exceptions though.
  82 
  83 
  84         // CANVAS & SCROLLBAR accept focus on click


  93             acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
  94 
  95 
  96         // Other components
  97         } else {
  98             ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
  99             acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
 100         }
 101         return acceptFocusOnClick && acc.canBeFocusOwner(component);
 102     }
 103 
 104     /*
 105      * Posts proper lost/gain focus events to the event queue.
 106      */
 107     @SuppressWarnings("deprecation")
 108     public static boolean deliverFocus(Component lightweightChild,
 109                                        Component target,
 110                                        boolean temporary,
 111                                        boolean focusedWindowChangeAllowed,
 112                                        long time,
 113                                        CausedFocusEvent.Cause cause,
 114                                        Component currentFocusOwner) // provided by the descendant peers
 115     {
 116         if (lightweightChild == null) {
 117             lightweightChild = target;
 118         }
 119 
 120         Component currentOwner = currentFocusOwner;
 121         if (currentOwner != null && !currentOwner.isDisplayable()) {
 122             currentOwner = null;
 123         }
 124         if (currentOwner != null) {
 125             FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
 126                                                  false, lightweightChild, cause);
 127 
 128             if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 129                 focusLog.finer("Posting focus event: " + fl);
 130             }
 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.Level.FINER)) {
 138             focusLog.finer("Posting focus event: " + fg);
 139         }
 140         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 141         return true;
 142     }
 143 
 144     // WARNING: Don't call it on the Toolkit thread.
 145     public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
 146         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 147     }
 148 
 149     // WARNING: Don't call it on the Toolkit thread.
 150     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 151                                                      Component descendant,
 152                                                      boolean temporary,
 153                                                      boolean focusedWindowChangeAllowed,
 154                                                      long time,
 155                                                      CausedFocusEvent.Cause cause)
 156     {
 157         return KfmAccessor.instance.shouldNativelyFocusHeavyweight(
 158             heavyweight, descendant, temporary, focusedWindowChangeAllowed,
 159                 time, cause);
 160     }
 161 
 162     public static void removeLastFocusRequest(Component heavyweight) {
 163         KfmAccessor.instance.removeLastFocusRequest(heavyweight);
 164     }
 165 
 166     // WARNING: Don't call it on the Toolkit thread.
 167     public static boolean processSynchronousLightweightTransfer(Component heavyweight,
 168                                                                 Component descendant,
 169                                                                 boolean temporary,
 170                                                                 boolean focusedWindowChangeAllowed,
 171                                                                 long time)
 172     {
 173         return KfmAccessor.instance.processSynchronousLightweightTransfer(
 174             heavyweight, descendant, temporary, focusedWindowChangeAllowed,
 175                 time);


  43     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
  44 
  45     private static class KfmAccessor {
  46         private static AWTAccessor.KeyboardFocusManagerAccessor instance =
  47                 AWTAccessor.getKeyboardFocusManagerAccessor();
  48     }
  49 
  50     // The constants are copied from java.awt.KeyboardFocusManager
  51     public static final int SNFH_FAILURE         = 0;
  52     public static final int SNFH_SUCCESS_HANDLED = 1;
  53     public static final int SNFH_SUCCESS_PROCEED = 2;
  54 
  55     @Override
  56     public void clearGlobalFocusOwner(Window activeWindow) {
  57         if (activeWindow != null) {
  58             Component focusOwner = activeWindow.getFocusOwner();
  59             if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
  60                 focusLog.fine("Clearing global focus owner " + focusOwner);
  61             }
  62             if (focusOwner != null) {
  63                 FocusEvent fl = new FocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
  64                                                      FocusEvent.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     public static boolean shouldFocusOnClick(Component component) {
  78         boolean acceptFocusOnClick = false;
  79 
  80         // A component is generally allowed to accept focus on click
  81         // if its peer is focusable. There're some exceptions though.
  82 
  83 
  84         // CANVAS & SCROLLBAR accept focus on click


  93             acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
  94 
  95 
  96         // Other components
  97         } else {
  98             ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
  99             acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
 100         }
 101         return acceptFocusOnClick && acc.canBeFocusOwner(component);
 102     }
 103 
 104     /*
 105      * Posts proper lost/gain focus events to the event queue.
 106      */
 107     @SuppressWarnings("deprecation")
 108     public static boolean deliverFocus(Component lightweightChild,
 109                                        Component target,
 110                                        boolean temporary,
 111                                        boolean focusedWindowChangeAllowed,
 112                                        long time,
 113                                        FocusEvent.Cause cause,
 114                                        Component currentFocusOwner) // provided by the descendant peers
 115     {
 116         if (lightweightChild == null) {
 117             lightweightChild = target;
 118         }
 119 
 120         Component currentOwner = currentFocusOwner;
 121         if (currentOwner != null && !currentOwner.isDisplayable()) {
 122             currentOwner = null;
 123         }
 124         if (currentOwner != null) {
 125             FocusEvent fl = new FocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
 126                                                  false, lightweightChild, cause);
 127 
 128             if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 129                 focusLog.finer("Posting focus event: " + fl);
 130             }
 131             SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
 132         }
 133 
 134         FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
 135                                              false, currentOwner, cause);
 136 
 137         if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 138             focusLog.finer("Posting focus event: " + fg);
 139         }
 140         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 141         return true;
 142     }
 143 
 144     // WARNING: Don't call it on the Toolkit thread.
 145     public static boolean requestFocusFor(Component target, FocusEvent.Cause cause) {
 146         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 147     }
 148 
 149     // WARNING: Don't call it on the Toolkit thread.
 150     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 151                                                      Component descendant,
 152                                                      boolean temporary,
 153                                                      boolean focusedWindowChangeAllowed,
 154                                                      long time,
 155                                                      FocusEvent.Cause cause)
 156     {
 157         return KfmAccessor.instance.shouldNativelyFocusHeavyweight(
 158             heavyweight, descendant, temporary, focusedWindowChangeAllowed,
 159                 time, cause);
 160     }
 161 
 162     public static void removeLastFocusRequest(Component heavyweight) {
 163         KfmAccessor.instance.removeLastFocusRequest(heavyweight);
 164     }
 165 
 166     // WARNING: Don't call it on the Toolkit thread.
 167     public static boolean processSynchronousLightweightTransfer(Component heavyweight,
 168                                                                 Component descendant,
 169                                                                 boolean temporary,
 170                                                                 boolean focusedWindowChangeAllowed,
 171                                                                 long time)
 172     {
 173         return KfmAccessor.instance.processSynchronousLightweightTransfer(
 174             heavyweight, descendant, temporary, focusedWindowChangeAllowed,
 175                 time);
< prev index next >