--- old/src/java.desktop/share/classes/sun/awt/CausedFocusEvent.java 2015-10-27 12:48:04.033491700 +0300
+++ /dev/null 2015-10-27 12:48:04.000000000 +0300
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2003, 2011, 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
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.awt;
-
-import java.awt.event.FocusEvent;
-import java.awt.Component;
-
-/**
- * This class represents FocusEvents with a known "cause" - reason why this event happened. It can
- * be mouse press, traversal, activation, and so on - all causes are described as Cause enum. The
- * event with the cause can be constructed in two ways - explicitly through constructor of
- * CausedFocusEvent class or implicitly, by calling appropriate requestFocusXXX method with "cause"
- * parameter. The default cause is UNKNOWN.
- */
-@SuppressWarnings("serial")
-public class CausedFocusEvent extends FocusEvent {
- public enum Cause {
- UNKNOWN,
- MOUSE_EVENT,
- TRAVERSAL,
- TRAVERSAL_UP,
- TRAVERSAL_DOWN,
- TRAVERSAL_FORWARD,
- TRAVERSAL_BACKWARD,
- MANUAL_REQUEST,
- AUTOMATIC_TRAVERSE,
- ROLLBACK,
- NATIVE_SYSTEM,
- ACTIVATION,
- CLEAR_GLOBAL_FOCUS_OWNER,
- RETARGETED
- };
-
- private final Cause cause;
-
- public Cause getCause() {
- return cause;
- }
-
- public String toString() {
- return "java.awt.FocusEvent[" + super.paramString() + ",cause=" + cause + "] on " + getSource();
- }
-
- public CausedFocusEvent(Component source, int id, boolean temporary,
- Component opposite, Cause cause) {
- super(source, id, temporary, opposite);
- if (cause == null) {
- cause = Cause.UNKNOWN;
- }
- this.cause = cause;
- }
-
- /**
- * Retargets the original focus event to the new target. If the
- * original focus event is CausedFocusEvent, it remains such and
- * cause is copied. Otherwise, new CausedFocusEvent is created,
- * with cause as RETARGETED.
- * @return retargeted event, or null if e is null
- */
- public static FocusEvent retarget(FocusEvent e, Component newSource) {
- if (e == null) return null;
-
- return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
- (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
- }
-}
--- old/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java 2015-10-27 12:48:05.353623700 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java 2015-10-27 12:48:04.951583500 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -903,7 +903,7 @@
@Override
public boolean requestFocus(Component lightweightChild, boolean temporary,
boolean focusedWindowChangeAllowed, long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
focusLog.finest("lightweightChild=" + lightweightChild + ", temporary=" + temporary +
@@ -1278,7 +1278,7 @@
assert (e.getSource() == target);
if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
- LWKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
+ LWKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
}
}
--- old/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java 2015-10-27 12:48:07.718860200 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java 2015-10-27 12:48:07.314819800 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -31,8 +31,8 @@
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.dnd.DropTarget;
+import java.awt.event.FocusEvent;
-import sun.awt.CausedFocusEvent;
import sun.awt.LightweightFrame;
import sun.swing.JLightweightFrame;
import sun.swing.SwingAccessor;
@@ -60,7 +60,7 @@
}
@Override
- public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+ public boolean requestWindowFocus(FocusEvent.Cause cause) {
if (!focusAllowedFor()) {
return false;
}
--- old/src/java.desktop/macosx/classes/sun/lwawt/LWWindowPeer.java 2015-10-27 12:48:10.031091400 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/LWWindowPeer.java 2015-10-27 12:48:09.622050500 +0300
@@ -256,14 +256,14 @@
if (!getTarget().isAutoRequestFocus()) {
return;
} else {
- requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
+ requestWindowFocus(FocusEvent.Cause.ACTIVATION);
}
// Focus the owner in case this window is focused.
} else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
// Transfer focus to the owner.
LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
if (owner != null) {
- owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
+ owner.requestWindowFocus(FocusEvent.Cause.ACTIVATION);
}
}
}
@@ -848,7 +848,7 @@
// 2. An active but not focused owner frame/dialog is clicked.
// The mouse event then will trigger a focus request "in window" to the component, so the window
// should gain focus before.
- requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
+ requestWindowFocus(FocusEvent.Cause.MOUSE_EVENT);
mouseDownTarget[targetIdx] = targetPeer;
} else if (id == MouseEvent.MOUSE_DRAGGED) {
@@ -1197,7 +1197,7 @@
* Requests platform to set native focus on a frame/dialog.
* In case of a simple window, triggers appropriate java focus change.
*/
- public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+ public boolean requestWindowFocus(FocusEvent.Cause cause) {
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
focusLog.fine("requesting native focus to " + this);
}
--- old/src/java.desktop/macosx/classes/sun/lwawt/PlatformWindow.java 2015-10-27 12:48:12.279316200 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/PlatformWindow.java 2015-10-27 12:48:11.874275700 +0300
@@ -26,8 +26,8 @@
package sun.lwawt;
import java.awt.*;
+import java.awt.event.FocusEvent;
-import sun.awt.CausedFocusEvent;
import sun.java2d.SurfaceData;
// TODO Is it worth to generify this interface, like that:
@@ -114,7 +114,7 @@
public void updateFocusableWindowState();
- public boolean rejectFocusRequest(CausedFocusEvent.Cause cause);
+ public boolean rejectFocusRequest(FocusEvent.Cause cause);
public boolean requestWindowFocus();
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java 2015-10-27 12:48:14.457534000 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java 2015-10-27 12:48:14.049493200 +0300
@@ -26,6 +26,7 @@
package sun.lwawt.macosx;
import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
import java.awt.peer.*;
import java.awt.BufferCapabilities.FlipContents;
import java.awt.event.*;
@@ -34,7 +35,6 @@
import java.util.List;
import java.io.*;
-import sun.awt.CausedFocusEvent.Cause;
import sun.awt.AWTAccessor;
import sun.java2d.pipe.Region;
import sun.misc.ManagedLocalsThread;
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java 2015-10-27 12:48:16.607749000 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java 2015-10-27 12:48:16.206708900 +0300
@@ -26,7 +26,8 @@
package sun.lwawt.macosx;
import java.awt.*;
-import sun.awt.CausedFocusEvent;
+import java.awt.event.FocusEvent;
+
import sun.java2d.SurfaceData;
import sun.java2d.opengl.CGLLayer;
import sun.lwawt.LWWindowPeer;
@@ -133,9 +134,9 @@
public void updateFocusableWindowState() {}
@Override
- public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
+ public boolean rejectFocusRequest(FocusEvent.Cause cause) {
// Cross-app activation requests are not allowed.
- if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
+ if (cause != FocusEvent.Cause.MOUSE_EVENT &&
!target.isParentWindowActive())
{
focusLogger.fine("the embedder is inactive, so the request is rejected");
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java 2015-10-27 12:48:18.769965200 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java 2015-10-27 12:48:18.352923500 +0300
@@ -37,7 +37,6 @@
import java.awt.Window;
import sun.awt.CGraphicsDevice;
import sun.awt.CGraphicsEnvironment;
-import sun.awt.CausedFocusEvent;
import sun.awt.LightweightFrame;
import sun.java2d.SurfaceData;
import sun.lwawt.LWLightweightFramePeer;
@@ -134,7 +133,7 @@
}
@Override
- public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
+ public boolean rejectFocusRequest(FocusEvent.Cause cause) {
return false;
}
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2015-10-27 12:48:20.921180300 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2015-10-27 12:48:20.522140400 +0300
@@ -706,9 +706,9 @@
}
@Override
- public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
+ public boolean rejectFocusRequest(FocusEvent.Cause cause) {
// Cross-app activation requests are not allowed.
- if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
+ if (cause != FocusEvent.Cause.MOUSE_EVENT &&
!((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
{
focusLogger.fine("the app is inactive, so the request is rejected");
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java 2015-10-27 12:48:23.199408100 +0300
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java 2015-10-27 12:48:22.735361700 +0300
@@ -33,7 +33,7 @@
import java.awt.MenuBar;
import java.awt.Point;
import java.awt.Window;
-import sun.awt.CausedFocusEvent.Cause;
+import java.awt.event.FocusEvent.Cause;
import sun.java2d.SurfaceData;
import sun.lwawt.LWWindowPeer;
import sun.lwawt.PlatformWindow;
--- old/src/java.desktop/share/classes/java/awt/Component.java 2015-10-27 12:48:25.317619900 +0300
+++ new/src/java.desktop/share/classes/java/awt/Component.java 2015-10-27 12:48:24.920580200 +0300
@@ -68,7 +68,6 @@
import sun.awt.ConstrainableGraphics;
import sun.awt.SubRegionShowable;
import sun.awt.SunToolkit;
-import sun.awt.CausedFocusEvent;
import sun.awt.EmbeddedFrame;
import sun.awt.dnd.SunDropTargetEvent;
import sun.awt.im.CompositionArea;
@@ -878,7 +877,7 @@
{
comp.setGraphicsConfiguration(gc);
}
- public boolean requestFocus(Component comp, CausedFocusEvent.Cause cause) {
+ public boolean requestFocus(Component comp, FocusEvent.Cause cause) {
return comp.requestFocus(cause);
}
public boolean canBeFocusOwner(Component comp) {
@@ -7540,7 +7539,7 @@
requestFocusHelper(false, true);
}
- boolean requestFocus(CausedFocusEvent.Cause cause) {
+ boolean requestFocus(FocusEvent.Cause cause) {
return requestFocusHelper(false, true, cause);
}
@@ -7607,7 +7606,7 @@
return requestFocusHelper(temporary, true);
}
- boolean requestFocus(boolean temporary, CausedFocusEvent.Cause cause) {
+ boolean requestFocus(boolean temporary, FocusEvent.Cause cause) {
return requestFocusHelper(temporary, true, cause);
}
/**
@@ -7658,7 +7657,7 @@
return requestFocusHelper(false, false);
}
- boolean requestFocusInWindow(CausedFocusEvent.Cause cause) {
+ boolean requestFocusInWindow(FocusEvent.Cause cause) {
return requestFocusHelper(false, false, cause);
}
@@ -7723,18 +7722,18 @@
return requestFocusHelper(temporary, false);
}
- boolean requestFocusInWindow(boolean temporary, CausedFocusEvent.Cause cause) {
+ boolean requestFocusInWindow(boolean temporary, FocusEvent.Cause cause) {
return requestFocusHelper(temporary, false, cause);
}
final boolean requestFocusHelper(boolean temporary,
boolean focusedWindowChangeAllowed) {
- return requestFocusHelper(temporary, focusedWindowChangeAllowed, CausedFocusEvent.Cause.UNKNOWN);
+ return requestFocusHelper(temporary, focusedWindowChangeAllowed, FocusEvent.Cause.UNKNOWN);
}
final boolean requestFocusHelper(boolean temporary,
boolean focusedWindowChangeAllowed,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
// 1) Check if the event being dispatched is a system-generated mouse event.
AWTEvent currentEvent = EventQueue.getCurrentEvent();
@@ -7822,7 +7821,7 @@
private boolean isRequestFocusAccepted(boolean temporary,
boolean focusedWindowChangeAllowed,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if (!isFocusable() || !isVisible()) {
if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
@@ -7869,7 +7868,7 @@
return true;
}
- if (CausedFocusEvent.Cause.ACTIVATION == cause) {
+ if (FocusEvent.Cause.ACTIVATION == cause) {
// we shouldn't call RequestFocusController in case we are
// in activation. We do request focus on component which
// has got temporary focus lost and then on component which is
@@ -7901,7 +7900,7 @@
private static class DummyRequestFocusController implements RequestFocusController {
public boolean acceptRequestFocus(Component from, Component to,
boolean temporary, boolean focusedWindowChangeAllowed,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
return true;
}
@@ -7985,7 +7984,7 @@
Component toFocus = getNextFocusCandidate();
boolean res = false;
if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
- res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
+ res = toFocus.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_FORWARD);
}
if (clearOnFailure && !res) {
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
@@ -8065,7 +8064,7 @@
toFocus = policy.getDefaultComponent(rootAncestor);
}
if (toFocus != null) {
- res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
+ res = toFocus.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_BACKWARD);
}
}
if (clearOnFailure && !res) {
@@ -8110,7 +8109,7 @@
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setGlobalCurrentFocusCycleRootPriv(fcr);
- rootAncestor.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
+ rootAncestor.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
} else {
Window window = getContainingWindow();
@@ -8120,7 +8119,7 @@
if (toFocus != null) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setGlobalCurrentFocusCycleRootPriv(window);
- toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
+ toFocus.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
}
}
}
--- old/src/java.desktop/share/classes/java/awt/Container.java 2015-10-27 12:48:27.880875300 +0300
+++ new/src/java.desktop/share/classes/java/awt/Container.java 2015-10-27 12:48:27.479835200 +0300
@@ -55,7 +55,6 @@
import sun.awt.AppContext;
import sun.awt.AWTAccessor;
-import sun.awt.CausedFocusEvent;
import sun.awt.PeerEvent;
import sun.awt.SunToolkit;
@@ -3515,7 +3514,7 @@
Component toFocus = getFocusTraversalPolicy().
getDefaultComponent(this);
if (toFocus != null) {
- toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_DOWN);
+ toFocus.requestFocus(FocusEvent.Cause.TRAVERSAL_DOWN);
}
}
}
--- old/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java 2015-10-27 12:48:30.333116000 +0300
+++ new/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java 2015-10-27 12:48:29.891071800 +0300
@@ -40,7 +40,6 @@
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.AWTAccessor;
-import sun.awt.CausedFocusEvent;
import sun.awt.TimedWindowEvent;
/**
@@ -165,13 +164,13 @@
boolean clearOnFailure)
{
if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
- toFocus.requestFocus(false, CausedFocusEvent.Cause.ROLLBACK))
+ toFocus.requestFocus(false, FocusEvent.Cause.ROLLBACK))
{
return true;
} else {
Component nextFocus = toFocus.getNextFocusCandidate();
if (nextFocus != null && nextFocus != vetoedComponent &&
- nextFocus.requestFocusInWindow(CausedFocusEvent.Cause.ROLLBACK))
+ nextFocus.requestFocusInWindow(FocusEvent.Cause.ROLLBACK))
{
return true;
} else if (clearOnFailure) {
@@ -431,13 +430,13 @@
tempLost, toFocus);
}
if (tempLost != null) {
- tempLost.requestFocusInWindow(CausedFocusEvent.Cause.ACTIVATION);
+ 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(CausedFocusEvent.Cause.ACTIVATION);
+ toFocus.requestFocusInWindow(FocusEvent.Cause.ACTIVATION);
}
}
@@ -490,8 +489,6 @@
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) {
@@ -509,10 +506,10 @@
if (oldFocusOwner != null) {
boolean isEventDispatched =
sendMessage(oldFocusOwner,
- new CausedFocusEvent(oldFocusOwner,
+ new FocusEvent(oldFocusOwner,
FocusEvent.FOCUS_LOST,
fe.isTemporary(),
- newFocusOwner, cause));
+ newFocusOwner, fe.getCause()));
// Failed to dispatch, clear by ourselves
if (!isEventDispatched) {
setGlobalFocusOwner(null);
@@ -552,7 +549,7 @@
// 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))))
+ (newFocusOwner.isEnabled() || fe.getCause().equals(FocusEvent.Cause.UNKNOWN))))
{
// we should not accept focus on such component, so reject it.
dequeueKeyEvents(-1, newFocusOwner);
@@ -601,10 +598,10 @@
Component realOppositeComponent = this.realOppositeComponentWR.get();
if (realOppositeComponent != null &&
realOppositeComponent != fe.getOppositeComponent()) {
- fe = new CausedFocusEvent(newFocusOwner,
+ fe = new FocusEvent(newFocusOwner,
FocusEvent.FOCUS_GAINED,
fe.isTemporary(),
- realOppositeComponent, cause);
+ realOppositeComponent, fe.getCause());
((AWTEvent) fe).isPosted = true;
}
return typeAheadAssertions(newFocusOwner, fe);
@@ -729,10 +726,10 @@
oppositeComp = oppositeWindow;
}
sendMessage(currentFocusOwner,
- new CausedFocusEvent(currentFocusOwner,
+ new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
true,
- oppositeComp, CausedFocusEvent.Cause.ACTIVATION));
+ oppositeComp, FocusEvent.Cause.ACTIVATION));
}
setGlobalFocusedWindow(null);
--- old/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java 2015-10-27 12:48:32.595342200 +0300
+++ new/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java 2015-10-27 12:48:32.185301200 +0300
@@ -57,7 +57,6 @@
import sun.awt.AppContext;
import sun.awt.SunToolkit;
-import sun.awt.CausedFocusEvent;
import sun.awt.KeyboardFocusManagerPeerProvider;
import sun.awt.AWTAccessor;
@@ -124,7 +123,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
return KeyboardFocusManager.shouldNativelyFocusHeavyweight(
heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
@@ -2160,9 +2159,9 @@
private static final class LightweightFocusRequest {
final Component component;
final boolean temporary;
- final CausedFocusEvent.Cause cause;
+ final FocusEvent.Cause cause;
- LightweightFocusRequest(Component component, boolean temporary, CausedFocusEvent.Cause cause) {
+ LightweightFocusRequest(Component component, boolean temporary, FocusEvent.Cause cause) {
this.component = component;
this.temporary = temporary;
this.cause = cause;
@@ -2186,7 +2185,7 @@
}
HeavyweightFocusRequest(Component heavyweight, Component descendant,
- boolean temporary, CausedFocusEvent.Cause cause) {
+ boolean temporary, FocusEvent.Cause cause) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (heavyweight == null) {
log.fine("Assertion (heavyweight != null) failed");
@@ -2198,7 +2197,7 @@
addLightweightRequest(descendant, temporary, cause);
}
boolean addLightweightRequest(Component descendant,
- boolean temporary, CausedFocusEvent.Cause cause) {
+ boolean temporary, FocusEvent.Cause cause) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (this == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) {
log.fine("Assertion (this != HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER) failed");
@@ -2310,7 +2309,7 @@
hwFocusRequest =
new HeavyweightFocusRequest(heavyweight, descendant,
- temporary, CausedFocusEvent.Cause.UNKNOWN);
+ temporary, FocusEvent.Cause.UNKNOWN);
heavyweightRequests.add(hwFocusRequest);
if (currentFocusOwner != null) {
@@ -2375,7 +2374,7 @@
*/
static int shouldNativelyFocusHeavyweight
(Component heavyweight, Component descendant, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
+ boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause)
{
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (heavyweight == null) {
@@ -2441,7 +2440,7 @@
if (currentFocusOwner != null) {
FocusEvent currentFocusOwnerEvent =
- new CausedFocusEvent(currentFocusOwner,
+ new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
temporary, descendant, cause);
// Fix 5028014. Rolled out.
@@ -2450,7 +2449,7 @@
currentFocusOwnerEvent);
}
FocusEvent newFocusOwnerEvent =
- new CausedFocusEvent(descendant, FocusEvent.FOCUS_GAINED,
+ new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
temporary, currentFocusOwner, cause);
// Fix 5028014. Rolled out.
// SunToolkit.postPriorityEvent(newFocusOwnerEvent);
@@ -2666,13 +2665,13 @@
* lw requests.
*/
if (currentFocusOwner != null) {
- currentFocusOwnerEvent = new CausedFocusEvent(currentFocusOwner,
+ currentFocusOwnerEvent = new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
lwFocusRequest.temporary,
lwFocusRequest.component, lwFocusRequest.cause);
}
FocusEvent newFocusOwnerEvent =
- new CausedFocusEvent(lwFocusRequest.component,
+ new FocusEvent(lwFocusRequest.component,
FocusEvent.FOCUS_GAINED,
lwFocusRequest.temporary,
currentFocusOwner == null ? lastFocusOwner : currentFocusOwner,
@@ -2722,8 +2721,8 @@
{
temporary = true;
}
- return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
- CausedFocusEvent.Cause.NATIVE_SYSTEM);
+ return new FocusEvent(source, fe.getID(), temporary, opposite,
+ FocusEvent.Cause.UNEXPECTED);
}
}
@@ -2798,7 +2797,7 @@
// 'opposite' will be fixed by
// DefaultKeyboardFocusManager.realOppositeComponent
- return new CausedFocusEvent(newSource,
+ return new FocusEvent(newSource,
FocusEvent.FOCUS_GAINED, temporary,
opposite, lwFocusRequest.cause);
}
@@ -2811,8 +2810,8 @@
// If it arrives as the result of activation we should skip it
// This event will not have appropriate request record and
// on arrival there will be already some focus owner set.
- return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_GAINED, false,
- null, CausedFocusEvent.Cause.ACTIVATION);
+ return new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_GAINED, false,
+ null, FocusEvent.Cause.ACTIVATION);
}
return retargetUnexpectedFocusEvent(fe);
@@ -2835,9 +2834,9 @@
if (currentFocusOwner != null) {
// Call to KeyboardFocusManager.clearGlobalFocusOwner()
heavyweightRequests.removeFirst();
- return new CausedFocusEvent(currentFocusOwner,
+ return new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST, false, null,
- CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
+ FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
}
// Otherwise, fall through to failure case below
@@ -2846,9 +2845,9 @@
{
// Focus leaving application
if (currentFocusOwner != null) {
- return new CausedFocusEvent(currentFocusOwner,
+ return new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
- true, null, CausedFocusEvent.Cause.ACTIVATION);
+ true, null, FocusEvent.Cause.ACTIVATION);
} else {
return fe;
}
@@ -2874,15 +2873,15 @@
? true
: lwFocusRequest.temporary;
- return new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
+ return new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
temporary, lwFocusRequest.component, lwFocusRequest.cause);
} else if (focusedWindowChanged(opposite, currentFocusOwner)) {
// If top-level changed there might be no focus request in a list
// But we know the opposite, we now it is temporary - dispatch the event.
if (!fe.isTemporary() && currentFocusOwner != null) {
// Create copy of the event with only difference in temporary parameter.
- fe = new CausedFocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
- true, opposite, CausedFocusEvent.Cause.ACTIVATION);
+ fe = new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
+ true, opposite, FocusEvent.Cause.ACTIVATION);
}
return fe;
}
--- old/src/java.desktop/share/classes/java/awt/Window.java 2015-10-27 12:48:34.990581700 +0300
+++ new/src/java.desktop/share/classes/java/awt/Window.java 2015-10-27 12:48:34.586541300 +0300
@@ -52,7 +52,6 @@
import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext;
-import sun.awt.CausedFocusEvent;
import sun.awt.DebugSettings;
import sun.awt.SunToolkit;
import sun.awt.util.IdentityArrayList;
@@ -2603,7 +2602,7 @@
{
Component toFocus =
KeyboardFocusManager.getMostRecentFocusOwner(owner);
- if (toFocus != null && toFocus.requestFocus(false, CausedFocusEvent.Cause.ACTIVATION)) {
+ if (toFocus != null && toFocus.requestFocus(false, FocusEvent.Cause.ACTIVATION)) {
return;
}
}
--- old/src/java.desktop/share/classes/java/awt/event/FocusEvent.java 2015-10-27 12:48:37.282810900 +0300
+++ new/src/java.desktop/share/classes/java/awt/event/FocusEvent.java 2015-10-27 12:48:36.889771600 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -25,18 +25,19 @@
package java.awt.event;
-import java.awt.Component;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
+import java.awt.*;
+
/**
* A low-level event which indicates that a Component has gained or lost the
* input focus. This low-level event is generated by a Component (such as a
- * TextField). The event is passed to every FocusListener
or
- * FocusAdapter
object which registered to receive such events
- * using the Component's addFocusListener
method. (
- * FocusAdapter
objects implement the FocusListener
- * interface.) Each such listener object gets this FocusEvent
when
+ * TextField). The event is passed to every {@code FocusListener} or
+ * {@code FocusAdapter} object which registered to receive such events
+ * using the Component's {@code addFocusListener} method. ({@code
+ * FocusAdapter} objects implement the {@code FocusListener}
+ * interface.) Each such listener object gets this {@code FocusEvent} when
* the event occurs.
*
* There are two levels of focus events: permanent and temporary. Permanent @@ -51,6 +52,10 @@ * the FOCUS_GAINED and FOCUS_LOST event ids; the level may be distinguished in * the event using the isTemporary() method. *
+ * Every {@code FocusEvent} records its cause - the reason why this event was + * generated. The cause is assigned during the focus event creation and may be + * retrieved by calling {@link #getCause}. + *
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code FocusEvent} instance is not
* in the range from {@code FOCUS_FIRST} to {@code FOCUS_LAST}.
@@ -66,6 +71,61 @@
public class FocusEvent extends ComponentEvent {
/**
+ * This enum represents the cause of a {@code FocusEvent}- the reason why it
+ * occurred. Possible reasons include mouse events, keyboard focus
+ * traversal, window activation.
+ * If no cause is provided then the reason is {@code UNKNOWN}.
+ *
+ * @since 1.9
+ */
+ public enum Cause {
+ /**
+ * The default value.
+ */
+ UNKNOWN,
+ /**
+ * An activating mouse event.
+ */
+ MOUSE_EVENT,
+ /**
+ * A focus traversal action with unspecified direction.
+ */
+ TRAVERSAL,
+ /**
+ * An up-cycle focus traversal action.
+ */
+ TRAVERSAL_UP,
+ /**
+ * A down-cycle focus traversal action.
+ */
+ TRAVERSAL_DOWN,
+ /**
+ * A forward focus traversal action.
+ */
+ TRAVERSAL_FORWARD,
+ /**
+ * A backward focus traversal action.
+ */
+ TRAVERSAL_BACKWARD,
+ /**
+ * Restoring focus after a focus request has been rejected.
+ */
+ ROLLBACK,
+ /**
+ * A system action causing an unexpected focus change.
+ */
+ UNEXPECTED,
+ /**
+ * An activation of a toplevel window.
+ */
+ ACTIVATION,
+ /**
+ * Clearing global focus owner.
+ */
+ CLEAR_GLOBAL_FOCUS_OWNER
+ }
+
+ /**
* The first number in the range of ids used for focus events.
*/
public static final int FOCUS_FIRST = 1004;
@@ -85,6 +145,8 @@
*/
public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
+ private final Cause cause;
+
/**
* A focus event can have two different levels, permanent and temporary.
* It will be set to true if some operation takes away the focus
@@ -109,62 +171,107 @@
transient Component opposite;
/*
- * JDK 1.1 serialVersionUID
+ * JDK 1.9 serialVersionUID
*/
- private static final long serialVersionUID = 523753786457416396L;
+ private static final long serialVersionUID = 523753786457416397L;
/**
- * Constructs a FocusEvent
object with the
- * specified temporary state and opposite Component
.
- * The opposite Component
is the other
- * Component
involved in this focus change.
- * For a FOCUS_GAINED
event, this is the
- * Component
that lost focus. For a
- * FOCUS_LOST
event, this is the Component
+ * Constructs a {@code FocusEvent} object with the
+ * specified temporary state and opposite {@code Component} and the
+ * {@code Cause.UNKNOWN} cause.
+ * The opposite {@code Component} is the other
+ * {@code Component} involved in this focus change.
+ * For a {@code FOCUS_GAINED} event, this is the
+ * {@code Component} that lost focus. For a
+ * {@code FOCUS_LOST} event, this is the {@code Component}
* that gained focus. If this focus change occurs with a native
* application, with a Java application in a different VM,
- * or with no other Component
, then the opposite
- * Component
is null
.
+ * or with no other {@code Component}, then the opposite
+ * {@code Component} is {@code null}.
*
This method throws an
- * IllegalArgumentException
if source
- * is null
.
+ * {@code IllegalArgumentException} if {@code source}
+ * is {@code null}.
*
- * @param source The Component
that originated the event
+ * @param source The {@code Component} that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
- * @param temporary Equals true
if the focus change is temporary;
- * false
otherwise
+ * @param temporary Equals {@code true} if the focus change is temporary;
+ * {@code false} otherwise
* @param opposite The other Component involved in the focus change,
- * or null
- * @throws IllegalArgumentException if source
equals {@code null}
+ * or {@code null}
+ * @throws IllegalArgumentException if {@code source} equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
* @see #getOppositeComponent()
+ * @see Cause#UNKNOWN
* @since 1.4
*/
public FocusEvent(Component source, int id, boolean temporary,
Component opposite) {
+ this(source, id, temporary, opposite, Cause.UNKNOWN);
+ }
+
+ /**
+ * Constructs a {@code FocusEvent} object with the
+ * specified temporary state, opposite {@code Component} and the cause.
+ * The opposite {@code Component} is the other
+ * {@code Component} involved in this focus change.
+ * For a {@code FOCUS_GAINED} event, this is the
+ * {@code Component} that lost focus. For a
+ * {@code FOCUS_LOST} event, this is the {@code Component}
+ * that gained focus. If this focus change occurs with a native
+ * application, with a Java application in a different VM,
+ * or with no other {@code Component}, then the opposite
+ * {@code Component} is {@code null}.
+ *
This method throws an
+ * {@code IllegalArgumentException} if {@code source} or {@code cause}
+ * is {@code null}.
+ *
+ * @param source The {@code Component} that originated the event
+ * @param id An integer indicating the type of event.
+ * For information on allowable values, see
+ * the class description for {@link FocusEvent}
+ * @param temporary Equals {@code true} if the focus change is temporary;
+ * {@code false} otherwise
+ * @param opposite The other Component involved in the focus change,
+ * or {@code null}
+ * @param cause The focus event cause.
+ * @throws IllegalArgumentException if {@code source} equals {@code null}
+ * or if {@code cause} equals {@code null}
+ * @see #getSource()
+ * @see #getID()
+ * @see #isTemporary()
+ * @see #getOppositeComponent()
+ * @see Cause
+ * @since 1.9
+ */
+ public FocusEvent(Component source, int id, boolean temporary,
+ Component opposite, Cause cause) {
super(source, id);
+ if (cause == null) {
+ throw new IllegalArgumentException("null cause");
+ }
this.temporary = temporary;
this.opposite = opposite;
+ this.cause = cause;
}
/**
- * Constructs a FocusEvent
object and identifies
+ * Constructs a {@code FocusEvent} object and identifies
* whether or not the change is temporary.
*
This method throws an
- * IllegalArgumentException
if source
- * is null
.
+ * {@code IllegalArgumentException} if {@code source}
+ * is {@code null}.
*
- * @param source The Component
that originated the event
+ * @param source The {@code Component} that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
- * @param temporary Equals true
if the focus change is temporary;
- * false
otherwise
- * @throws IllegalArgumentException if source
equals {@code null}
+ * @param temporary Equals {@code true} if the focus change is temporary;
+ * {@code false} otherwise
+ * @throws IllegalArgumentException if {@code source} equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
@@ -174,17 +281,17 @@
}
/**
- * Constructs a FocusEvent
object and identifies it
+ * Constructs a {@code FocusEvent} object and identifies it
* as a permanent change in focus.
*
This method throws an
- * IllegalArgumentException
if source
- * is null
.
+ * {@code IllegalArgumentException} if {@code source}
+ * is {@code null}.
*
- * @param source The Component
that originated the event
+ * @param source The {@code Component} that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
- * @throws IllegalArgumentException if source
equals {@code null}
+ * @throws IllegalArgumentException if {@code source} equals {@code null}
* @see #getSource()
* @see #getID()
*/
@@ -195,8 +302,8 @@
/**
* Identifies the focus change event as temporary or permanent.
*
- * @return true
if the focus change is temporary;
- * false
otherwise
+ * @return {@code true} if the focus change is temporary;
+ * {@code false} otherwise
*/
public boolean isTemporary() {
return temporary;
@@ -243,7 +350,16 @@
typeStr = "unknown type";
}
return typeStr + (temporary ? ",temporary" : ",permanent") +
- ",opposite=" + getOppositeComponent();
+ ",opposite=" + getOppositeComponent() + ",cause=" + getCause();
}
+ /**
+ * Returns the event cause.
+ *
+ * @return one of {@link Cause} values
+ * @since 1.9
+ */
+ public final Cause getCause() {
+ return cause;
+ }
}
--- old/src/java.desktop/share/classes/java/awt/peer/ComponentPeer.java 2015-10-27 12:48:39.460028600 +0300
+++ new/src/java.desktop/share/classes/java/awt/peer/ComponentPeer.java 2015-10-27 12:48:39.054988100 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -27,12 +27,12 @@
import java.awt.*;
import java.awt.event.PaintEvent;
+import java.awt.event.FocusEvent.Cause;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
-import sun.awt.CausedFocusEvent;
import sun.java2d.pipe.Region;
@@ -343,7 +343,7 @@
*/
boolean requestFocus(Component lightweightChild, boolean temporary,
boolean focusedWindowChangeAllowed, long time,
- CausedFocusEvent.Cause cause);
+ Cause cause);
/**
* Returns {@code true} when the component takes part in the focus
--- old/src/java.desktop/share/classes/javax/swing/JComponent.java 2015-10-27 12:48:41.659248500 +0300
+++ new/src/java.desktop/share/classes/javax/swing/JComponent.java 2015-10-27 12:48:41.238206400 +0300
@@ -3557,7 +3557,7 @@
new sun.awt.RequestFocusController() {
public boolean acceptRequestFocus(Component from, Component to,
boolean temporary, boolean focusedWindowChangeAllowed,
- sun.awt.CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if ((to == null) || !(to instanceof JComponent)) {
return true;
--- old/src/java.desktop/share/classes/sun/awt/AWTAccessor.java 2015-10-27 12:48:44.111493700 +0300
+++ new/src/java.desktop/share/classes/sun/awt/AWTAccessor.java 2015-10-27 12:48:43.690451600 +0300
@@ -29,6 +29,7 @@
import javax.accessibility.AccessibleContext;
import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
import java.awt.dnd.DragSourceContext;
import java.awt.dnd.DropTargetContext;
import java.awt.dnd.peer.DragSourceContextPeer;
@@ -104,7 +105,7 @@
/*
* Requests focus to the component.
*/
- boolean requestFocus(Component comp, CausedFocusEvent.Cause cause);
+ boolean requestFocus(Component comp, Cause cause);
/*
* Determines if the component can gain focus.
*/
@@ -438,7 +439,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause);
+ Cause cause);
/**
* Delivers focus for the lightweight descendant of the heavyweight
* synchronously.
--- old/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java 2015-10-27 12:48:46.348717400 +0300
+++ new/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java 2015-10-27 12:48:45.946677200 +0300
@@ -58,8 +58,8 @@
focusLog.fine("Clearing global focus owner " + focusOwner);
}
if (focusOwner != null) {
- FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
- CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
+ FocusEvent fl = new FocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
+ FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
SunToolkit.postPriorityEvent(fl);
}
}
@@ -108,7 +108,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause,
+ FocusEvent.Cause cause,
Component currentFocusOwner) // provided by the descendant peers
{
if (lightweightChild == null) {
@@ -120,7 +120,7 @@
currentOwner = null;
}
if (currentOwner != null) {
- FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
+ FocusEvent fl = new FocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
false, lightweightChild, cause);
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
@@ -129,7 +129,7 @@
SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
}
- FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
+ FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
false, currentOwner, cause);
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
@@ -140,7 +140,7 @@
}
// WARNING: Don't call it on the Toolkit thread.
- public static boolean requestFocusFor(Component target, CausedFocusEvent.Cause cause) {
+ public static boolean requestFocusFor(Component target, FocusEvent.Cause cause) {
return AWTAccessor.getComponentAccessor().requestFocus(target, cause);
}
@@ -150,7 +150,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
return kfmAccessor.shouldNativelyFocusHeavyweight(
heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause);
--- old/src/java.desktop/share/classes/sun/awt/NullComponentPeer.java 2015-10-27 12:48:48.466929200 +0300
+++ new/src/java.desktop/share/classes/sun/awt/NullComponentPeer.java 2015-10-27 12:48:48.065889100 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -37,7 +37,7 @@
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Insets;
-import java.awt.MenuBar;
+import java.awt.event.FocusEvent.Cause;
import java.awt.Point;
import java.awt.Event;
import java.awt.event.PaintEvent;
@@ -178,7 +178,7 @@
public boolean requestFocus
(Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) {
+ boolean focusedWindowChangeAllowed, long time, Cause cause) {
return false;
}
--- old/src/java.desktop/share/classes/sun/awt/RequestFocusController.java 2015-10-27 12:48:50.689151400 +0300
+++ new/src/java.desktop/share/classes/sun/awt/RequestFocusController.java 2015-10-27 12:48:50.275110000 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -25,10 +25,11 @@
package sun.awt;
import java.awt.Component;
+import java.awt.event.FocusEvent.Cause;
public interface RequestFocusController
{
public boolean acceptRequestFocus(Component from, Component to,
boolean temporary, boolean focusedWindowChangeAllowed,
- CausedFocusEvent.Cause cause);
+ Cause cause);
}
--- old/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java 2015-10-27 12:48:52.829365400 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java 2015-10-27 12:48:52.422324700 +0300
@@ -285,7 +285,7 @@
@SuppressWarnings("deprecation")
public final boolean requestFocus(Component lightweightChild, boolean temporary,
boolean focusedWindowChangeAllowed, long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if (XKeyboardFocusManagerPeer.
processSynchronousLightweightTransfer(target, lightweightChild, temporary,
@@ -525,7 +525,7 @@
// WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS);
// parentWindow.dispatchEvent(wfg);
// }
- XKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
+ XKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
}
break;
}
--- old/src/java.desktop/unix/classes/sun/awt/X11/XEmbedCanvasPeer.java 2015-10-27 12:48:55.072589700 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XEmbedCanvasPeer.java 2015-10-27 12:48:54.669549400 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, 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
@@ -430,13 +430,10 @@
if (isXEmbedActive()) {
xembedLog.fine("Forwarding FOCUS_GAINED");
int flavor = XEMBED_FOCUS_CURRENT;
- if (e instanceof CausedFocusEvent) {
- CausedFocusEvent ce = (CausedFocusEvent)e;
- if (ce.getCause() == CausedFocusEvent.Cause.TRAVERSAL_FORWARD) {
- flavor = XEMBED_FOCUS_FIRST;
- } else if (ce.getCause() == CausedFocusEvent.Cause.TRAVERSAL_BACKWARD) {
- flavor = XEMBED_FOCUS_LAST;
- }
+ if (e.getCause() == FocusEvent.Cause.TRAVERSAL_FORWARD) {
+ flavor = XEMBED_FOCUS_FIRST;
+ } else if (e.getCause() == FocusEvent.Cause.TRAVERSAL_BACKWARD) {
+ flavor = XEMBED_FOCUS_LAST;
}
xembed.sendMessage(xembed.handle, XEMBED_FOCUS_IN, flavor, 0, 0);
}
--- old/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java 2015-10-27 12:48:57.274809900 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java 2015-10-27 12:48:56.866769100 +0300
@@ -195,7 +195,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
int result = XKeyboardFocusManagerPeer
.shouldNativelyFocusHeavyweight(proxy, lightweightChild,
--- old/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java 2015-10-27 12:48:59.493031700 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java 2015-10-27 12:48:59.063988800 +0300
@@ -1,5 +1,5 @@
/*
- * 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
@@ -28,7 +28,7 @@
import java.awt.Window;
import sun.awt.AWTAccessor;
-import sun.awt.CausedFocusEvent;
+import java.awt.event.FocusEvent;
import sun.awt.KeyboardFocusManagerPeerImpl;
import sun.util.logging.PlatformLogger;
@@ -101,7 +101,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
target,
--- old/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java 2015-10-27 12:49:01.706253000 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java 2015-10-27 12:49:01.296212000 +0300
@@ -59,7 +59,6 @@
import javax.swing.plaf.BorderUIResource;
import java.awt.im.InputMethodRequests;
-import sun.awt.CausedFocusEvent;
import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
@@ -945,14 +944,16 @@
void forwardFocusGained( FocusEvent e) {
isFocused = true;
- FocusEvent fe = CausedFocusEvent.retarget(e, this);
+ FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
+ e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
void forwardFocusLost( FocusEvent e) {
isFocused = false;
- FocusEvent fe = CausedFocusEvent.retarget(e, this);
+ FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
+ e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
--- old/src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java 2015-10-27 12:49:03.964478800 +0300
+++ new/src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java 2015-10-27 12:49:03.552437600 +0300
@@ -54,7 +54,6 @@
import sun.util.logging.PlatformLogger;
-import sun.awt.CausedFocusEvent;
import sun.awt.AWTAccessor;
final class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
@@ -618,13 +617,15 @@
void forwardFocusGained( FocusEvent e) {
isFocused = true;
- FocusEvent fe = CausedFocusEvent.retarget(e, this);
+ FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
+ e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
void forwardFocusLost( FocusEvent e) {
isFocused = false;
- FocusEvent fe = CausedFocusEvent.retarget(e, this);
+ FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(),
+ e.getOppositeComponent(), e.getCause());
super.processFocusEvent(fe);
}
--- old/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java 2015-10-27 12:49:06.176700000 +0300
+++ new/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java 2015-10-27 12:49:05.757658100 +0300
@@ -28,7 +28,6 @@
import java.awt.peer.*;
import java.awt.image.VolatileImage;
import sun.awt.RepaintArea;
-import sun.awt.CausedFocusEvent;
import sun.awt.image.SunVolatileImage;
import sun.awt.image.ToolkitImage;
import java.awt.image.BufferedImage;
@@ -321,7 +320,7 @@
WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
{
WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
- CausedFocusEvent.Cause.MOUSE_EVENT);
+ FocusEvent.Cause.MOUSE_EVENT);
}
break;
}
@@ -687,7 +686,7 @@
@Override
public boolean requestFocus(Component lightweightChild, boolean temporary,
boolean focusedWindowChangeAllowed, long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if (WKeyboardFocusManagerPeer.
processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
--- old/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java 2015-10-27 12:49:08.393921700 +0300
+++ new/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java 2015-10-27 12:49:07.962878600 +0300
@@ -25,6 +25,7 @@
package sun.awt.windows;
import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
import java.awt.dnd.DropTarget;
import java.awt.peer.*;
import java.io.File;
@@ -34,7 +35,6 @@
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.util.Vector;
-import sun.awt.CausedFocusEvent;
import sun.awt.AWTAccessor;
import sun.misc.ManagedLocalsThread;
@@ -283,7 +283,7 @@
@Override
public boolean requestFocus
(Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
+ boolean focusedWindowChangeAllowed, long time, Cause cause)
{
return false;
}
--- old/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java 2015-10-27 12:49:10.574139700 +0300
+++ new/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java 2015-10-27 12:49:10.169099200 +0300
@@ -32,7 +32,7 @@
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.ComponentAccessor;
import sun.awt.KeyboardFocusManagerPeerImpl;
-import sun.awt.CausedFocusEvent;
+import java.awt.event.FocusEvent.Cause;
final class WKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
static native void setNativeFocusOwner(ComponentPeer peer);
@@ -75,7 +75,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ Cause cause)
{
// TODO: do something to eliminate this forwarding
return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
--- old/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java 2015-10-27 12:49:12.863368600 +0300
+++ new/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java 2015-10-27 12:49:12.419324200 +0300
@@ -26,11 +26,11 @@
package sun.awt.windows;
import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
import java.awt.peer.DialogPeer;
import java.awt.peer.ComponentPeer;
import java.awt.dnd.DropTarget;
import java.util.Vector;
-import sun.awt.CausedFocusEvent;
import sun.awt.AWTAccessor;
import sun.misc.ManagedLocalsThread;
@@ -154,7 +154,7 @@
@Override
public boolean requestFocus
(Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
+ boolean focusedWindowChangeAllowed, long time, Cause cause)
{
return false;
--- old/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java 2015-10-27 12:49:15.252607500 +0300
+++ new/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java 2015-10-27 12:49:14.825564800 +0300
@@ -294,11 +294,11 @@
synchronized native void reshapeFrame(int x, int y, int width, int height);
- public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+ public boolean requestWindowFocus(FocusEvent.Cause cause) {
if (!focusAllowedFor()) {
return false;
}
- return requestWindowFocus(cause == CausedFocusEvent.Cause.MOUSE_EVENT);
+ return requestWindowFocus(cause == FocusEvent.Cause.MOUSE_EVENT);
}
private native boolean requestWindowFocus(boolean isMouseEventCause);
--- /dev/null 2015-10-27 12:49:17.000000000 +0300
+++ new/test/java/awt/Focus/Cause/FocusCauseTest.java 2015-10-27 12:49:17.010783300 +0300
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 8080395
+ @summary
+ @author Semyon Sadetsky
+ @run main AutoRequestFocusSetVisibleTest
+*/
+
+
+import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.lang.IllegalArgumentException;
+import java.lang.Override;
+import java.lang.RuntimeException;
+import java.util.Arrays;
+
+public class FocusCauseTest {
+
+ private static Cause[] causes1 = {Cause.ACTIVATION,
+ Cause.UNKNOWN, Cause.UNKNOWN, Cause.TRAVERSAL_FORWARD,
+ Cause.TRAVERSAL_FORWARD, Cause.TRAVERSAL_BACKWARD,
+ Cause.TRAVERSAL_BACKWARD, Cause.TRAVERSAL_UP,
+ Cause.TRAVERSAL_DOWN, Cause.CLEAR_GLOBAL_FOCUS_OWNER};
+ private static Cause[] causes2 = new Cause[10];
+ private static int cnt;
+
+ public static void main(String[] args) throws Exception {
+ testCauses();
+ testNullCause();
+ System.out.println("ok");
+ }
+
+ private static void testNullCause() {
+ try {
+ new FocusEvent(new Frame(), FocusEvent.FOCUS_GAINED, true,
+ null, null);
+ throw new RuntimeException("Exception is not thrown when the " +
+ "cause is null");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ private static void testCauses() throws Exception {
+ Frame frame = new Frame();
+ TextField comp1 = new TextField();
+ comp1.addFocusListener(new FocusListener() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ System.out.println(e.getCause());
+ causes2[cnt++] = e.getCause();
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ System.out.println(e.getCause());
+ causes2[cnt++] = e.getCause();
+ }
+ });
+ TextField comp2 = new TextField();
+ comp2.addFocusListener(new FocusListener() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ System.out.println(e.getCause());
+ causes2[cnt++] = e.getCause();
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ System.out.println(e.getCause());
+ causes2[cnt++] = e.getCause();
+ }
+ });
+ frame.add(comp1, BorderLayout.NORTH);
+ frame.add(comp2, BorderLayout.SOUTH);
+ frame.setVisible(true);
+
+ Robot robot = new Robot();
+ robot.delay(200);
+ robot.waitForIdle();
+ comp2.requestFocus();
+ robot.waitForIdle();
+ comp2.transferFocus();
+ robot.waitForIdle();
+ comp1.transferFocusBackward();
+ robot.waitForIdle();
+ comp2.transferFocusUpCycle();
+ robot.waitForIdle();
+ frame.transferFocusDownCycle();
+ robot.waitForIdle();
+ frame.dispose();
+ robot.waitForIdle();
+ if (!Arrays.equals(causes1, causes2)) {
+ throw new RuntimeException("wrong cause " + causes2);
+ }
+ }
+}