diff options
Diffstat (limited to 'gnu/java/awt/peer/gtk/ComponentGraphics.java')
-rw-r--r-- | gnu/java/awt/peer/gtk/ComponentGraphics.java | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/gnu/java/awt/peer/gtk/ComponentGraphics.java b/gnu/java/awt/peer/gtk/ComponentGraphics.java index cb8350265..d9d173118 100644 --- a/gnu/java/awt/peer/gtk/ComponentGraphics.java +++ b/gnu/java/awt/peer/gtk/ComponentGraphics.java @@ -53,6 +53,7 @@ import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; import java.awt.image.RenderedImage; +import gnu.classpath.Pointer; /** * ComponentGraphics - context for drawing directly to a component, @@ -62,38 +63,14 @@ import java.awt.image.RenderedImage; */ public class ComponentGraphics extends CairoGraphics2D { + private static final boolean hasXRenderExtension = hasXRender(); + private GtkComponentPeer component; protected long cairo_t; private static ThreadLocal hasLock = new ThreadLocal(); private static Integer ONE = Integer.valueOf(1); - private void lock() - { - Integer i = (Integer) hasLock.get(); - if (i == null) - { - start_gdk_drawing(); - hasLock.set(ONE); - } - else - hasLock.set(Integer.valueOf(i.intValue() + 1)); - } - - private void unlock() - { - Integer i = (Integer) hasLock.get(); - if (i == null) - throw new IllegalStateException(); - if (i == ONE) - { - hasLock.set(null); - end_gdk_drawing(); - } - else - hasLock.set(Integer.valueOf(i.intValue() - 1)); - } - ComponentGraphics() { } @@ -125,6 +102,32 @@ public class ComponentGraphics extends CairoGraphics2D */ private native long initState(GtkComponentPeer component); + private void lock() + { + Integer i = (Integer) hasLock.get(); + if (i == null) + { + start_gdk_drawing(); + hasLock.set(ONE); + } + else + hasLock.set(Integer.valueOf(i.intValue() + 1)); + } + + private void unlock() + { + Integer i = (Integer) hasLock.get(); + if (i == null) + throw new IllegalStateException(); + if (i == ONE) + { + hasLock.set(null); + end_gdk_drawing(); + } + else + hasLock.set(Integer.valueOf(i.intValue() - 1)); + } + /** * Destroys the component surface and calls dispose on the cairo * graphics2d to destroy any super class resources. @@ -160,6 +163,11 @@ public class ComponentGraphics extends CairoGraphics2D */ public static native boolean hasXRender(); + /** + * This is a utility method (used by GtkComponentPeer) for grabbing the + * image of a component. + */ + private static native Pointer nativeGrab(GtkComponentPeer component); private native void copyAreaNative(GtkComponentPeer component, int x, int y, int width, int height, int dx, int dy); @@ -170,12 +178,20 @@ public class ComponentGraphics extends CairoGraphics2D int cw, int ch); /** + * Not really related (moveme?). Utility method used by GtkComponent. + */ + public static GtkImage grab( GtkComponentPeer component ) + { + return new GtkImage( nativeGrab( component ) ); + } + + /** * Returns a Graphics2D object for a component, either an instance of this * class (if xrender is supported), or a context which copies. */ public static Graphics2D getComponentGraphics(GtkComponentPeer component) { - if( hasXRender() ) + if( hasXRenderExtension ) return new ComponentGraphics(component); Rectangle r = component.awtComponent.getBounds(); @@ -402,5 +418,18 @@ public class ComponentGraphics extends CairoGraphics2D } } + public void setClip(Shape s) + { + lock(); + try + { + super.setClip(s); + } + finally + { + unlock(); + } + } + } |