8074763: Remove API references to java.awt.dnd.peer

Reviewed-by: alanb, ant, prr
This commit is contained in:
Sergey Bylokhov 2015-04-17 16:57:30 +03:00
parent b9aead1b2c
commit 677097c128
8 changed files with 170 additions and 88 deletions

View File

@ -1085,7 +1085,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
DropTarget old;
if ((old = dropTarget) != null) {
if (peer != null) dropTarget.removeNotify(peer);
dropTarget.removeNotify();
DropTarget t = dropTarget;
@ -1103,12 +1103,12 @@ public abstract class Component implements ImageObserver, MenuContainer,
if ((dropTarget = dt) != null) {
try {
dropTarget.setComponent(this);
if (peer != null) dropTarget.addNotify(peer);
dropTarget.addNotify();
} catch (IllegalArgumentException iae) {
if (old != null) {
try {
old.setComponent(this);
if (peer != null) dropTarget.addNotify(peer);
dropTarget.addNotify();
} catch (IllegalArgumentException iae1) {
// ignore it!
}
@ -7011,7 +7011,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
popup.addNotify();
}
if (dropTarget != null) dropTarget.addNotify(peer);
if (dropTarget != null) dropTarget.addNotify();
peerFont = getFont();
@ -7098,7 +7098,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
((FlipBufferStrategy)bufferStrategy).destroyBuffers();
}
if (dropTarget != null) dropTarget.removeNotify(peer);
if (dropTarget != null) dropTarget.removeNotify();
// Hide peer first to stop system events such as cursor moves.
if (visible) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -35,13 +35,15 @@ import java.awt.Toolkit;
import java.awt.datatransfer.FlavorMap;
import java.awt.datatransfer.SystemFlavorMap;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.AccessController;
import java.util.EventListener;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.DragSourceContextAccessor;
import sun.awt.dnd.SunDragSourceContextPeer;
import sun.security.action.GetIntegerAction;
@ -303,22 +305,16 @@ public class DragSource implements Serializable {
try {
if (flavorMap != null) this.flavorMap = flavorMap;
DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
DragSourceContext dsc = createDragSourceContext(dscp,
trigger,
dragCursor,
dragImage,
imageOffset,
transferable,
dsl
);
DragSourceContext dsc = createDragSourceContext(trigger, dragCursor,
dragImage,
imageOffset,
transferable, dsl);
if (dsc == null) {
throw new InvalidDnDOperationException();
}
dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
DragSourceContextAccessor acc = AWTAccessor.getDragSourceContextAccessor();
acc.getPeer(dsc).startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
} catch (RuntimeException e) {
SunDragSourceContextPeer.setDragDropInProgress(false);
throw e;
@ -442,7 +438,6 @@ public class DragSource implements Serializable {
* is registered with the created <code>DragSourceContext</code>,
* but <code>NullPointerException</code> is not thrown.
*
* @param dscp The <code>DragSourceContextPeer</code> for this drag
* @param dgl The <code>DragGestureEvent</code> that triggered the
* drag
* @param dragCursor The initial {@code Cursor} for this drag operation
@ -473,8 +468,13 @@ public class DragSource implements Serializable {
* event are equal to <code>DnDConstants.ACTION_NONE</code>.
*/
protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl) {
return new DragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
protected DragSourceContext createDragSourceContext(DragGestureEvent dgl,
Cursor dragCursor,
Image dragImage,
Point imageOffset,
Transferable t,
DragSourceListener dsl) {
return new DragSourceContext(dgl, dragCursor, dragImage, imageOffset, t, dsl);
}
/**

View File

@ -29,21 +29,20 @@ import java.awt.Component;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.TooManyListenersException;
import sun.awt.AWTAccessor;
/**
* The <code>DragSourceContext</code> class is responsible for managing the
* initiator side of the Drag and Drop protocol. In particular, it is responsible
@ -123,6 +122,10 @@ public class DragSourceContext
protected static final int CHANGED = 3;
static {
AWTAccessor.setDragSourceContextAccessor(dsc -> dsc.peer);
}
/**
* Called from <code>DragSource</code>, this constructor creates a new
* <code>DragSourceContext</code> given the
@ -155,7 +158,6 @@ public class DragSourceContext
* If <code>DragSourceListener</code> is <code>null</code> no exception
* is thrown.
*
* @param dscp the <code>DragSourceContextPeer</code> for this drag
* @param trigger the triggering event
* @param dragCursor the initial {@code Cursor} for this drag operation
* or {@code null} for the default cursor handling;
@ -179,10 +181,12 @@ public class DragSourceContext
* @throws NullPointerException if dscp, trigger, or t are null, or
* if dragImage is non-null and offset is null
*/
public DragSourceContext(DragSourceContextPeer dscp,
DragGestureEvent trigger, Cursor dragCursor,
public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor,
Image dragImage, Point offset, Transferable t,
DragSourceListener dsl) {
DragSourceContextPeer dscp = Toolkit.getDefaultToolkit()
.createDragSourceContextPeer(trigger);
if (dscp == null) {
throw new NullPointerException("DragSourceContextPeer");
}
@ -623,8 +627,7 @@ public class DragSourceContext
/*
* fields
*/
private transient DragSourceContextPeer peer;
private final transient DragSourceContextPeer peer;
/**
* The event which triggered the start of the drag.

View File

@ -207,19 +207,13 @@ public class DropTarget implements DropTargetListener, Serializable {
if (component == c || component != null && component.equals(c))
return;
Component old;
ComponentPeer oldPeer = null;
final Component old = component;
if ((old = component) != null) {
if (old != null) {
clearAutoscroll();
component = null;
if (componentPeer != null) {
oldPeer = componentPeer;
removeNotify(componentPeer);
}
removeNotify();
old.setDropTarget(null);
}
@ -229,7 +223,7 @@ public class DropTarget implements DropTargetListener, Serializable {
} catch (Exception e) { // undo the change
if (old != null) {
old.setDropTarget(this);
addNotify(oldPeer);
addNotify();
}
}
}
@ -497,16 +491,16 @@ public class DropTarget implements DropTargetListener, Serializable {
* association of the ComponentPeer with the Component may result in
* a malfunction of the DnD system.
**********************************************************************
*
* @param peer The Peer of the Component we are associated with!
*
*/
public void addNotify(ComponentPeer peer) {
if (peer == componentPeer) return;
public void addNotify() {
final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
ComponentPeer peer = acc.getPeer(component);
if (peer == null || peer == componentPeer) {
return;
}
componentPeer = peer;
final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
for (Component c = component;
c != null && peer instanceof LightweightPeer; c = c.getParent()) {
@ -514,7 +508,7 @@ public class DropTarget implements DropTargetListener, Serializable {
}
if (peer instanceof DropTargetPeer) {
nativePeer = peer;
nativePeer = (DropTargetPeer) peer;
((DropTargetPeer)peer).addDropTarget(this);
} else {
nativePeer = null;
@ -533,15 +527,14 @@ public class DropTarget implements DropTargetListener, Serializable {
* disassociation of the ComponentPeer from the Component may result in
* a malfunction of the DnD system.
**********************************************************************
*
* @param peer The Peer of the Component we are being disassociated from!
*/
public void removeNotify(ComponentPeer peer) {
if (nativePeer != null)
((DropTargetPeer)nativePeer).removeDropTarget(this);
componentPeer = nativePeer = null;
public void removeNotify() {
if (nativePeer != null) {
nativePeer.removeDropTarget(this);
}
componentPeer = null;
nativePeer = null;
synchronized (this) {
if (isDraggingInside) {
@ -837,7 +830,7 @@ public class DropTarget implements DropTargetListener, Serializable {
/*
* That Component's "native" Peer
*/
private transient ComponentPeer nativePeer;
private transient DropTargetPeer nativePeer;
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -39,6 +39,8 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.DropTargetContextAccessor;
/**
* A <code>DropTargetContext</code> is created
@ -58,6 +60,19 @@ public class DropTargetContext implements Serializable {
private static final long serialVersionUID = -634158968993743371L;
static {
AWTAccessor.setDropTargetContextAccessor(new DropTargetContextAccessor() {
@Override
public void reset(DropTargetContext dtc) {
dtc.reset();
}
@Override
public void setDropTargetContextPeer(DropTargetContext dtc,
DropTargetContextPeer dtcp) {
dtc.setDropTargetContextPeer(dtcp);
}
});
}
/**
* Construct a <code>DropTargetContext</code>
* given a specified <code>DropTarget</code>.
@ -89,21 +104,10 @@ public class DropTargetContext implements Serializable {
public Component getComponent() { return dropTarget.getComponent(); }
/**
* Called when associated with the <code>DropTargetContextPeer</code>.
*
* @param dtcp the <code>DropTargetContextPeer</code>
*/
public void addNotify(DropTargetContextPeer dtcp) {
dropTargetContextPeer = dtcp;
}
/**
* Called when disassociated with the <code>DropTargetContextPeer</code>.
*/
public void removeNotify() {
void reset() {
dropTargetContextPeer = null;
transferable = null;
}
@ -282,11 +286,17 @@ public class DropTargetContext implements Serializable {
*
* @return the platform peer
*/
DropTargetContextPeer getDropTargetContextPeer() {
return dropTargetContextPeer;
}
/**
* Sets the {@code DropTargetContextPeer}
*/
void setDropTargetContextPeer(final DropTargetContextPeer dtcp) {
dropTargetContextPeer = dtcp;
}
/**
* Creates a TransferableProxy to proxy for the specified
* Transferable.
@ -412,7 +422,7 @@ public class DropTargetContext implements Serializable {
*
* @serial
*/
private DropTarget dropTarget;
private final DropTarget dropTarget;
private transient DropTargetContextPeer dropTargetContextPeer;

View File

@ -29,6 +29,10 @@ import sun.misc.Unsafe;
import javax.accessibility.AccessibleContext;
import java.awt.*;
import java.awt.dnd.DragSourceContext;
import java.awt.dnd.DropTargetContext;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.dnd.peer.DropTargetContextPeer;
import java.awt.event.InputEvent;
import java.awt.event.InvocationEvent;
import java.awt.event.KeyEvent;
@ -784,6 +788,31 @@ public final class AWTAccessor {
AppContext getAppContext(AccessibleContext accessibleContext);
}
/*
* An accessor object for the DragSourceContext class
*/
public interface DragSourceContextAccessor {
/**
* Returns the peer of the DragSourceContext.
*/
DragSourceContextPeer getPeer(DragSourceContext dsc);
}
/*
* An accessor object for the DropTargetContext class
*/
public interface DropTargetContextAccessor {
/**
* Resets the DropTargetContext.
*/
void reset(DropTargetContext dtc);
/**
* Sets the {@code DropTargetContextPeer}
*/
void setDropTargetContextPeer(DropTargetContext dtc,
DropTargetContextPeer dtcp);
}
/*
* Accessor instances are initialized in the static initializers of
* corresponding AWT classes by using setters defined below.
@ -815,6 +844,8 @@ public final class AWTAccessor {
private static InvocationEventAccessor invocationEventAccessor;
private static SystemColorAccessor systemColorAccessor;
private static AccessibleContextAccessor accessibleContextAccessor;
private static DragSourceContextAccessor dragSourceContextAccessor;
private static DropTargetContextAccessor dropTargetContextAccessor;
/*
* Set an accessor object for the java.awt.Component class.
@ -1275,4 +1306,39 @@ public final class AWTAccessor {
public static void setAccessibleContextAccessor(AccessibleContextAccessor accessor) {
AWTAccessor.accessibleContextAccessor = accessor;
}
/*
* Get the accessor object for the java.awt.dnd.DragSourceContext class.
*/
public static DragSourceContextAccessor getDragSourceContextAccessor() {
if (dragSourceContextAccessor == null) {
unsafe.ensureClassInitialized(DragSourceContext.class);
}
return dragSourceContextAccessor;
}
/*
* Set the accessor object for the java.awt.dnd.DragSourceContext class.
*/
public static void setDragSourceContextAccessor(DragSourceContextAccessor accessor) {
AWTAccessor.dragSourceContextAccessor = accessor;
}
/*
* Get the accessor object for the java.awt.dnd.DropTargetContext class.
*/
public static DropTargetContextAccessor getDropTargetContextAccessor() {
if (dropTargetContextAccessor == null) {
unsafe.ensureClassInitialized(DropTargetContext.class);
}
return dropTargetContextAccessor;
}
/*
* Set the accessor object for the java.awt.dnd.DropTargetContext class.
*/
public static void setDropTargetContextAccessor(DropTargetContextAccessor accessor) {
AWTAccessor.dropTargetContextAccessor = accessor;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2014, 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
@ -48,6 +48,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Arrays;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.DropTargetContextAccessor;
import sun.util.logging.PlatformLogger;
import java.io.IOException;
@ -313,9 +315,10 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
Point hots = event.getPoint();
local = getJVMLocalSourceTransferable();
DropTargetContextAccessor acc =
AWTAccessor.getDropTargetContextAccessor();
if (currentDTC != null) { // some wreckage from last time
currentDTC.removeNotify();
acc.reset(currentDTC);
currentDTC = null;
}
@ -323,7 +326,7 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
currentDT = dt;
currentDTC = currentDT.getDropTargetContext();
currentDTC.addNotify(this);
acc.setDropTargetContextPeer(currentDTC, this);
currentA = dt.getDefaultActions();
@ -370,13 +373,15 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
Component c = (Component)event.getSource();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
DropTargetContextAccessor acc =
AWTAccessor.getDropTargetContextAccessor();
if (dt == null) {
currentDT = null;
currentT = null;
if (currentDTC != null) {
currentDTC.removeNotify();
acc.reset(currentDTC);
}
currentDTC = null;
@ -387,13 +392,13 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
if (dt != currentDT) {
if (currentDTC != null) {
currentDTC.removeNotify();
acc.reset(currentDTC);
}
currentDT = dt;
currentDTC = dt.getDropTargetContext();
currentDTC.addNotify(this);
acc.setDropTargetContextPeer(currentDTC, this);
}
dtc = currentDTC;
@ -409,7 +414,7 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
currentDT = null;
currentT = null;
currentDTC.removeNotify();
acc.reset(currentDTC);
currentDTC = null;
local = null;
@ -440,11 +445,13 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
int id = event.getID();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
DropTargetContextAccessor acc =
AWTAccessor.getDropTargetContextAccessor();
if (c.isShowing() && (dt != null) && dt.isActive()) {
if (currentDT != dt) {
if (currentDTC != null) {
currentDTC.removeNotify();
acc.reset(currentDTC);
}
currentDT = dt;
@ -454,11 +461,11 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
dtc = currentDT.getDropTargetContext();
if (dtc != currentDTC) {
if (currentDTC != null) {
currentDTC.removeNotify();
acc.reset(currentDTC);
}
currentDTC = dtc;
currentDTC.addNotify(this);
acc.setDropTargetContextPeer(currentDTC, this);
}
currentA = currentDT.getDefaultActions();
@ -518,13 +525,15 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
DropTargetContext dtc = dt.getDropTargetContext();
currentDT = dt;
DropTargetContextAccessor acc =
AWTAccessor.getDropTargetContextAccessor();
if (currentDTC != null) {
currentDTC.removeNotify();
acc.reset(currentDTC);
}
currentDTC = dtc;
currentDTC.addNotify(this);
acc.setDropTargetContextPeer(currentDTC, this);
currentA = dt.getDefaultActions();
synchronized(_globalLock) {
@ -687,7 +696,9 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
throw new InvalidDnDOperationException("No Drop pending");
}
if (currentDTC != null) currentDTC.removeNotify();
if (currentDTC != null) {
AWTAccessor.getDropTargetContextAccessor().reset(currentDTC);
}
currentDT = null;
currentDTC = null;

View File

@ -74,7 +74,6 @@ public class DragSourceListenerSerializationTest {
new Point(100, 100),
Arrays.asList(me));
DragSourceContext dsc = new DragSourceContext(
Toolkit.getDefaultToolkit().createDragSourceContextPeer(dge),
dge,
new Cursor(Cursor.HAND_CURSOR),
null, null, new StringSelection("TEXT"), null);