src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,24 +23,21 @@
* questions.
*/
package sun.awt;
import java.awt.Component;
-import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.awt.Canvas;
import java.awt.Scrollbar;
import java.awt.Panel;
import java.awt.event.FocusEvent;
import java.awt.peer.KeyboardFocusManagerPeer;
import java.awt.peer.ComponentPeer;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
+import sun.awt.AWTAccessor.ComponentAccessor;
import sun.util.logging.PlatformLogger;
public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer {
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl");
@@ -73,19 +70,19 @@
*
* Checks if the component:
* 1) accepts focus on click (in general)
* 2) may be a focus owner (in particular)
*/
- @SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
boolean acceptFocusOnClick = false;
// A component is generally allowed to accept focus on click
// if its peer is focusable. There're some exceptions though.
// CANVAS & SCROLLBAR accept focus on click
+ final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
if (component instanceof Canvas ||
component instanceof Scrollbar)
{
acceptFocusOnClick = true;
@@ -94,15 +91,14 @@
acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
// Other components
} else {
- ComponentPeer peer = (component != null ? component.getPeer() : null);
+ ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
}
- return acceptFocusOnClick &&
- AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
+ return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
/*
* Posts proper lost/gain focus events to the event queue.
*/
@@ -118,11 +114,11 @@
if (lightweightChild == null) {
lightweightChild = target;
}
Component currentOwner = currentFocusOwner;
- if (currentOwner != null && currentOwner.getPeer() == null) {
+ if (currentOwner != null && !currentOwner.isDisplayable()) {
currentOwner = null;
}
if (currentOwner != null) {
FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
false, lightweightChild, cause);