use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class DefaultKeyboardFocusManager method sendMessage.
/**
* Sends a synthetic AWTEvent to a Component. If the Component is in
* the current AppContext, then the event is immediately dispatched.
* If the Component is in a different AppContext, then the event is
* posted to the other AppContext's EventQueue, and this method blocks
* until the event is handled or target AppContext is disposed.
* Returns true if successfuly dispatched event, false if failed
* to dispatch.
*/
static boolean sendMessage(Component target, AWTEvent e) {
e.isPosted = true;
AppContext myAppContext = AppContext.getAppContext();
final AppContext targetAppContext = target.appContext;
final SentEvent se = new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);
if (myAppContext == targetAppContext) {
se.dispatch();
} else {
if (targetAppContext.isDisposed()) {
return false;
}
SunToolkit.postEvent(targetAppContext, se);
if (EventQueue.isDispatchThread()) {
EventDispatchThread edt = (EventDispatchThread) Thread.currentThread();
edt.pumpEvents(SentEvent.ID, new Conditional() {
public boolean evaluate() {
return !se.dispatched && !targetAppContext.isDisposed();
}
});
} else {
synchronized (se) {
while (!se.dispatched && !targetAppContext.isDisposed()) {
try {
se.wait(1000);
} catch (InterruptedException ie) {
break;
}
}
}
}
}
return se.dispatched;
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class ImageIO method getCacheInfo.
/**
* Returns the <code>CacheInfo</code> object associated with this
* <code>ThreadGroup</code>.
*/
private static synchronized CacheInfo getCacheInfo() {
AppContext context = AppContext.getAppContext();
CacheInfo info = (CacheInfo) context.get(CacheInfo.class);
if (info == null) {
info = new CacheInfo();
context.put(CacheInfo.class, info);
}
return info;
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class AppletSecurity method checkAwtEventQueueAccess.
/**
* Tests if a client can get access to the AWT event queue.
* <p>
* This method calls <code>checkPermission</code> with the
* <code>AWTPermission("accessEventQueue")</code> permission.
*
* @since JDK1.1
* @exception SecurityException if the caller does not have
* permission to access the AWT event queue.
*/
public void checkAwtEventQueueAccess() {
AppContext appContext = AppContext.getAppContext();
AppletClassLoader appletClassLoader = currentAppletClassLoader();
if (AppContext.isMainContext(appContext) && (appletClassLoader != null)) {
// If we're about to allow access to the main EventQueue,
// and anything untrusted is on the class context stack,
// disallow access.
super.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
}
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class AppletPanel method appletResize.
/**
* Is called when the applet wants to be resized.
*/
@Override
public void appletResize(int width, int height) {
currentAppletSize.width = width;
currentAppletSize.height = height;
final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height);
if (loader != null) {
AppContext appCtxt = loader.getAppContext();
if (appCtxt != null)
appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY);
}
final AppletPanel ap = this;
if (appEvtQ != null) {
appEvtQ.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), new Runnable() {
@Override
public void run() {
if (ap != null) {
ap.dispatchAppletEvent(APPLET_RESIZE, currentSize);
}
}
}));
}
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class AppletPanel method changeFrameAppContext.
public static void changeFrameAppContext(Frame frame, AppContext newAppContext) {
// Fixed #4754451: Applet can have methods running on main
// thread event queue.
//
// The cause of this bug is that the frame of the applet
// is created in main thread group. Thus, when certain
// AWT/Swing events are generated, the events will be
// dispatched through the wrong event dispatch thread.
//
// To fix this, we rearrange the AppContext with the frame,
// so the proper event queue will be looked up.
//
// Swing also maintains a Frame list for the AppContext,
// so we will have to rearrange it as well.
// Check if frame's AppContext has already been set properly
AppContext oldAppContext = SunToolkit.targetToAppContext(frame);
if (oldAppContext == newAppContext)
return;
// critical section of the window list in AppContext.
synchronized (Window.class) {
WeakReference weakRef = null;
// Remove frame from the Window list in wrong AppContext
{
// Lookup current frame's AppContext
Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) oldAppContext.get(Window.class);
if (windowList != null) {
for (WeakReference ref : windowList) {
if (ref.get() == frame) {
weakRef = ref;
break;
}
}
// Remove frame from wrong AppContext
if (weakRef != null)
windowList.remove(weakRef);
}
}
// Put the frame into the applet's AppContext map
SunToolkit.insertTargetMapping(frame, newAppContext);
// Insert frame into the Window list in the applet's AppContext map
{
Vector<WeakReference<Window>> windowList = (Vector) newAppContext.get(Window.class);
if (windowList == null) {
windowList = new Vector<WeakReference<Window>>();
newAppContext.put(Window.class, windowList);
}
// use the same weakRef here as it is used elsewhere
windowList.add(weakRef);
}
}
}
Aggregations