diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nwi/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/nwi/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nwi/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java new file mode 100644 index 000000000..87feb5f50 --- /dev/null +++ b/src/nwi/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nwi.impl.x11.awt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nwi.*; + +import com.sun.nwi.impl.*; +import com.sun.nwi.impl.jawt.*; +import com.sun.nwi.impl.jawt.x11.*; +import com.sun.nwi.impl.x11.*; + +public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl { + + // When running the AWT on X11 platforms, we use the AWT native + // interface (JAWT) to lock and unlock the toolkit + private ToolkitLock toolkitLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + JAWTUtil.lockToolkit(); + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + JAWTUtil.unlockToolkit(); + } + }; + + public ToolkitLock getToolkitLock() { + return toolkitLock; + } +} |