< prev index next >

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

Print this page




  25 package sun.awt;
  26 
  27 import java.awt.Component;
  28 import java.awt.Window;
  29 import java.awt.Canvas;
  30 import java.awt.Scrollbar;
  31 import java.awt.Panel;
  32 
  33 import java.awt.event.FocusEvent;
  34 
  35 import java.awt.peer.KeyboardFocusManagerPeer;
  36 import java.awt.peer.ComponentPeer;
  37 
  38 import sun.awt.AWTAccessor.ComponentAccessor;
  39 import sun.util.logging.PlatformLogger;
  40 
  41 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer {
  42 
  43     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
  44 
  45     private static AWTAccessor.KeyboardFocusManagerAccessor kfmAccessor =

  46         AWTAccessor.getKeyboardFocusManagerAccessor();

  47 
  48     // The constants are copied from java.awt.KeyboardFocusManager
  49     public static final int SNFH_FAILURE         = 0;
  50     public static final int SNFH_SUCCESS_HANDLED = 1;
  51     public static final int SNFH_SUCCESS_PROCEED = 2;
  52 
  53     @Override
  54     public void clearGlobalFocusOwner(Window activeWindow) {
  55         if (activeWindow != null) {
  56             Component focusOwner = activeWindow.getFocusOwner();
  57             if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
  58                 focusLog.fine("Clearing global focus owner " + focusOwner);
  59             }
  60             if (focusOwner != null) {
  61                 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
  62                                                      CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
  63                 SunToolkit.postPriorityEvent(fl);
  64             }
  65         }
  66     }


 135         if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 136             focusLog.finer("Posting focus event: " + fg);
 137         }
 138         SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
 139         return true;
 140     }
 141 
 142     // WARNING: Don't call it on the Toolkit thread.
 143     public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
 144         return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
 145     }
 146 
 147     // WARNING: Don't call it on the Toolkit thread.
 148     public static int shouldNativelyFocusHeavyweight(Component heavyweight,
 149                                                      Component descendant,
 150                                                      boolean temporary,
 151                                                      boolean focusedWindowChangeAllowed,
 152                                                      long time,
 153                                                      CausedFocusEvent.Cause cause)
 154     {
 155         return kfmAccessor.shouldNativelyFocusHeavyweight(
 156             heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);

 157     }
 158 
 159     public static void removeLastFocusRequest(Component heavyweight) {
 160         kfmAccessor.removeLastFocusRequest(heavyweight);
 161     }
 162 
 163     // WARNING: Don't call it on the Toolkit thread.
 164     public static boolean processSynchronousLightweightTransfer(Component heavyweight,
 165                                                                 Component descendant,
 166                                                                 boolean temporary,
 167                                                                 boolean focusedWindowChangeAllowed,
 168                                                                 long time)
 169     {
 170         return kfmAccessor.processSynchronousLightweightTransfer(
 171             heavyweight, descendant, temporary, focusedWindowChangeAllowed, time);

 172     }
 173 }


  25 package sun.awt;
  26 
  27 import java.awt.Component;
  28 import java.awt.Window;
  29 import java.awt.Canvas;
  30 import java.awt.Scrollbar;
  31 import java.awt.Panel;
  32 
  33 import java.awt.event.FocusEvent;
  34 
  35 import java.awt.peer.KeyboardFocusManagerPeer;
  36 import java.awt.peer.ComponentPeer;
  37 
  38 import sun.awt.AWTAccessor.ComponentAccessor;
  39 import sun.util.logging.PlatformLogger;
  40 
  41 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer {
  42 
  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     }


 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);
 176     }
 177 }
< prev index next >