edu.rit.slides.items
Class ImageItem

java.lang.Object
  extended by edu.rit.slides.items.SlideItem
      extended by edu.rit.slides.items.ImageItem
All Implemented Interfaces:
Externalizable, Serializable

public class ImageItem
extends SlideItem
implements Externalizable

Class ImageItem provides a SlideItem containing an image. The image is read from an input stream when the image item is constructed. Image formats supported by the javax.imageio package are supported; this typically includes GIF, JPEG, and PNG images.

Class ImageItem keeps track of the "last image item." The static ImageItem.last() method returns a reference to the last created image item.

When an ImageItem is created, the "last point" (returned by the Point.last() method) is set to the point where the image item was located.

See Also:
Serialized Form

Constructor Summary
ImageItem()
          Construct a new empty image item.
ImageItem(InputStream in, Point theLocation)
          Construct a new image item with the image read from the given input stream.
ImageItem(InputStream in, Point theLocation, double scale)
          Construct a new image item with the image read from the given input stream.
 
Method Summary
 Point c()
          Returns the center point of this image item.
 void draw(Graphics2D g2d)
          Draw this image item in the given graphics context.
 Point e()
          Returns the east middle point of this image item.
static ImageItem last()
          Returns the last image item created.
 Point location()
          Returns this image item's upper left corner location.
 Point n()
          Returns the north middle point of this image item.
 Point ne()
          Returns the northeast corner point of this image item.
 Point nw()
          Returns the northwest corner point of this image item.
 void readExternal(ObjectInput in)
          Read this image item from the given object input stream.
 Point s()
          Returns the south middle point of this image item.
 Point se()
          Returns the southeast corner point of this image item.
 Size size()
          Returns this image item's size.
 Point sw()
          Returns the southwest corner point of this image item.
 Point w()
          Returns the west middle point of this image item.
 void writeExternal(ObjectOutput out)
          Write this image item to the given object output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageItem

public ImageItem()
Construct a new empty image item.


ImageItem

public ImageItem(InputStream in,
                 Point theLocation)
          throws IOException
Construct a new image item with the image read from the given input stream. The entire input stream is read until EOF is encountered, then the input stream is closed. The image's upper left corner goes on the slide at the given location. The image is displayed at its regular size, one image pixel = one display unit.

Parameters:
in - Input stream from which to read the image.
theLocation - Upper left corner location.
Throws:
NullPointerException - (unchecked exception) Thrown if in is null or theLocation is null.
IOException - Thrown if an I/O error occurred.

ImageItem

public ImageItem(InputStream in,
                 Point theLocation,
                 double scale)
          throws IOException
Construct a new image item with the image read from the given input stream. The entire input stream is read until EOF is encountered, then the input stream is closed. The image's upper left corner goes on the slide at the given location. The image is displayed at a scaled size, one image pixel = scale display units.

Parameters:
in - Input stream from which to read the image.
theLocation - Upper left corner location.
scale - Scale factor > 0.
Throws:
NullPointerException - (unchecked exception) Thrown if in is null or theLocation is null.
IllegalArgumentException - (unchecked exception) Thrown if scale <= 0.
IOException - Thrown if an I/O error occurred.
Method Detail

last

public static ImageItem last()
Returns the last image item created. If no image items have been created yet, null is returned.


location

public Point location()
Returns this image item's upper left corner location.


size

public Size size()
Returns this image item's size.


nw

public Point nw()
Returns the northwest corner point of this image item.


n

public Point n()
Returns the north middle point of this image item.


ne

public Point ne()
Returns the northeast corner point of this image item.


w

public Point w()
Returns the west middle point of this image item.


c

public Point c()
Returns the center point of this image item.


e

public Point e()
Returns the east middle point of this image item.


sw

public Point sw()
Returns the southwest corner point of this image item.


s

public Point s()
Returns the south middle point of this image item.


se

public Point se()
Returns the southeast corner point of this image item.


draw

public void draw(Graphics2D g2d)
Draw this image item in the given graphics context.

Specified by:
draw in class SlideItem
Parameters:
g2d - 2-D graphics context.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this image item to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Read this image item from the given object input stream.

Specified by:
readExternal in interface Externalizable
Parameters:
in - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.
ClassNotFoundException - Thrown if any class needed to deserialize this image item cannot be found.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.