org.zkoss.image
Class AImage

java.lang.Object
  extended by org.zkoss.image.AImage
All Implemented Interfaces:
Image, Media

public class AImage
extends java.lang.Object
implements Image

Represents an image. Unlike java.awt.Image and javax.swing.ImageIcon, this class holds the raw image data, i.e., the original format, as opaque.

In other words, it is used to retrieve and store the opaque data as polymorphic thru the Media interface.

Author:
tomyeh

Constructor Summary
AImage(java.io.File file)
           
AImage(java.lang.String filename)
           
AImage(java.lang.String name, byte[] data)
          the hash code.
AImage(java.lang.String name, java.io.InputStream is)
           
AImage(java.net.URL url)
           
 
Method Summary
 byte[] getByteData()
          Returns the raw data in byte array.
 java.lang.String getContentType()
          Returns the content type, e.g., "image/jpeg", or null if not available.
 java.lang.String getFormat()
          Returns the format name, e.g., "jpeg", or null if not available.
 int getHeight()
          Returns the height.
 java.lang.String getName()
          Returns the name (usually filename) of this media, or null if not available.
 java.io.Reader getReaderData()
          Always throws IllegalStateException.
 java.io.InputStream getStreamData()
          An input stream on top of getByteData().
 java.lang.String getStringData()
          Always throws IllegalStateException.
 int getWidth()
          Returns the width.
 boolean inMemory()
          Returns whether the data is cached in memory (in form of byte[] or String).
 boolean isBinary()
          Returns whether the format of tis content is binary or text-based.
 javax.swing.ImageIcon toImageIcon()
          Converts to an image icon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AImage

public AImage(java.lang.String name,
              byte[] data)
       throws java.io.IOException
the hash code.

Throws:
java.io.IOException

AImage

public AImage(java.lang.String name,
              java.io.InputStream is)
       throws java.io.IOException
Throws:
java.io.IOException

AImage

public AImage(java.lang.String filename)
       throws java.io.IOException
Throws:
java.io.IOException

AImage

public AImage(java.io.File file)
       throws java.io.IOException
Throws:
java.io.IOException

AImage

public AImage(java.net.URL url)
       throws java.io.IOException
Throws:
java.io.IOException
Method Detail

isBinary

public final boolean isBinary()
Description copied from interface: Media
Returns whether the format of tis content is binary or text-based. If true, use Media.getByteData() or Media.getStreamData(), depending on Media.inMemory(), to retrieve its content. If false, use Media.getStringData() or Media.getReaderData(), depending on Media.inMemory(), to retrieve its content.

To decide which API to use, you need to examine both Media.isBinary() and Media.inMemory().

Specified by:
isBinary in interface Media
See Also:
Media.getStringData(), Media.getByteData(), Media.getReaderData(), Media.getStreamData()

inMemory

public final boolean inMemory()
Description copied from interface: Media
Returns whether the data is cached in memory (in form of byte[] or String). If true, use Media.getByteData() or Media.getStringData(), depending on Media.isBinary(), to retrieve its content. If false, use Media.getStreamData() or Media.getReaderData(), depending on Media.isBinary(), to retrieve its content.

To decide which API to use, you need to examine both Media.isBinary() and Media.inMemory().

Specified by:
inMemory in interface Media
See Also:
Media.getStringData(), Media.getByteData(), Media.getReaderData(), Media.getStreamData()

getByteData

public byte[] getByteData()
Description copied from interface: Media
Returns the raw data in byte array.

It might not be a copy, so don't modify it directly unless you know what you are doing.

Specified by:
getByteData in interface Media
See Also:
Media.getStringData()

getStringData

public final java.lang.String getStringData()
Always throws IllegalStateException.

Specified by:
getStringData in interface Media
See Also:
Media.getByteData()

getStreamData

public final java.io.InputStream getStreamData()
An input stream on top of getByteData().

Specified by:
getStreamData in interface Media
See Also:
Media.getReaderData()

getReaderData

public final java.io.Reader getReaderData()
Always throws IllegalStateException.

Specified by:
getReaderData in interface Media
See Also:
Media.getStreamData()

getName

public final java.lang.String getName()
Description copied from interface: Media
Returns the name (usually filename) of this media, or null if not available.

Specified by:
getName in interface Media

getFormat

public final java.lang.String getFormat()
Description copied from interface: Media
Returns the format name, e.g., "jpeg", or null if not available.

Specified by:
getFormat in interface Media
See Also:
Media.getContentType()

getContentType

public final java.lang.String getContentType()
Description copied from interface: Media
Returns the content type, e.g., "image/jpeg", or null if not available.

Specified by:
getContentType in interface Media
See Also:
Media.getFormat()

getWidth

public final int getWidth()
Returns the width.

Specified by:
getWidth in interface Image

getHeight

public final int getHeight()
Returns the height.

Specified by:
getHeight in interface Image

toImageIcon

public final javax.swing.ImageIcon toImageIcon()
Converts to an image icon.

Specified by:
toImageIcon in interface Image


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.