63 public void clearGlobalFocusOwner(Window activeWindow) {
64 if (activeWindow != null) {
65 Component focusOwner = activeWindow.getFocusOwner();
66 if (focusLog.isLoggable(PlatformLogger.FINE))
67 focusLog.fine("Clearing global focus owner " + focusOwner);
68 if (focusOwner != null) {
69 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
70 CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
71 SunToolkit.postPriorityEvent(fl);
72 }
73 }
74 }
75
76 /*
77 * WARNING: Don't call it on the Toolkit thread.
78 *
79 * Checks if the component:
80 * 1) accepts focus on click (in general)
81 * 2) may be a focus owner (in particular)
82 */
83 public static boolean shouldFocusOnClick(Component component) {
84 boolean acceptFocusOnClick = false;
85
86 // A component is generally allowed to accept focus on click
87 // if its peer is focusable. There're some exceptions though.
88
89
90 // CANVAS & SCROLLBAR accept focus on click
91 if (component instanceof Canvas ||
92 component instanceof Scrollbar)
93 {
94 acceptFocusOnClick = true;
95
96 // PANEL, empty only, accepts focus on click
97 } else if (component instanceof Panel) {
98 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
99
100
101 // Other components
102 } else {
103 ComponentPeer peer = (component != null ? component.getPeer() : null);
104 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
105 }
106 return acceptFocusOnClick &&
107 AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
108 }
109
110 /*
111 * Posts proper lost/gain focus events to the event queue.
112 */
113 public static boolean deliverFocus(Component lightweightChild,
114 Component target,
115 boolean temporary,
116 boolean focusedWindowChangeAllowed,
117 long time,
118 CausedFocusEvent.Cause cause,
119 Component currentFocusOwner) // provided by the descendant peers
120 {
121 if (lightweightChild == null) {
122 lightweightChild = (Component)target;
123 }
124
125 Component currentOwner = currentFocusOwner;
126 if (currentOwner != null && currentOwner.getPeer() == null) {
127 currentOwner = null;
128 }
129 if (currentOwner != null) {
130 FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
131 false, lightweightChild, cause);
132
133 if (focusLog.isLoggable(PlatformLogger.FINER))
134 focusLog.finer("Posting focus event: " + fl);
135 SunToolkit.postPriorityEvent(fl);
136 }
137
138 FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
139 false, currentOwner, cause);
140
141 if (focusLog.isLoggable(PlatformLogger.FINER))
142 focusLog.finer("Posting focus event: " + fg);
|
63 public void clearGlobalFocusOwner(Window activeWindow) {
64 if (activeWindow != null) {
65 Component focusOwner = activeWindow.getFocusOwner();
66 if (focusLog.isLoggable(PlatformLogger.FINE))
67 focusLog.fine("Clearing global focus owner " + focusOwner);
68 if (focusOwner != null) {
69 FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
70 CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
71 SunToolkit.postPriorityEvent(fl);
72 }
73 }
74 }
75
76 /*
77 * WARNING: Don't call it on the Toolkit thread.
78 *
79 * Checks if the component:
80 * 1) accepts focus on click (in general)
81 * 2) may be a focus owner (in particular)
82 */
83 @SuppressWarnings("deprecation")
84 public static boolean shouldFocusOnClick(Component component) {
85 boolean acceptFocusOnClick = false;
86
87 // A component is generally allowed to accept focus on click
88 // if its peer is focusable. There're some exceptions though.
89
90
91 // CANVAS & SCROLLBAR accept focus on click
92 if (component instanceof Canvas ||
93 component instanceof Scrollbar)
94 {
95 acceptFocusOnClick = true;
96
97 // PANEL, empty only, accepts focus on click
98 } else if (component instanceof Panel) {
99 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
100
101
102 // Other components
103 } else {
104 ComponentPeer peer = (component != null ? component.getPeer() : null);
105 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
106 }
107 return acceptFocusOnClick &&
108 AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
109 }
110
111 /*
112 * Posts proper lost/gain focus events to the event queue.
113 */
114 @SuppressWarnings("deprecation")
115 public static boolean deliverFocus(Component lightweightChild,
116 Component target,
117 boolean temporary,
118 boolean focusedWindowChangeAllowed,
119 long time,
120 CausedFocusEvent.Cause cause,
121 Component currentFocusOwner) // provided by the descendant peers
122 {
123 if (lightweightChild == null) {
124 lightweightChild = target;
125 }
126
127 Component currentOwner = currentFocusOwner;
128 if (currentOwner != null && currentOwner.getPeer() == null) {
129 currentOwner = null;
130 }
131 if (currentOwner != null) {
132 FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
133 false, lightweightChild, cause);
134
135 if (focusLog.isLoggable(PlatformLogger.FINER))
136 focusLog.finer("Posting focus event: " + fl);
137 SunToolkit.postPriorityEvent(fl);
138 }
139
140 FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
141 false, currentOwner, cause);
142
143 if (focusLog.isLoggable(PlatformLogger.FINER))
144 focusLog.finer("Posting focus event: " + fg);
|