SunToolkit.java revision 6356
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This code is free software; you can redistribute it and/or modify it
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * under the terms of the GNU General Public License version 2 only, as
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * published by the Free Software Foundation. Oracle designates this
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * particular file as subject to the "Classpath" exception as provided
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * by Oracle in the LICENSE file that accompanied this code.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This code is distributed in the hope that it will be useful, but WITHOUT
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * version 2 for more details (a copy is included in the LICENSE file that
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * accompanied this code).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You should have received a copy of the GNU General Public License version
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * 2 along with this work; if not, write to the Free Software Foundation,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * or visit www.oracle.com if you need additional information or have any
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * questions.
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbingsimport java.awt.dnd.peer.DragSourceContextPeer;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport java.util.concurrent.locks.ReentrantLock;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport java.lang.reflect.InvocationTargetException;
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbingspublic abstract class SunToolkit extends Toolkit
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster implements WindowClosingSupport, WindowClosingListener,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.SunToolkit");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* Load debug settings for native code */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.nativedebug"))) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Special mask for the UngrabEvent events, in addition to the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * public masks defined in AWTEvent. Should be used as the mask
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * value for Toolkit.addAWTEventListener.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public static final int GRAB_EVENT_MASK = 0x80000000;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* The key to put()/get() the PostEventQueue into/from the AppContext.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Number of buttons.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * By default it's taken from the system. If system value does not
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* XFree standard mention 24 buttons as maximum:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * We workaround systems supporting more than 24 buttons.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Otherwise, we have to use long type values as masks
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * which leads to API change.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * InputEvent.BUTTON_DOWN_MASK may contain only 21 masks due to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the 4-bytes limit for the int type. (CR 6799099)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * One more bit is reserved for FIRST_HIGH_BIT.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public final static int MAX_BUTTONS_SUPPORTED = 20;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Creates and initializes EventQueue instance for the specified
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * AppContext.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Note that event queue must be created from createNewAppContext()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * only in order to ensure that EventQueue constructor obtains
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the correct AppContext.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param appContext AppContext to associate with the event queue
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private static void initEQ(AppContext appContext) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster String eqName = System.getProperty("AWT.EventQueueClass",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster "java.awt.EventQueue");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster eventQueue = (EventQueue)Class.forName(eqName).newInstance();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster System.err.println("Failed loading " + eqName + ": " + e);
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue);
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey PostEventQueue postEventQueue = new PostEventQueue(eventQueue);
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue);
public SunToolkit() {
public boolean useBufferPerWindow() {
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws HeadlessException;
throws InvalidDnDOperationException;
public abstract boolean isTraySupported();
throws AWTException;
public abstract KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
throws HeadlessException;
public static final void awtLock() {
public static final boolean awtTryLock() {
public static final void awtUnlock() {
public static final void awtLockWait()
throws InterruptedException
throws InterruptedException
public static final void awtLockNotify() {
public static final void awtLockNotifyAll() {
public static final boolean isAWTLockHeldByCurrentThread() {
return appContext;
return null;
// Maps from non-Component/MenuComponent to AppContext.
return null;
return null;
// target is not a Component/MenuComponent, try the
return context;
catch (ClassNotFoundException e) {
catch (InstantiationException e) {
catch (IllegalAccessException e) {
return policy;
// Target is not a Component/MenuComponent, use the private Map
* on the toolkit (AWT-Windows/AWT-Motif) thread. This function should
throw new NullPointerException();
public void run() {
private static boolean isFlushingPendingEvents = false;
public static void flushPendingEvents() {
if (!isFlushingPendingEvents) {
isFlushingPendingEvents = true;
isFlushingPendingEvents = false;
public static boolean isPostEventQueueEmpty() {
final long when) {
public long getWhen(){
return when;
public static void invokeLaterOnAppContext(
class AWTInvocationLock {}
synchronized (lock) {
protected abstract int getScreenWidth();
protected abstract int getScreenHeight();
return hardwiredFontList;
public static boolean getSunAwtNoerasebackground() {
public static boolean getSunAwtErasebackgroundonresize() {
// fallback to checkRead/checkConnect for pre 1.2
} else if ((perm instanceof
throw se;
synchronized (imgCache) {
} catch (Exception e) {
return img;
synchronized (imgCache) {
} catch (Exception e) {
return img;
// fallback to checkRead/checkConnect for pre 1.2
} else if ((perm instanceof
throw se;
int repbits;
if (o != null) {
public static BufferedImage getScaledIconImage(java.util.List<Image> imageList, int width, int height) {
return null;
int iw;
int ih;
} catch (Exception e){
return null;
g.dispose();
return bimage;
public static DataBufferInt getScaledIconData(java.util.List<Image> imageList, int width, int height) {
return null;
return getSystemEventQueueImplPP();
return theEventQueue;
public int getFocusAcceleratorKeyMask() {
public boolean canPopupOverlapTaskBar() {
boolean result = true;
result = false;
return result;
public boolean enableInputMethodsForTextComponent() {
return startupLocale;
return getStartupLocale();
return dataTransfererClassName;
return windowClosingListener;
return null;
return null;
return mPeer;
public static boolean needsXEmbed() {
protected boolean needsXEmbedImpl() {
protected final boolean isXEmbedServerRequested() {
public static boolean isModalExcludedSupported()
protected boolean isModalExcludedSupportedImpl()
super(msg);
public OperationTimedOut() {
super(msg);
public IllegalThreadException() {
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");
sync();
// generate new events. Example: MapNotify/XSetInputFocus.
iters++;
iters++;
throw new InfiniteLoop();
iters++;
iters++;
throw new InfiniteLoop();
bigLoop++;
private boolean eventDispatched = false;
private boolean queueEmpty = false;
private boolean isEQEmpty() {
queueEmpty = false;
eventDispatched = false;
synchronized(waitLock) {
public void dispatch() {
iters++;
iters++;
synchronized(waitLock) {
eventDispatched = true;
while (!eventDispatched) {
synchronized (waitLock) {
public static native void closeSplashScreen();
private void fireDesktopFontPropertyChanges() {
private static boolean checkedSystemAAFontSettings;
private static boolean useSystemAAFontSettings;
private static boolean lastExtraCondition = true;
if (checkedSystemAAFontSettings) {
checkedSystemAAFontSettings = false;
return map;
return null;
private static boolean useSystemAAFontSettings() {
if (!checkedSystemAAFontSettings) {
if (!useSystemAAFontSettings) {
if (useSystemAAFontSettings) {
checkedSystemAAFontSettings = true;
return useSystemAAFontSettings;
return null;
if (useSystemAAFontSettings()) {
return null;
return null;
public abstract boolean isDesktopSupported();
keyEvent);
public synchronized static boolean getSunAwtDisableMixing() {
public boolean isNativeGTKAvailable() {
public boolean isWindowOpacitySupported() {
public boolean isWindowShapingSupported() {
public boolean isWindowTranslucencySupported() {
public boolean needUpdateWindow() {
public int getNumberOfButtons(){
* Checks that the given object implements/extends the given
* @return true, if this object implements/extends the given
* Java EventQueue. The toolkit Thread (AWT-Windows/AWT-Motif) posts
class PostEventQueue {
private volatile boolean isFlushing = false;
public synchronized boolean noEvents() {
public void flush() {
isFlushing = false;