FSF GCC merge 02/23/03
[official-gcc.git] / libjava / gnu / gcj / xlib / GC.java
blob1806c2ae5694834443282d6067a7f8b2a59dfb82
1 /* Copyright (C) 2000, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.gcj.xlib;
11 import gnu.gcj.RawData;
12 import java.awt.Rectangle;
14 /**
15 * An X11 graphics context. Unlike a traditional X11 graphics
16 * context, the target drawable is part of the GC state.
18 * Implementation notes: There is no need to do coalescing of changes
19 * since Xlib will do this for us. The implementation relies on the
20 * Xlib GC cache and will not try to be clever.
22 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
24 public class GC implements Cloneable
27 public GC(Drawable target)
29 this.target = target;
30 initStructure(null);
33 public Object clone()
35 GC gcClone = (GC) super.clone();
36 gcClone.structure = null;
37 gcClone.initStructure(this);
38 gcClone.updateClip();
39 return gcClone;
42 private native void initStructure(GC copyFrom);
44 public GC create()
46 return (GC) clone();
49 public void finalize()
51 disposeImpl();
54 public void dispose()
56 disposeImpl();
59 public synchronized native void disposeImpl();
61 public native void setForeground(long pixel);
62 public native void setFont(gnu.gcj.xlib.Font font);
64 /**
65 * Set the clip region for the graphics operations performed by the
66 * GC.
68 * This is one of the few costly operations of this class. It is
69 * suggested that the clip is only set or changed if really
70 * necessary. Higher level APIs can make such optimizations
71 * transparent.
73 * @param rectangles the union of these rectangles describe the clip
74 * region.
76 public void setClipRectangles(Rectangle[] rectangles)
78 clip = new Clip(rectangles);
79 updateClip();
82 public native void drawString(String text, int x, int y);
83 public native void drawLine(int x1, int y1, int x2, int y2);
84 public native void drawRectangle(int x, int y, int w, int h);
86 public native void fillRectangle(int x, int y, int w, int h);
87 public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints,
88 int translateX, int translateY);
90 /**
92 * Clear area using the background pixel or pixmap of the drawable.
93 * Note that this operation does not adhere to the current clip.
95 public native void clearArea(int x, int y, int w, int h,
96 boolean exposures);
99 public native void putImage(XImage image,
100 int srcX, int srcY,
101 int destX, int destY,
102 int width, int height);
104 public Drawable getDrawable()
106 return target;
109 private native void updateClip();
111 private Drawable target;
112 private RawData structure;
113 private Clip clip;