< prev index next >
src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java
Print this page
*** 38,48 ****
import sun.util.logging.PlatformLogger;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.AWTAccessor;
- import sun.awt.CausedFocusEvent;
import sun.awt.TimedWindowEvent;
/**
* The default KeyboardFocusManager for AWT applications. Focus traversal is
* done in response to a Component's focus traversal keys, and using a
--- 38,47 ----
*** 163,179 ****
}
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
boolean clearOnFailure)
{
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
! toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK))
{
return true;
} else {
Component nextFocus = toFocus.getNextFocusCandidate();
if (nextFocus != null && nextFocus != vetoedComponent &&
! nextFocus.requestFocusInWindow(CausedFocusEvent.Cause.ROLLBACK))
{
return true;
} else if (clearOnFailure) {
clearGlobalFocusOwnerPriv();
return true;
--- 162,178 ----
}
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
boolean clearOnFailure)
{
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
! toFocus.requestFocus(false, FocusEvent.Cause.ROLLBACK))
{
return true;
} else {
Component nextFocus = toFocus.getNextFocusCandidate();
if (nextFocus != null && nextFocus != vetoedComponent &&
! nextFocus.requestFocusInWindow(FocusEvent.Cause.ROLLBACK))
{
return true;
} else if (clearOnFailure) {
clearGlobalFocusOwnerPriv();
return true;
*** 429,445 ****
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("tempLost {0}, toFocus {1}",
tempLost, toFocus);
}
if (tempLost != null) {
! tempLost.requestFocusInWindow(CausedFocusEvent.Cause.ACTIVATION);
}
if (toFocus != null && toFocus != tempLost) {
// If there is a component which requested focus when this window
// was inactive it expects to receive focus after activation.
! toFocus.requestFocusInWindow(CausedFocusEvent.Cause.ACTIVATION);
}
}
Window realOppositeWindow = this.realOppositeWindowWR.get();
if (realOppositeWindow != we.getOppositeWindow()) {
--- 428,444 ----
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("tempLost {0}, toFocus {1}",
tempLost, toFocus);
}
if (tempLost != null) {
! tempLost.requestFocusInWindow(FocusEvent.Cause.ACTIVATION);
}
if (toFocus != null && toFocus != tempLost) {
// If there is a component which requested focus when this window
// was inactive it expects to receive focus after activation.
! toFocus.requestFocusInWindow(FocusEvent.Cause.ACTIVATION);
}
}
Window realOppositeWindow = this.realOppositeWindowWR.get();
if (realOppositeWindow != we.getOppositeWindow()) {
*** 488,499 ****
return typeAheadAssertions(newActiveWindow, we);
}
case FocusEvent.FOCUS_GAINED: {
FocusEvent fe = (FocusEvent)e;
- CausedFocusEvent.Cause cause = (fe instanceof CausedFocusEvent) ?
- ((CausedFocusEvent)fe).getCause() : CausedFocusEvent.Cause.UNKNOWN;
Component oldFocusOwner = getGlobalFocusOwner();
Component newFocusOwner = fe.getComponent();
if (oldFocusOwner == newFocusOwner) {
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
focusLog.fine("Skipping {0} because focus owner is the same", e);
--- 487,496 ----
*** 507,520 ****
// If there exists a current focus owner, then notify it that
// it has lost focus.
if (oldFocusOwner != null) {
boolean isEventDispatched =
sendMessage(oldFocusOwner,
! new CausedFocusEvent(oldFocusOwner,
FocusEvent.FOCUS_LOST,
fe.isTemporary(),
! newFocusOwner, cause));
// Failed to dispatch, clear by ourselves
if (!isEventDispatched) {
setGlobalFocusOwner(null);
if (!fe.isTemporary()) {
setGlobalPermanentFocusOwner(null);
--- 504,517 ----
// If there exists a current focus owner, then notify it that
// it has lost focus.
if (oldFocusOwner != null) {
boolean isEventDispatched =
sendMessage(oldFocusOwner,
! new FocusEvent(oldFocusOwner,
FocusEvent.FOCUS_LOST,
fe.isTemporary(),
! newFocusOwner, fe.getCause()));
// Failed to dispatch, clear by ourselves
if (!isEventDispatched) {
setGlobalFocusOwner(null);
if (!fe.isTemporary()) {
setGlobalPermanentFocusOwner(null);
*** 550,560 ****
if (!(newFocusOwner.isFocusable() && newFocusOwner.isShowing() &&
// Refuse focus on a disabled component if the focus event
// isn't of UNKNOWN reason (i.e. not a result of a direct request
// but traversal, activation or system generated).
! (newFocusOwner.isEnabled() || cause.equals(CausedFocusEvent.Cause.UNKNOWN))))
{
// we should not accept focus on such component, so reject it.
dequeueKeyEvents(-1, newFocusOwner);
if (KeyboardFocusManager.isAutoFocusTransferEnabled()) {
// If FOCUS_GAINED is for a disposed component (however
--- 547,557 ----
if (!(newFocusOwner.isFocusable() && newFocusOwner.isShowing() &&
// Refuse focus on a disabled component if the focus event
// isn't of UNKNOWN reason (i.e. not a result of a direct request
// but traversal, activation or system generated).
! (newFocusOwner.isEnabled() || fe.getCause().equals(FocusEvent.Cause.UNKNOWN))))
{
// we should not accept focus on such component, so reject it.
dequeueKeyEvents(-1, newFocusOwner);
if (KeyboardFocusManager.isAutoFocusTransferEnabled()) {
// If FOCUS_GAINED is for a disposed component (however
*** 599,612 ****
setNativeFocusOwner(getHeavyweight(newFocusOwner));
Component realOppositeComponent = this.realOppositeComponentWR.get();
if (realOppositeComponent != null &&
realOppositeComponent != fe.getOppositeComponent()) {
! fe = new CausedFocusEvent(newFocusOwner,
FocusEvent.FOCUS_GAINED,
fe.isTemporary(),
! realOppositeComponent, cause);
((AWTEvent) fe).isPosted = true;
}
return typeAheadAssertions(newFocusOwner, fe);
}
--- 596,609 ----
setNativeFocusOwner(getHeavyweight(newFocusOwner));
Component realOppositeComponent = this.realOppositeComponentWR.get();
if (realOppositeComponent != null &&
realOppositeComponent != fe.getOppositeComponent()) {
! fe = new FocusEvent(newFocusOwner,
FocusEvent.FOCUS_GAINED,
fe.isTemporary(),
! realOppositeComponent, fe.getCause());
((AWTEvent) fe).isPosted = true;
}
return typeAheadAssertions(newFocusOwner, fe);
}
*** 727,740 ****
}
if (oppositeComp == null) {
oppositeComp = oppositeWindow;
}
sendMessage(currentFocusOwner,
! new CausedFocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
true,
! oppositeComp, CausedFocusEvent.Cause.ACTIVATION));
}
setGlobalFocusedWindow(null);
if (getGlobalFocusedWindow() != null) {
// Focus change was rejected. Unlikely, but possible.
--- 724,737 ----
}
if (oppositeComp == null) {
oppositeComp = oppositeWindow;
}
sendMessage(currentFocusOwner,
! new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
true,
! oppositeComp, FocusEvent.Cause.ACTIVATION));
}
setGlobalFocusedWindow(null);
if (getGlobalFocusedWindow() != null) {
// Focus change was rejected. Unlikely, but possible.
< prev index next >