8080395: consider making sun.awt.CausedFocusEvent functionality public
Reviewed-by: alexsch, prr
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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);
}
}
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, 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;
}
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWWindowPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/LWWindowPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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
@@ -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) {
@@ -1199,7 +1199,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);
}
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/PlatformWindow.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/PlatformWindow.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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
@@ -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();
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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
@@ -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.security.action.GetBooleanAction;
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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
@@ -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");
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, 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.Window;
import sun.awt.CGraphicsDevice;
import sun.awt.CGraphicsEnvironment;
-import sun.awt.CausedFocusEvent;
+import java.awt.event.FocusEvent;
import sun.awt.LightweightFrame;
import sun.java2d.SurfaceData;
import sun.lwawt.LWLightweightFramePeer;
@@ -134,7 +134,7 @@
}
@Override
- public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
+ public boolean rejectFocusRequest(FocusEvent.Cause cause) {
return false;
}
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, 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
@@ -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");
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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
@@ -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;
--- a/jdk/src/java.desktop/share/classes/java/awt/Component.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/Component.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, 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
@@ -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) {
@@ -7538,7 +7537,7 @@
requestFocusHelper(false, true);
}
- boolean requestFocus(CausedFocusEvent.Cause cause) {
+ boolean requestFocus(FocusEvent.Cause cause) {
return requestFocusHelper(false, true, cause);
}
@@ -7605,7 +7604,7 @@
return requestFocusHelper(temporary, true);
}
- boolean requestFocus(boolean temporary, CausedFocusEvent.Cause cause) {
+ boolean requestFocus(boolean temporary, FocusEvent.Cause cause) {
return requestFocusHelper(temporary, true, cause);
}
/**
@@ -7656,7 +7655,7 @@
return requestFocusHelper(false, false);
}
- boolean requestFocusInWindow(CausedFocusEvent.Cause cause) {
+ boolean requestFocusInWindow(FocusEvent.Cause cause) {
return requestFocusHelper(false, false, cause);
}
@@ -7721,18 +7720,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();
@@ -7820,7 +7819,7 @@
private boolean isRequestFocusAccepted(boolean temporary,
boolean focusedWindowChangeAllowed,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
if (!isFocusable() || !isVisible()) {
if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
@@ -7867,7 +7866,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
@@ -7899,7 +7898,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;
}
@@ -7983,7 +7982,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)) {
@@ -8063,7 +8062,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) {
@@ -8108,7 +8107,7 @@
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setGlobalCurrentFocusCycleRootPriv(fcr);
- rootAncestor.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
+ rootAncestor.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
} else {
Window window = getContainingWindow();
@@ -8118,7 +8117,7 @@
if (toFocus != null) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setGlobalCurrentFocusCycleRootPriv(window);
- toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
+ toFocus.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
}
}
}
--- a/jdk/src/java.desktop/share/classes/java/awt/Container.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/Container.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, 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
@@ -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);
}
}
}
--- a/jdk/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -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);
--- a/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -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);
@@ -2164,9 +2163,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;
@@ -2190,7 +2189,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");
@@ -2202,7 +2201,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");
@@ -2314,7 +2313,7 @@
hwFocusRequest =
new HeavyweightFocusRequest(heavyweight, descendant,
- temporary, CausedFocusEvent.Cause.UNKNOWN);
+ temporary, FocusEvent.Cause.UNKNOWN);
heavyweightRequests.add(hwFocusRequest);
if (currentFocusOwner != null) {
@@ -2379,7 +2378,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) {
@@ -2445,7 +2444,7 @@
if (currentFocusOwner != null) {
FocusEvent currentFocusOwnerEvent =
- new CausedFocusEvent(currentFocusOwner,
+ new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
temporary, descendant, cause);
// Fix 5028014. Rolled out.
@@ -2454,7 +2453,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);
@@ -2670,13 +2669,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,
@@ -2726,8 +2725,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);
}
}
@@ -2802,7 +2801,7 @@
// 'opposite' will be fixed by
// DefaultKeyboardFocusManager.realOppositeComponent
- return new CausedFocusEvent(newSource,
+ return new FocusEvent(newSource,
FocusEvent.FOCUS_GAINED, temporary,
opposite, lwFocusRequest.cause);
}
@@ -2815,8 +2814,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);
@@ -2839,9 +2838,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
@@ -2850,9 +2849,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;
}
@@ -2878,15 +2877,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;
}
--- a/jdk/src/java.desktop/share/classes/java/awt/Window.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/Window.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, 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
@@ -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;
@@ -2599,7 +2598,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;
}
}
--- a/jdk/src/java.desktop/share/classes/java/awt/event/FocusEvent.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/event/FocusEvent.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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
@@ -26,6 +26,9 @@
package java.awt.event;
import java.awt.Component;
+import java.io.ObjectStreamException;
+
+import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
@@ -51,6 +54,10 @@
* the FOCUS_GAINED and FOCUS_LOST event ids; the level may be distinguished in
* the event using the isTemporary() method.
* <p>
+ * 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}.
+ * <p>
* 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 +73,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 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;
@@ -86,6 +148,16 @@
public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
/**
+ * A focus event has the reason why this event was generated.
+ * The cause is set during the focus event creation.
+ *
+ * @serial
+ * @see #getCause()
+ * @since 9
+ */
+ 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
* temporarily and intends on getting it back once the event is completed.
@@ -115,7 +187,8 @@
/**
* Constructs a {@code FocusEvent} object with the
- * specified temporary state and opposite {@code Component}.
+ * specified temporary state, 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
@@ -142,13 +215,57 @@
* @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}.
+ * <p> 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 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;
}
/**
@@ -220,8 +337,8 @@
return (SunToolkit.targetToAppContext(opposite) ==
AppContext.getAppContext())
- ? opposite
- : null;
+ ? opposite
+ : null;
}
/**
@@ -233,17 +350,56 @@
public String paramString() {
String typeStr;
switch(id) {
- case FOCUS_GAINED:
- typeStr = "FOCUS_GAINED";
- break;
- case FOCUS_LOST:
- typeStr = "FOCUS_LOST";
- break;
- default:
- typeStr = "unknown type";
+ case FOCUS_GAINED:
+ typeStr = "FOCUS_GAINED";
+ break;
+ case FOCUS_LOST:
+ typeStr = "FOCUS_LOST";
+ break;
+ default:
+ 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 9
+ */
+ public final Cause getCause() {
+ return cause;
}
-}
+ /**
+ * Checks if this deserialized {@code FocusEvent} instance is compatible
+ * with the current specification which implies that focus event has
+ * non-null {@code cause} value. If the check fails a new {@code FocusEvent}
+ * instance is returned which {@code cause} field equals to
+ * {@link Cause#UNKNOWN} and its other fields have the same values as in
+ * this {@code FocusEvent} instance.
+ *
+ * @serial
+ * @see #cause
+ * @since 9
+ */
+ @SuppressWarnings("serial")
+ Object readResolve() throws ObjectStreamException {
+ if (cause != null) {
+ return this;
+ }
+ FocusEvent focusEvent = new FocusEvent(new Component(){}, getID(),
+ isTemporary(), getOppositeComponent());
+ focusEvent.setSource(null);
+ focusEvent.consumed = consumed;
+
+ AWTAccessor.AWTEventAccessor accessor =
+ AWTAccessor.getAWTEventAccessor();
+ accessor.setBData(focusEvent, accessor.getBData(this));
+ return focusEvent;
+ }
+
+
+}
\ No newline at end of file
--- a/jdk/src/java.desktop/share/classes/java/awt/peer/ComponentPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/peer/ComponentPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, 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
--- a/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -3558,7 +3558,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;
--- a/jdk/src/java.desktop/share/classes/sun/awt/AWTAccessor.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/awt/AWTAccessor.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, 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
@@ -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.
--- a/jdk/src/java.desktop/share/classes/sun/awt/CausedFocusEvent.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/awt/CausedFocusEvent.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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,17 +27,18 @@
import java.awt.event.FocusEvent;
import java.awt.Component;
+import java.io.ObjectStreamException;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
- * 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.
+ * This class exists for deserialization compatibility only.
*/
-@SuppressWarnings("serial")
-public class CausedFocusEvent extends FocusEvent {
- public enum Cause {
+class CausedFocusEvent extends FocusEvent {
+ private static final long serialVersionUID = -3647309088427840738L;
+
+ private enum Cause {
UNKNOWN,
MOUSE_EVENT,
TRAVERSAL,
@@ -51,39 +52,82 @@
NATIVE_SYSTEM,
ACTIVATION,
CLEAR_GLOBAL_FOCUS_OWNER,
- RETARGETED
+ RETARGETED;
};
+ @SuppressWarnings("serial")
+ private static final Component dummy = new Component(){};
+
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,
+ private 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;
+ throw new IllegalStateException();
}
- /**
- * 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;
+ Object readResolve() throws ObjectStreamException {
+ FocusEvent.Cause newCause;
+ switch (cause) {
+ case UNKNOWN:
+ newCause = FocusEvent.Cause.UNKNOWN;
+ break;
+ case MOUSE_EVENT:
+ newCause = FocusEvent.Cause.MOUSE_EVENT;
+ break;
+ case TRAVERSAL:
+ newCause = FocusEvent.Cause.TRAVERSAL;
+ break;
+ case TRAVERSAL_UP:
+ newCause = FocusEvent.Cause.TRAVERSAL_UP;
+ break;
+ case TRAVERSAL_DOWN:
+ newCause = FocusEvent.Cause.TRAVERSAL_DOWN;
+ break;
+ case TRAVERSAL_FORWARD:
+ newCause = FocusEvent.Cause.TRAVERSAL_FORWARD;
+ break;
+ case TRAVERSAL_BACKWARD:
+ newCause = FocusEvent.Cause.TRAVERSAL_BACKWARD;
+ break;
+ case ROLLBACK:
+ newCause = FocusEvent.Cause.ROLLBACK;
+ break;
+ case NATIVE_SYSTEM:
+ newCause = FocusEvent.Cause.UNEXPECTED;
+ break;
+ case ACTIVATION:
+ newCause = FocusEvent.Cause.ACTIVATION;
+ break;
+ case CLEAR_GLOBAL_FOCUS_OWNER:
+ newCause = FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER;
+ break;
+ default:
+ newCause = FocusEvent.Cause.UNKNOWN;
+ }
- return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
- (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
+ FocusEvent focusEvent = new FocusEvent(dummy, getID(), isTemporary(),
+ getOppositeComponent(), newCause);
+ focusEvent.setSource(null);
+ try {
+ final Field consumedField = FocusEvent.class.getField("consumed");
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ consumedField.setAccessible(true);
+ try {
+ consumedField.set(focusEvent, consumed);
+ } catch (IllegalAccessException e) {
+ }
+ return null;
+ }
+ });
+ } catch (NoSuchFieldException e) {
+ }
+
+ AWTAccessor.AWTEventAccessor accessor =
+ AWTAccessor.getAWTEventAccessor();
+ accessor.setBData(focusEvent, accessor.getBData(this));
+ return focusEvent;
}
}
--- a/jdk/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -60,8 +60,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);
}
}
@@ -110,7 +110,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause,
+ FocusEvent.Cause cause,
Component currentFocusOwner) // provided by the descendant peers
{
if (lightweightChild == null) {
@@ -122,7 +122,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)) {
@@ -131,7 +131,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)) {
@@ -142,7 +142,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);
}
@@ -152,7 +152,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
return KfmAccessor.instance.shouldNativelyFocusHeavyweight(
heavyweight, descendant, temporary, focusedWindowChangeAllowed,
--- a/jdk/src/java.desktop/share/classes/sun/awt/NullComponentPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/awt/NullComponentPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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;
}
--- a/jdk/src/java.desktop/share/classes/sun/awt/RequestFocusController.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/awt/RequestFocusController.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2016 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);
}
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, 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
@@ -287,7 +287,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,
@@ -527,7 +527,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;
}
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbedCanvasPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbedCanvasPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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);
}
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -195,7 +195,7 @@
boolean temporary,
boolean focusedWindowChangeAllowed,
long time,
- CausedFocusEvent.Cause cause)
+ FocusEvent.Cause cause)
{
int result = XKeyboardFocusManagerPeer
.shouldNativelyFocusHeavyweight(proxy, lightweightChild,
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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,
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -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);
}
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -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);
}
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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,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,
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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,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;
final class WFileDialogPeer extends WWindowPeer implements FileDialogPeer {
@@ -282,7 +282,7 @@
@Override
public boolean requestFocus
(Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
+ boolean focusedWindowChangeAllowed, long time, Cause cause)
{
return false;
}
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2016, 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
@@ -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,
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPrintDialogPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, 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
@@ -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;
class WPrintDialogPeer extends WWindowPeer implements DialogPeer {
@@ -153,7 +153,7 @@
@Override
public boolean requestFocus
(Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
+ boolean focusedWindowChangeAllowed, long time, Cause cause)
{
return false;
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java Fri Apr 15 12:00:37 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java Fri Apr 15 09:46:31 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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
@@ -300,11 +300,11 @@
return getNativeWindowSize();
}
- 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 Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Focus/Cause/FocusCauseTest.java Fri Apr 15 09:46:31 2016 +0300
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2016, 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 consider making sun.awt.CausedFocusEvent functionality public
+ @run main FocusCauseTest
+*/
+
+
+import java.awt.*;
+import java.awt.event.FocusEvent.Cause;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+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;
+
+ static byte[] data =
+ {-84, -19, 0, 5, 115, 114, 0, 24, 115, 117, 110, 46, 97, 119,
+ 116, 46, 67, 97, 117, 115, 101, 100, 70, 111, 99, 117, 115, 69, 118,
+ 101, 110, 116, -51, 98, 39, -75, 86, 52, 107, 30, 2, 0, 1, 76, 0, 5,
+ 99, 97, 117, 115, 101, 116, 0, 32, 76, 115, 117, 110, 47, 97, 119,
+ 116, 47, 67, 97, 117, 115, 101, 100, 70, 111, 99, 117, 115, 69, 118,
+ 101, 110, 116, 36, 67, 97, 117, 115, 101, 59, 120, 114, 0, 25, 106,
+ 97, 118, 97, 46, 97, 119, 116, 46, 101, 118, 101, 110, 116, 46, 70,
+ 111, 99, 117, 115, 69, 118, 101, 110, 116, 7, 68, -65, 75, 55, -113,
+ 98, -52, 2, 0, 1, 90, 0, 9, 116, 101, 109, 112, 111, 114, 97, 114,
+ 121, 120, 114, 0, 29, 106, 97, 118, 97, 46, 97, 119, 116, 46, 101,
+ 118, 101, 110, 116, 46, 67, 111, 109, 112, 111, 110, 101, 110, 116,
+ 69, 118, 101, 110, 116, 112, 109, -6, -107, 79, -87, -38, 69, 2, 0,
+ 0, 120, 114, 0, 17, 106, 97, 118, 97, 46, 97, 119, 116, 46, 65, 87,
+ 84, 69, 118, 101, 110, 116, -26, -85, 45, -31, 24, -33, -118, -61,
+ 2, 0, 3, 90, 0, 8, 99, 111, 110, 115, 117, 109, 101, 100, 73, 0, 2,
+ 105, 100, 91, 0, 5, 98, 100, 97, 116, 97, 116, 0, 2, 91, 66, 120,
+ 114, 0, 21, 106, 97, 118, 97, 46, 117, 116, 105, 108, 46, 69, 118,
+ 101, 110, 116, 79, 98, 106, 101, 99, 116, 76, -115, 9, 78, 24, 109,
+ 125, -88, 2, 0, 0, 120, 112, 0, 0, 0, 3, -20, 112, 0, 126, 114, 0,
+ 30, 115, 117, 110, 46, 97, 119, 116, 46, 67, 97, 117, 115, 101, 100,
+ 70, 111, 99, 117, 115, 69, 118, 101, 110, 116, 36, 67, 97, 117, 115,
+ 101, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 120, 114, 0, 14, 106, 97,
+ 118, 97, 46, 108, 97, 110, 103, 46, 69, 110, 117, 109, 0, 0, 0, 0,
+ 0, 0, 0, 0, 18, 0, 0, 120, 112, 116, 0};
+
+ static byte[] dataOld =
+ {-84, -19, 0, 5, 115, 114, 0, 25, 106, 97, 118, 97, 46, 97, 119,
+ 116, 46, 101, 118, 101, 110, 116, 46, 70, 111, 99, 117, 115, 69,
+ 118, 101, 110, 116, 7, 68, -65, 75, 55, -113, 98, -52, 2, 0, 1, 90,
+ 0, 9, 116, 101, 109, 112, 111, 114, 97, 114, 121, 120, 114, 0, 29,
+ 106, 97, 118, 97, 46, 97, 119, 116, 46, 101, 118, 101, 110, 116, 46,
+ 67, 111, 109, 112, 111, 110, 101, 110, 116, 69, 118, 101, 110, 116,
+ 112, 109, -6, -107, 79, -87, -38, 69, 2, 0, 0, 120, 114, 0, 17, 106,
+ 97, 118, 97, 46, 97, 119, 116, 46, 65, 87, 84, 69, 118, 101, 110,
+ 116, -26, -85, 45, -31, 24, -33, -118, -61, 2, 0, 3, 90, 0, 8, 99,
+ 111, 110, 115, 117, 109, 101, 100, 73, 0, 2, 105, 100, 91, 0, 5, 98,
+ 100, 97, 116, 97, 116, 0, 2, 91, 66, 120, 114, 0, 21, 106, 97, 118,
+ 97, 46, 117, 116, 105, 108, 46, 69, 118, 101, 110, 116, 79, 98, 106,
+ 101, 99, 116, 76, -115, 9, 78, 24, 109, 125, -88, 2, 0, 0, 120, 112,
+ 0, 0, 0, 0, 100, 112, 0};
+
+ static String[] causesIn = {"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"};
+
+ static FocusEvent.Cause[] causesOut = {FocusEvent.Cause.UNKNOWN,
+ FocusEvent.Cause.MOUSE_EVENT,
+ FocusEvent.Cause.TRAVERSAL, FocusEvent.Cause.TRAVERSAL_UP,
+ FocusEvent.Cause.TRAVERSAL_DOWN, FocusEvent.Cause.TRAVERSAL_FORWARD,
+ FocusEvent.Cause.TRAVERSAL_BACKWARD, FocusEvent.Cause.UNKNOWN,
+ FocusEvent.Cause.UNKNOWN, FocusEvent.Cause.ROLLBACK,
+ FocusEvent.Cause.UNEXPECTED, FocusEvent.Cause.ACTIVATION,
+ FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER, FocusEvent.Cause.UNKNOWN
+ };
+
+ public static void main(String[] args) throws Exception {
+ testCauses();
+ testNullCause();
+ testCausedFocusEventDeserialization();
+ testFocusEventDeserialization();
+ 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 {
+ cnt = 0;
+ 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);
+ }
+ }
+
+ private static void testCausedFocusEventDeserialization() throws
+ Exception {
+ for (int i = 0; i < causesIn.length; i++) {
+ final String causeIn = causesIn[i];
+ ObjectInputStream oi = new ObjectInputStream(new InputStream() {
+ int cnt = 0;
+ @Override
+ public int read() throws IOException {
+ if(cnt < data.length) {
+ return data[cnt++];
+ } else if(cnt == data.length){
+ cnt++;
+ return causeIn.length();
+ } else if(cnt - data.length - 1 < causeIn.length()) {
+ return causeIn.getBytes()[cnt++ - data.length - 1];
+ }
+ return -1;
+ }
+ });
+ FocusEvent ev = (FocusEvent) oi.readObject();
+ System.out.println(ev);
+ if(ev.getCause() != causesOut[i]) {
+ throw new RuntimeException("Wrong cause read :" +ev.getCause());
+ }
+ }
+ }
+
+ private static void testFocusEventDeserialization() throws
+ Exception {
+ ObjectInputStream oi = new ObjectInputStream(
+ new ByteArrayInputStream(dataOld));
+ FocusEvent ev = (FocusEvent)oi.readObject();
+ if(ev.getCause() != FocusEvent.Cause.UNKNOWN) {
+ throw new RuntimeException("Wrong cause in deserialized FocusEvent "
+ + ev.getCause());
+ }
+ }
+
+}