XGraphics.java (XGraphics): Use new GC.create.

2003-04-19  Scott Gilbertson  <scottg@mantatest.com>

	* gnu/awt/xlib/XGraphics.java (XGraphics): Use new GC.create.
	(dispose): Null metrics.
	* gnu/awt/xlib/XToolkit.java (sync): Implement.
	* gnu/gcj/xlib/Clip.java (dispose): Change name of native from
	finalize.
	(finalize): Call dispose.
	* gnu/gcj/xlib/Drawable.java (gcCache): New field.
	(gcCachedCount): New field.
	(finalize): New method.
	(putGCInCache): New method.
	(getGCFromCache): New method.
	* gnu/gcj/xlib/GC.java (GC): Make protected.
	(clone): Get new GC from cache if possible.
	(create): New static method.
	(dispose): Save old GC in cache.
	* gnu/gcj/xlib/natClip.cc (dispose): Check for null before
	deleting.
	* gnu/gcj/xlib/natGC.cc (initStructure): Call XCreateGC only if gc
	is null.
	* gnu/gcj/xlib/Pixmap.java (Pixmap): Use new GC.create.
	* java/awt/Container.java (visitChild): Dispose gfx2 when
	finished.

From-SVN: r65827
This commit is contained in:
Scott Gilbertson 2003-04-19 19:54:39 +00:00 committed by Tom Tromey
parent afd4910af1
commit 9e9e204234
10 changed files with 132 additions and 27 deletions

View file

@ -23,17 +23,25 @@ import java.awt.Rectangle;
*/
public class GC implements Cloneable
{
public GC(Drawable target)
/** Protected constructor, because GC.create(target) should be used instead.
*/
protected GC(Drawable target)
{
this.target = target;
initStructure(null);
}
/** Try to get a suitable GC from the drawable's cache.
* If there isn't one, create one.
*/
public Object clone()
{
GC gcClone = (GC) super.clone();
gcClone.structure = null;
GC gcClone = target.getGCFromCache ();
if (gcClone==null)
{
gcClone = (GC) super.clone();
gcClone.structure = null;
}
gcClone.initStructure(this);
gcClone.updateClip();
return gcClone;
@ -45,15 +53,31 @@ public class GC implements Cloneable
{
return (GC) clone();
}
/** Create a GC, or if one is already cached for target, return that.
* @param target The Drawable for which a GC is needed
* @return The new or retrieved GC
*/
static public GC create (Drawable target)
{
GC returnValue = target.getGCFromCache ();
if (returnValue == null)
returnValue = new GC (target);
return returnValue;
}
public void finalize()
{
disposeImpl();
}
/** Save this GC in the drawable's cache.
* The "real" dispose (disposeImpl) is called when the
* drawable is finialized, to free X server resources.
*/
public void dispose()
{
disposeImpl();
target.putGCInCache (this);
}
public synchronized native void disposeImpl();