/[classpath]/classpath/gnu/java/awt/peer/gtk/GtkImage.java
ViewVC logotype

Diff of /classpath/gnu/java/awt/peer/gtk/GtkImage.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by mark, Tue Aug 16 18:16:26 2005 UTC revision 1.24 by fitzsim, Fri Sep 2 03:15:21 2005 UTC
# Line 51  import java.io.File; Line 51  import java.io.File;
51  import java.io.IOException;  import java.io.IOException;
52  import java.util.Hashtable;  import java.util.Hashtable;
53  import java.util.Vector;  import java.util.Vector;
54    import java.io.ByteArrayOutputStream;
55    import java.io.BufferedInputStream;
56    import java.net.URL;
57  import gnu.classpath.Pointer;  import gnu.classpath.Pointer;
58    
59  /**  /**
# Line 129  public class GtkImage extends Image Line 132  public class GtkImage extends Image
132    private native void setPixels(int[] pixels);    private native void setPixels(int[] pixels);
133    
134    /**    /**
135     * Loads an image using gdk-pixbuf.     * Loads an image using gdk-pixbuf from a file.
136     */     */
137    private native boolean loadPixbuf(String name);    private native boolean loadPixbuf(String name);
138    
139    /**    /**
140       * Loads an image using gdk-pixbuf from data.
141       */
142      private native boolean loadImageFromData(byte[] data);
143    
144      /**
145     * Allocates a Gtk Pixbuf or pixmap     * Allocates a Gtk Pixbuf or pixmap
146     */     */
147    private native void createPixmap();    private native void createPixmap();
# Line 210  public class GtkImage extends Image Line 218  public class GtkImage extends Image
218      props = new Hashtable();      props = new Hashtable();
219    }    }
220    
221      /**
222       * Constructs a GtkImage from a byte array of an image file.
223       *
224       * @throws IllegalArgumentException if the image could not be
225       * loaded.
226       */
227      public GtkImage (byte[] data)
228      {
229        if (loadImageFromData (data) != true)
230          throw new IllegalArgumentException ("Couldn't load image.");
231    
232        isLoaded = true;
233        observers = null;
234        offScreen = false;
235        props = new Hashtable();
236        errorLoading = false;
237      }
238    
239      /**
240       * Constructs a GtkImage from a URL. May result in an error image.
241       */
242      public GtkImage (URL url)
243      {
244        isLoaded = false;
245        observers = new Vector();
246        errorLoading = false;
247        if( url == null)
248          return;
249        ByteArrayOutputStream baos = new ByteArrayOutputStream (5000);
250        try
251          {
252            BufferedInputStream bis = new BufferedInputStream (url.openStream());
253    
254            byte[] buf = new byte[5000];
255            int n = 0;
256    
257            while ((n = bis.read(buf)) != -1)
258              baos.write(buf, 0, n);
259            bis.close();
260          }
261        catch(IOException e)
262          {
263            throw new IllegalArgumentException ("Couldn't load image.");
264          }
265        if (loadImageFromData (baos.toByteArray()) != true)
266          throw new IllegalArgumentException ("Couldn't load image.");
267    
268        isLoaded = true;
269        observers = null;
270        props = new Hashtable();
271      }
272    
273    /**    /**
274     * Constructs an empty GtkImage.     * Constructs an empty GtkImage.
275     */     */

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26