aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/java
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2003-11-12 00:37:34 +0000
committerThomas Fitzsimmons <fitzsim@gcc.gnu.org>2003-11-12 00:37:34 +0000
commita5966c9ef9036294c09f0729f9950b90b1d1c3b5 (patch)
tree76d0f90da057662bc2f5deb1bc000be30244807e /libjava/gnu/java
parentc754c6f1311f79ce60dfdf9e8d61b9557a36808f (diff)
downloadgcc-a5966c9ef9036294c09f0729f9950b90b1d1c3b5.zip
gcc-a5966c9ef9036294c09f0729f9950b90b1d1c3b5.tar.gz
gcc-a5966c9ef9036294c09f0729f9950b90b1d1c3b5.tar.bz2
Makefile.am: Add GdkPixbufDecoder.java and gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
2003-11-11 Thomas Fitzsimmons <fitzsim@redhat.com> * Makefile.am: Add GdkPixbufDecoder.java and gnu_java_awt_peer_gtk_GdkPixbufDecoder.c * Makefile.in: Regenerate. * gnu/java/awt/image/ImageDecoder.java (ImageDecoder(byte[],int,int)): New constructor. (startProduction): Create ByteArrayInputStream when url and filename are null. (produce): Declare stream parameter as InputStream. * gnu/java/awt/image/XBMDecoder.java (produce): Declare stream parameter as InputStream. * gnu/java/awt/peer/gtk/GdkPixbufDecoder.java (GdkPixbufDecoder(byte[],int,int)): New constructor. (produce): Declare stream parameter as InputStream. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (prepareImage): Throw NPE if image is null. Set image's observer before running PrepareImage thread. Pass image to startProduction. * gnu/java/awt/peer/gtk/GtkImage.java: Add null checks before calls to source's member functions. (observer): New field. (setObserver): New method. (setDimensions, setPixels, imageComplete): Call observer's imageUpdate. * gnu/java/awt/peer/gtk/GtkToolkit.java (checkImage, getImage): Return new GtkImage. (prepareImage): Implement. * java/awt/Component.java: Add static fields incrementalDraw and redrawRate. (imageUpdate): Implement. (createImage): Call Toolkit's createImage if peer is null. (prepareImage): Throw NPE if image is null. * java/awt/MediaTracker.java: Fix return value. From-SVN: r73476
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r--libjava/gnu/java/awt/image/ImageDecoder.java34
-rw-r--r--libjava/gnu/java/awt/image/XBMDecoder.java2
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java10
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java8
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkImage.java51
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkToolkit.java55
6 files changed, 122 insertions, 38 deletions
diff --git a/libjava/gnu/java/awt/image/ImageDecoder.java b/libjava/gnu/java/awt/image/ImageDecoder.java
index 4d3fbec..d44efce 100644
--- a/libjava/gnu/java/awt/image/ImageDecoder.java
+++ b/libjava/gnu/java/awt/image/ImageDecoder.java
@@ -48,6 +48,10 @@ public abstract class ImageDecoder implements ImageProducer
Vector consumers = new Vector ();
String filename;
URL url;
+ byte[] data;
+ int offset;
+ int length;
+ InputStream input;
public static ColorModel cm;
@@ -69,6 +73,13 @@ public abstract class ImageDecoder implements ImageProducer
this.url = url;
}
+ public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength)
+ {
+ data = imagedata;
+ offset = imageoffset;
+ length = imagelength;
+ }
+
public void addConsumer (ImageConsumer ic)
{
consumers.addElement (ic);
@@ -90,11 +101,22 @@ public abstract class ImageDecoder implements ImageProducer
Vector list = (Vector) consumers.clone ();
try
{
- FileInputStream is = (url == null) ? new FileInputStream (filename) :
- (FileInputStream) url.openStream();
-
- produce (list, is);
- }
+ // Create the input stream here rather than in the
+ // ImageDecoder constructors so that exceptions cause
+ // imageComplete to be called with an appropriate error
+ // status.
+ if (url != null)
+ input = url.openStream();
+ else
+ {
+ if (filename != null)
+ input = new FileInputStream (filename);
+ else
+ input = new ByteArrayInputStream (data, offset, length);
+ }
+
+ produce (list, input);
+ }
catch (Exception e)
{
for (int i = 0; i < list.size (); i++)
@@ -109,5 +131,5 @@ public abstract class ImageDecoder implements ImageProducer
{
}
- abstract void produce (Vector v, FileInputStream is) throws IOException;
+ abstract void produce (Vector v, InputStream is) throws IOException;
}
diff --git a/libjava/gnu/java/awt/image/XBMDecoder.java b/libjava/gnu/java/awt/image/XBMDecoder.java
index 2505b3d..b80fd55 100644
--- a/libjava/gnu/java/awt/image/XBMDecoder.java
+++ b/libjava/gnu/java/awt/image/XBMDecoder.java
@@ -62,7 +62,7 @@ public class XBMDecoder extends ImageDecoder
super (url);
}
- public void produce (Vector v, FileInputStream is) throws IOException
+ public void produce (Vector v, InputStream is) throws IOException
{
reader = new BufferedReader (new InputStreamReader (is));
int width = -1, height = -1;
diff --git a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java b/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
index 55f3338..3cc42cb 100644
--- a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
+++ b/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
@@ -41,6 +41,7 @@ package gnu.java.awt.peer.gtk;
import java.awt.image.*;
import java.io.FileDescriptor;
import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Vector;
@@ -85,6 +86,12 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
initState ();
}
+ public GdkPixbufDecoder (byte[] imagedata, int imageoffset, int imagelength)
+ {
+ super (imagedata, imageoffset, imagelength);
+ initState ();
+ }
+
// called back by native side
void areaPrepared (int width, int height)
{
@@ -122,7 +129,7 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
// this object, feeding back decoded pixel blocks, which we pass to each
// of the ImageConsumers in the provided Vector.
- void produce (Vector v, FileInputStream is) throws IOException
+ public void produce (Vector v, InputStream is) throws IOException
{
curr = v;
@@ -213,5 +220,4 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
dec.startProduction (bb);
return bb.getBufferedImage ();
}
-
}
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index f3676f3..f4c143b 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -230,6 +230,9 @@ public class GtkComponentPeer extends GtkGenericPeer
public boolean prepareImage (Image image, int width, int height,
ImageObserver observer)
{
+ if (image == null)
+ throw new NullPointerException ();
+
GtkImage i = (GtkImage) image;
if (i.isLoaded ()) return true;
@@ -242,13 +245,12 @@ public class GtkComponentPeer extends GtkGenericPeer
PrepareImage (GtkImage image, ImageObserver observer)
{
this.image = image;
- this.observer = observer;
+ image.setObserver (observer);
}
public void run ()
{
- // XXX: need to return data to image observer
- image.source.startProduction (null);
+ image.source.startProduction (image);
}
}
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkImage.java b/libjava/gnu/java/awt/peer/gtk/GtkImage.java
index 6252a50..5f8d223 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkImage.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkImage.java
@@ -60,6 +60,7 @@ public class GtkImage extends Image implements ImageConsumer
Vector propertyObservers = new Vector ();
ImageProducer source;
+ ImageObserver observer;
Graphics g;
/* Variables in which we stored cached data, if possible.
@@ -79,9 +80,15 @@ public class GtkImage extends Image implements ImageConsumer
source = producer;
this.g = g;
- source.addConsumer (this);
+ if (source != null)
+ source.addConsumer (this);
}
-
+
+ public void setObserver (ImageObserver observer)
+ {
+ this.observer = observer;
+ }
+
public synchronized int
getWidth (ImageObserver observer)
{
@@ -135,8 +142,11 @@ public class GtkImage extends Image implements ImageConsumer
pixelCache = null;
model = null;
- source.removeConsumer (this);
- source.addConsumer (this);
+ if (source != null)
+ {
+ source.removeConsumer (this);
+ source.addConsumer (this);
+ }
}
public boolean
@@ -166,6 +176,12 @@ public class GtkImage extends Image implements ImageConsumer
ImageObserver io = (ImageObserver) heightObservers.elementAt (i);
io.imageUpdate (this, ImageObserver.HEIGHT, -1, -1, width, height);
}
+
+ if (observer != null)
+ observer.imageUpdate (this,
+ (ImageObserver.WIDTH
+ | ImageObserver.HEIGHT),
+ -1, -1, width, height);
}
public synchronized void
@@ -200,6 +216,11 @@ public class GtkImage extends Image implements ImageConsumer
{
setPixels (x, y, width, height, cm, convertPixels (pixels), offset,
scansize);
+
+ if (observer != null)
+ observer.imageUpdate (this,
+ ImageObserver.SOMEBITS,
+ x, y, width, height);
}
public synchronized void
@@ -241,7 +262,20 @@ public class GtkImage extends Image implements ImageConsumer
if (status == ImageConsumer.SINGLEFRAMEDONE)
isCacheable = false;
- source.removeConsumer (this);
+ if (observer != null)
+ {
+ if (status == ImageConsumer.IMAGEERROR)
+ observer.imageUpdate (null,
+ ImageObserver.ERROR,
+ -1, -1, -1, -1);
+ else
+ observer.imageUpdate (null,
+ ImageObserver.ALLBITS,
+ -1, -1, -1, -1);
+ }
+
+ if (source != null)
+ source.removeConsumer (this);
}
public synchronized void
@@ -254,8 +288,11 @@ public class GtkImage extends Image implements ImageConsumer
}
else
{
- source.startProduction (painter);
- source.removeConsumer (painter);
+ if (source != null)
+ {
+ source.startProduction (painter);
+ source.removeConsumer (painter);
+ }
}
}
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
index 9f669ac..7f8ae2e 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -56,6 +56,7 @@ import gnu.java.awt.EmbeddedWindow;
import gnu.java.awt.EmbeddedWindowSupport;
import gnu.java.awt.peer.EmbeddedWindowPeer;
import gnu.classpath.Configuration;
+import gnu.java.awt.peer.gtk.GdkPixbufDecoder;
/* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer().
This merits comment. We are basically calling Sun's bluff on this one.
@@ -91,24 +92,17 @@ public class GtkToolkit extends Toolkit
public int checkImage (Image image, int width, int height,
ImageObserver observer)
{
- return ImageObserver.ALLBITS;
-
-// GtkImage i = (GtkImage) image;
-// return i.checkImage ();
+ return ((GtkImage) image).checkImage ();
}
public Image createImage (String filename)
{
- // FIXME - gcj local: GdkPixbufDecoder doesn't work.
- // return new GtkImage (new GdkPixbufDecoder (filename), null);
- return null;
+ return new GtkImage (new GdkPixbufDecoder (filename), null);
}
public Image createImage (URL url)
{
- // FIXME - gcj local: GdkPixbufDecoder doesn't work.
- // return new GtkImage (new GdkPixbufDecoder (url), null);
- return null;
+ return new GtkImage (new GdkPixbufDecoder (url), null);
}
public Image createImage (ImageProducer producer)
@@ -117,10 +111,12 @@ public class GtkToolkit extends Toolkit
}
public Image createImage (byte[] imagedata, int imageoffset,
- int imagelength)
+ int imagelength)
{
- // System.out.println ("createImage byte[] NOT SUPPORTED");
- return null;
+ return new GtkImage (new GdkPixbufDecoder (imagedata,
+ imageoffset,
+ imagelength),
+ null);
}
public ColorModel getColorModel ()
@@ -144,16 +140,12 @@ public class GtkToolkit extends Toolkit
public Image getImage (String filename)
{
- // FIXME - gcj local: GdkPixbufDecoder doesn't work.
- // return new GtkImage (new GdkPixbufDecoder (filename), null);
- return null;
+ return new GtkImage (new GdkPixbufDecoder (filename), null);
}
public Image getImage (URL url)
{
- // FIXME - gcj local: GdkPixbufDecoder doesn't work.
- // return new GtkImage (new GdkPixbufDecoder (url), null);
- return null;
+ return new GtkImage (new GdkPixbufDecoder (url), null);
}
public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
@@ -177,6 +169,31 @@ public class GtkToolkit extends Toolkit
public boolean prepareImage (Image image, int width, int height,
ImageObserver observer)
{
+ if (image == null)
+ throw new NullPointerException ();
+
+ GtkImage i = (GtkImage) image;
+
+ if (i.isLoaded ()) return true;
+
+ class PrepareImage extends Thread
+ {
+ GtkImage image;
+ ImageObserver observer;
+
+ PrepareImage (GtkImage image, ImageObserver observer)
+ {
+ this.image = image;
+ image.setObserver (observer);
+ }
+
+ public void run ()
+ {
+ image.source.startProduction (image);
+ }
+ }
+
+ new PrepareImage (i, observer).start ();
return false;
}