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 } 67 68 /* 69 * WARNING: Don't call it on the Toolkit thread. 70 * 71 * Checks if the component: 72 * 1) accepts focus on click (in general) 73 * 2) may be a focus owner (in particular) 74 */ 75 public static boolean shouldFocusOnClick(Component component) { 76 boolean acceptFocusOnClick = false; 77 78 // A component is generally allowed to accept focus on click 79 // if its peer is focusable. There're some exceptions though. 80 81 82 // CANVAS & SCROLLBAR accept focus on click 91 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0); 92 93 94 // Other components 95 } else { 96 ComponentPeer peer = (component != null ? acc.getPeer(component) : null); 97 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false); 98 } 99 return acceptFocusOnClick && acc.canBeFocusOwner(component); 100 } 101 102 /* 103 * Posts proper lost/gain focus events to the event queue. 104 */ 105 @SuppressWarnings("deprecation") 106 public static boolean deliverFocus(Component lightweightChild, 107 Component target, 108 boolean temporary, 109 boolean focusedWindowChangeAllowed, 110 long time, 111 CausedFocusEvent.Cause cause, 112 Component currentFocusOwner) // provided by the descendant peers 113 { 114 if (lightweightChild == null) { 115 lightweightChild = target; 116 } 117 118 Component currentOwner = currentFocusOwner; 119 if (currentOwner != null && !currentOwner.isDisplayable()) { 120 currentOwner = null; 121 } 122 if (currentOwner != null) { 123 FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST, 124 false, lightweightChild, cause); 125 126 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 127 focusLog.finer("Posting focus event: " + fl); 128 } 129 SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); 130 } 131 132 FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, 133 false, currentOwner, cause); 134 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 } | 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 FocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null, 62 FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER); 63 SunToolkit.postPriorityEvent(fl); 64 } 65 } 66 } 67 68 /* 69 * WARNING: Don't call it on the Toolkit thread. 70 * 71 * Checks if the component: 72 * 1) accepts focus on click (in general) 73 * 2) may be a focus owner (in particular) 74 */ 75 public static boolean shouldFocusOnClick(Component component) { 76 boolean acceptFocusOnClick = false; 77 78 // A component is generally allowed to accept focus on click 79 // if its peer is focusable. There're some exceptions though. 80 81 82 // CANVAS & SCROLLBAR accept focus on click 91 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0); 92 93 94 // Other components 95 } else { 96 ComponentPeer peer = (component != null ? acc.getPeer(component) : null); 97 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false); 98 } 99 return acceptFocusOnClick && acc.canBeFocusOwner(component); 100 } 101 102 /* 103 * Posts proper lost/gain focus events to the event queue. 104 */ 105 @SuppressWarnings("deprecation") 106 public static boolean deliverFocus(Component lightweightChild, 107 Component target, 108 boolean temporary, 109 boolean focusedWindowChangeAllowed, 110 long time, 111 FocusEvent.Cause cause, 112 Component currentFocusOwner) // provided by the descendant peers 113 { 114 if (lightweightChild == null) { 115 lightweightChild = target; 116 } 117 118 Component currentOwner = currentFocusOwner; 119 if (currentOwner != null && !currentOwner.isDisplayable()) { 120 currentOwner = null; 121 } 122 if (currentOwner != null) { 123 FocusEvent fl = new FocusEvent(currentOwner, FocusEvent.FOCUS_LOST, 124 false, lightweightChild, cause); 125 126 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 127 focusLog.finer("Posting focus event: " + fl); 128 } 129 SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); 130 } 131 132 FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, 133 false, currentOwner, cause); 134 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, FocusEvent.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 FocusEvent.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 } |