8378918: Remove AppContext from some DnD classes

Reviewed-by: serb, dnguyen
This commit is contained in:
Phil Race 2026-03-22 19:53:43 +00:00
parent aba5d31ae7
commit fae345c6cf
3 changed files with 11 additions and 23 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2026, 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,14 +29,12 @@ import java.awt.event.*;
import java.awt.dnd.DragSource;
import javax.swing.*;
import sun.awt.dnd.SunDragSourceContextPeer;
import sun.awt.AppContext;
/**
* Drag gesture recognition support for classes that have a
* <code>TransferHandler</code>. The gesture for a drag in this class is a mouse
* press followed by movement by <code>DragSource.getDragThreshold()</code>
* pixels. An instance of this class is maintained per AppContext, and the
* public static methods call into the appropriate instance.
* pixels.
*
* @author Shannon Hickey
*/
@ -53,19 +51,14 @@ class DragRecognitionSupport {
public void dragStarting(MouseEvent me);
}
private static DragRecognitionSupport support;
/**
* Returns the DragRecognitionSupport for the caller's AppContext.
* Returns the DragRecognitionSupport instance.
*/
private static DragRecognitionSupport getDragRecognitionSupport() {
DragRecognitionSupport support =
(DragRecognitionSupport)AppContext.getAppContext().
get(DragRecognitionSupport.class);
private static synchronized DragRecognitionSupport getDragRecognitionSupport() {
if (support == null) {
support = new DragRecognitionSupport();
AppContext.getAppContext().put(DragRecognitionSupport.class, support);
}
return support;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2026, 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
@ -264,8 +264,7 @@ public abstract class SunDragSourceContextPeer implements DragSourceContextPeer
modifiers, x, y);
EventDispatcher dispatcher = new EventDispatcher(dispatchType, event);
SunToolkit.invokeLaterOnAppContext(
SunToolkit.targetToAppContext(getComponent()), dispatcher);
SunToolkit.invokeLater(dispatcher);
startSecondaryEventLoop();
}
@ -310,8 +309,7 @@ public abstract class SunDragSourceContextPeer implements DragSourceContextPeer
EventDispatcher dispatcher =
new EventDispatcher(DISPATCH_EXIT, event);
SunToolkit.invokeLaterOnAppContext(
SunToolkit.targetToAppContext(getComponent()), dispatcher);
SunToolkit.invokeLater(dispatcher);
startSecondaryEventLoop();
}
@ -341,8 +339,7 @@ public abstract class SunDragSourceContextPeer implements DragSourceContextPeer
EventDispatcher dispatcher =
new EventDispatcher(DISPATCH_FINISH, event);
SunToolkit.invokeLaterOnAppContext(
SunToolkit.targetToAppContext(getComponent()), dispatcher);
SunToolkit.invokeLater(dispatcher);
startSecondaryEventLoop();
setNativeContext(0);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2026, 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.util.logging.PlatformLogger;
import java.io.IOException;
import java.io.InputStream;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
@ -558,7 +557,6 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
final long nativeCtxt,
final int eventID,
final boolean dispatchType) {
AppContext appContext = SunToolkit.targetToAppContext(component);
EventDispatcher dispatcher =
new EventDispatcher(this, dropAction, actions, formats, nativeCtxt,
@ -572,7 +570,7 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
}
// schedule callback
SunToolkit.postEvent(appContext, event);
SunToolkit.postEvent(event);
eventPosted(event);