edu.rit.draw.item
Class Image

java.lang.Object
  extended by edu.rit.draw.item.DrawingItem
      extended by edu.rit.draw.item.Image
All Implemented Interfaces:
Externalizable, Serializable

public class Image
extends DrawingItem
implements Externalizable

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

See Also:
Serialized Form

Field Summary
static double NORMAL_SCALE
          The normal scale factor (1).
 
Constructor Summary
Image()
          Construct a new image item.
Image(Image theItem)
          Construct a new image item with the same image and attributes as the given image item.
 
Method Summary
 Image add()
          Add this image item to the end of the default drawing's sequence of drawing items.
 Image add(Drawing theDrawing)
          Add this image item to the end of the given drawing's sequence of drawing items.
 Image addFirst()
          Add this image item to the beginning of the default drawing's sequence of drawing items.
 Image addFirst(Drawing theDrawing)
          Add this image item to the beginning of the given drawing's sequence of drawing items.
 Image c(double x, double y)
          Set the center point of this image item's bounding box.
 Image c(Point thePoint)
          Set the center point of this image item's bounding box.
static double defaultScale()
          Returns the default scale factor.
static void defaultScale(double theScale)
          Set the default scale factor.
 void draw(Graphics2D g2d)
          Draw this image item in the given graphics context.
 Image e(double x, double y)
          Set the east middle point of this image item's bounding box.
 Image e(Point thePoint)
          Set the east middle point of this image item's bounding box.
 double height()
          Returns the height of this image item's bounding box.
 BufferedImage image()
          Returns this image item's image.
 Image image(File theFile)
          Read this image item's image from the given file.
 Image image(InputStream in)
          Read this image item's image from the given input stream.
 Image image(String theFileName)
          Read this image item's image from the file with the given name.
 Image n(double x, double y)
          Set the north middle point of this image item's bounding box.
 Image n(Point thePoint)
          Set the north middle point of this image item's bounding box.
 Image ne(double x, double y)
          Set the northeast corner point of this image item's bounding box.
 Image ne(Point thePoint)
          Set the northeast corner point of this image item's bounding box.
 Point nw()
          Returns the northwest corner point of this image item's bounding box.
 Image nw(double x, double y)
          Set the northwest corner point of this image item's bounding box.
 Image nw(Point thePoint)
          Set the northwest corner point of this image item's bounding box.
 void readExternal(ObjectInput in)
          Read this image item from the given object input stream.
 Image s(double x, double y)
          Set the south middle point of this image item's bounding box.
 Image s(Point thePoint)
          Set the south middle point of this image item's bounding box.
 double scale()
          Returns this image item's scale factor.
 Image scale(double theScale)
          Set this image item's scale factor.
 Image se(double x, double y)
          Set the southeast corner point of this image item's bounding box.
 Image se(Point thePoint)
          Set the southeast corner point of this image item's bounding box.
 Image sw(double x, double y)
          Set the southwest corner point of this image item's bounding box.
 Image sw(Point thePoint)
          Set the southwest corner point of this image item's bounding box.
 Image w(double x, double y)
          Set the west middle point of this image item's bounding box.
 Image w(Point thePoint)
          Set the west middle point of this image item's bounding box.
 double width()
          Returns the width of this image item's bounding box.
 void writeExternal(ObjectOutput out)
          Write this image item to the given object output stream.
 
Methods inherited from class edu.rit.draw.item.DrawingItem
boundingBox, c, e, n, ne, s, se, size, sw, w
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL_SCALE

public static final double NORMAL_SCALE
The normal scale factor (1).

See Also:
Constant Field Values
Constructor Detail

Image

public Image()
Construct a new image item. The image item's image is empty. The image item's northwest corner is located at (0,0). The image item's attributes have the default values.


Image

public Image(Image theItem)
Construct a new image item with the same image and attributes as the given image item.

Parameters:
theItem - Image item.
Throws:
NullPointerException - (unchecked exception) Thrown if theItem is null.
Method Detail

defaultScale

public static double defaultScale()
Returns the default scale factor. Images are displayed at a scaled size, one image pixel = (scale factor) display units.

Returns:
Default scale factor.

defaultScale

public static void defaultScale(double theScale)
Set the default scale factor. Images are displayed at a scaled size, one image pixel = (scale factor) display units.

Parameters:
theScale - Default scale factor.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theScale is less than 0.

image

public BufferedImage image()
Returns this image item's image.

Returns:
Image.

image

public Image image(String theFileName)
            throws IOException
Read this image item's image from the file with the given name.

Parameters:
theFileName - File name.
Returns:
This image item.
Throws:
IOException - Thrown if an I/O error occurred.

image

public Image image(File theFile)
            throws IOException
Read this image item's image from the given file.

Parameters:
theFile - File.
Returns:
This image item.
Throws:
IOException - Thrown if an I/O error occurred.

image

public Image image(InputStream in)
            throws IOException
Read this image item's image from the given input stream. The entire input stream is read until EOF is encountered, then the input stream is closed.

Parameters:
in - Input stream.
Returns:
This image item.
Throws:
IOException - Thrown if an I/O error occurred.

scale

public double scale()
Returns this image item's scale factor. This image is displayed at a scaled size, one image pixel = (scale factor) display units.

Returns:
Scale factor.

scale

public Image scale(double theScale)
Set this image item's scale factor. This image is displayed at a scaled size, one image pixel = (scale factor) display units.

Parameters:
theScale - Scale factor.
Returns:
This image.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theScale is less than 0.

width

public double width()
Returns the width of this image item's bounding box.

Specified by:
width in class DrawingItem
Returns:
Width.

height

public double height()
Returns the height of this image item's bounding box.

Specified by:
height in class DrawingItem
Returns:
Height.

nw

public Point nw()
Returns the northwest corner point of this image item's bounding box.

Specified by:
nw in class DrawingItem
Returns:
Northwest corner point.

nw

public Image nw(double x,
                double y)
Set the northwest corner point of this image item's bounding box.

Parameters:
x - X coordinate of northwest corner point.
y - Y coordinate of northwest corner point.
Returns:
This image item.

nw

public Image nw(Point thePoint)
Set the northwest corner point of this image item's bounding box.

Parameters:
thePoint - Northwest corner point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

n

public Image n(double x,
               double y)
Set the north middle point of this image item's bounding box.

Parameters:
x - X coordinate of north middle point.
y - Y coordinate of north middle point.
Returns:
This image item.

n

public Image n(Point thePoint)
Set the north middle point of this image item's bounding box.

Parameters:
thePoint - North middle point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

ne

public Image ne(double x,
                double y)
Set the northeast corner point of this image item's bounding box.

Parameters:
x - X coordinate of northeast corner point.
y - Y coordinate of northeast corner point.
Returns:
This image item.

ne

public Image ne(Point thePoint)
Set the northeast corner point of this image item's bounding box.

Parameters:
thePoint - Northeast corner point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

w

public Image w(double x,
               double y)
Set the west middle point of this image item's bounding box.

Parameters:
x - X coordinate of west middle point.
y - Y coordinate of west middle point.
Returns:
This image item.

w

public Image w(Point thePoint)
Set the west middle point of this image item's bounding box.

Parameters:
thePoint - West middle point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

c

public Image c(double x,
               double y)
Set the center point of this image item's bounding box.

Parameters:
x - X coordinate of center point.
y - Y coordinate of center point.
Returns:
This image item.

c

public Image c(Point thePoint)
Set the center point of this image item's bounding box.

Parameters:
thePoint - Center point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

e

public Image e(double x,
               double y)
Set the east middle point of this image item's bounding box.

Parameters:
x - X coordinate of east middle point.
y - Y coordinate of east middle point.
Returns:
This image item.

e

public Image e(Point thePoint)
Set the east middle point of this image item's bounding box.

Parameters:
thePoint - East middle point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

sw

public Image sw(double x,
                double y)
Set the southwest corner point of this image item's bounding box.

Parameters:
x - X coordinate of southwest corner point.
y - Y coordinate of southwest corner point.
Returns:
This image item.

sw

public Image sw(Point thePoint)
Set the southwest corner point of this image item's bounding box.

Parameters:
thePoint - Southwest corner point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

s

public Image s(double x,
               double y)
Set the south middle point of this image item's bounding box.

Parameters:
x - X coordinate of south middle point.
y - Y coordinate of south middle point.
Returns:
This image item.

s

public Image s(Point thePoint)
Set the south middle point of this image item's bounding box.

Parameters:
thePoint - South middle point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

se

public Image se(double x,
                double y)
Set the southeast corner point of this image item's bounding box.

Parameters:
x - X coordinate of southeast corner point.
y - Y coordinate of southeast corner point.
Returns:
This image item.

se

public Image se(Point thePoint)
Set the southeast corner point of this image item's bounding box.

Parameters:
thePoint - Southeast corner point.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

add

public Image add()
Add this image item to the end of the default drawing's sequence of drawing items.

Overrides:
add in class DrawingItem
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

add

public Image add(Drawing theDrawing)
Add this image item to the end of the given drawing's sequence of drawing items.

Overrides:
add in class DrawingItem
Parameters:
theDrawing - Drawing.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

addFirst

public Image addFirst()
Add this image item to the beginning of the default drawing's sequence of drawing items.

Overrides:
addFirst in class DrawingItem
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

addFirst

public Image addFirst(Drawing theDrawing)
Add this image item to the beginning of the given drawing's sequence of drawing items.

Overrides:
addFirst in class DrawingItem
Parameters:
theDrawing - Drawing.
Returns:
This image item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

writeExternal

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

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class DrawingItem
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
Overrides:
readExternal in class DrawingItem
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.

draw

public void draw(Graphics2D g2d)
Draw this image item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.

Overrides:
draw in class DrawingItem
Parameters:
g2d - 2-D graphics context.


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