author | malenkov |
Tue, 05 Feb 2013 20:07:54 +0400 | |
changeset 16892 | 24a521782b42 |
parent 13652 | 42544e68dc39 |
child 16839 | d0f2e97b7359 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package sun.awt; |
|
26 |
||
27 |
import java.awt.Component; |
|
28 |
import java.awt.KeyboardFocusManager; |
|
29 |
import java.awt.Window; |
|
2464 | 30 |
import java.awt.Canvas; |
31 |
import java.awt.Scrollbar; |
|
32 |
import java.awt.Panel; |
|
33 |
||
34 |
import java.awt.event.FocusEvent; |
|
2 | 35 |
|
36 |
import java.awt.peer.KeyboardFocusManagerPeer; |
|
2464 | 37 |
import java.awt.peer.ComponentPeer; |
2 | 38 |
|
39 |
import java.lang.reflect.InvocationTargetException; |
|
40 |
import java.lang.reflect.Method; |
|
41 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
42 |
import sun.util.logging.PlatformLogger; |
2 | 43 |
|
2464 | 44 |
public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer { |
45 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
46 |
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl"); |
2464 | 47 |
|
48 |
private static AWTAccessor.KeyboardFocusManagerAccessor kfmAccessor = |
|
49 |
AWTAccessor.getKeyboardFocusManagerAccessor(); |
|
2 | 50 |
|
2464 | 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(); |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
60 |
if (focusLog.isLoggable(PlatformLogger.FINE)) |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
61 |
focusLog.fine("Clearing global focus owner " + focusOwner); |
2464 | 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 |
} |
|
2 | 68 |
} |
69 |
||
2464 | 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 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
77 |
@SuppressWarnings("deprecation") |
2464 | 78 |
public static boolean shouldFocusOnClick(Component component) { |
79 |
boolean acceptFocusOnClick = false; |
|
80 |
||
81 |
// A component is generally allowed to accept focus on click |
|
82 |
// if its peer is focusable. There're some exceptions though. |
|
83 |
||
84 |
||
85 |
// CANVAS & SCROLLBAR accept focus on click |
|
86 |
if (component instanceof Canvas || |
|
87 |
component instanceof Scrollbar) |
|
88 |
{ |
|
89 |
acceptFocusOnClick = true; |
|
90 |
||
91 |
// PANEL, empty only, accepts focus on click |
|
92 |
} else if (component instanceof Panel) { |
|
93 |
acceptFocusOnClick = (((Panel)component).getComponentCount() == 0); |
|
94 |
||
95 |
||
96 |
// Other components |
|
97 |
} else { |
|
98 |
ComponentPeer peer = (component != null ? component.getPeer() : null); |
|
99 |
acceptFocusOnClick = (peer != null ? peer.isFocusable() : false); |
|
100 |
} |
|
101 |
return acceptFocusOnClick && |
|
102 |
AWTAccessor.getComponentAccessor().canBeFocusOwner(component); |
|
2 | 103 |
} |
104 |
||
2464 | 105 |
/* |
106 |
* Posts proper lost/gain focus events to the event queue. |
|
107 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
108 |
@SuppressWarnings("deprecation") |
2464 | 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) { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
118 |
lightweightChild = target; |
2464 | 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 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
129 |
if (focusLog.isLoggable(PlatformLogger.FINER)) |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
130 |
focusLog.finer("Posting focus event: " + fl); |
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
131 |
SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); |
2464 | 132 |
} |
133 |
||
134 |
FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, |
|
135 |
false, currentOwner, cause); |
|
136 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
137 |
if (focusLog.isLoggable(PlatformLogger.FINER)) |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2464
diff
changeset
|
138 |
focusLog.finer("Posting focus event: " + fg); |
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
139 |
SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg); |
2464 | 140 |
return true; |
2 | 141 |
} |
142 |
||
2464 | 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 |
} |
|
159 |
||
2 | 160 |
public static void removeLastFocusRequest(Component heavyweight) { |
2464 | 161 |
kfmAccessor.removeLastFocusRequest(heavyweight); |
162 |
} |
|
163 |
||
164 |
// WARNING: Don't call it on the Toolkit thread. |
|
165 |
public static boolean processSynchronousLightweightTransfer(Component heavyweight, |
|
166 |
Component descendant, |
|
167 |
boolean temporary, |
|
168 |
boolean focusedWindowChangeAllowed, |
|
169 |
long time) |
|
170 |
{ |
|
171 |
return kfmAccessor.processSynchronousLightweightTransfer( |
|
172 |
heavyweight, descendant, temporary, focusedWindowChangeAllowed, time); |
|
2 | 173 |
} |
174 |
} |