OSDN Git Service

2006-08-14 Mark Wielaard <mark@klomp.org>
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / javax / imageio / png / PNGData.java
@@ -1,5 +1,5 @@
-/* GtkCheckboxGroupPeer.java - Wrap a CheckboxGroup
-   Copyright (C) 2002 Free Software Foundation, Inc.
+/* PNGData.java -- PNG IDAT chunk.
+   Copyright (C) 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -35,52 +35,70 @@ this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+package gnu.javax.imageio.png;
 
-package gnu.java.awt.peer.gtk;
+import java.util.zip.Inflater;
+import java.util.zip.Deflater;
 
-import java.awt.CheckboxGroup;
-import java.util.WeakHashMap;
+/**
+ * A PNG IDAT (data) chunk.
+ */
+public class PNGData extends PNGChunk 
+{ 
+  private int offset;
 
-// Note that there is no peer interface for a CheckboxGroup.  We
-// introduce our own in order to make it easier to keep a piece of
-// native state for each one.
-public class GtkCheckboxGroupPeer extends GtkGenericPeer
-{
-  // This maps from a CheckboxGroup to the native peer.
-  private static WeakHashMap map = new WeakHashMap ();
+  protected PNGData( int type, byte[] data, int crc )
+  {
+    super( type, data, crc );
+  }
 
-  // Find the native peer corresponding to a CheckboxGroup.
-  public static synchronized GtkCheckboxGroupPeer
-      getCheckboxGroupPeer (CheckboxGroup group)
+  protected PNGData( int chunkSize )
   {
-    if (group == null)
-      return null;
-    GtkCheckboxGroupPeer nat = (GtkCheckboxGroupPeer) map.get (group);
-    if (nat == null)
-      {
-       nat = new GtkCheckboxGroupPeer ();
-       map.put (group, nat);
-      }
-    return nat;
+    super( PNGChunk.TYPE_DATA );
+    data = new byte[ chunkSize ];
+    offset = 0;
   }
 
-  private GtkCheckboxGroupPeer ()
+  /**
+   * Deflates the available data in def to the chunk.
+   *
+   * @return true if the chunk is filled and no more data can be written,
+   * false otherwise.
+   */
+  public void deflateToChunk( Deflater def ) 
   {
-    // We don't need any special state here.  Note that we can't store
-    // a reference to the java-side CheckboxGroup.  That would mean
-    // they could never be collected.
-    super (null);
+    offset += def.deflate( data, offset, data.length - offset );
   }
 
-  // Dispose of our native resources.
-  public native void dispose ();
+  /**
+   * Returns true if the chunk is filled.
+   */
+  public boolean chunkFull()
+  {
+    return (offset >= data.length);
+  }
 
-  // Remove a given checkbox from this group.
-  public native void remove (GtkCheckboxPeer box);
+  /**
+   * Shrink the chunk to offset size, used for the last chunk in a stream
+   * (no trailing data!) 
+   */
+  public void shrink()
+  {
+    byte[] newData = new byte[ offset ];
+    System.arraycopy( data, 0, newData, 0, offset );
+    data = newData;
+  }
+
+  /**
+   * Feeds the data in the chunk to a ZIP inflater object.
+   */
+  public void feedToInflater( Inflater inf ) 
+  {
+    inf.setInput( data );
+  }
 
-  // When collected, clean up the native state.
-  protected void finalize ()
+  public String toString()
   {
-    dispose ();
+    return "PNG Data chunk. Length = "+data.length;
   }
 }