edu.rit.draw.item
Class Rectangle

java.lang.Object
  extended by edu.rit.draw.item.DrawingItem
      extended by edu.rit.draw.item.OutlinedItem
          extended by edu.rit.draw.item.FilledItem
              extended by edu.rit.draw.item.ShapeItem
                  extended by edu.rit.draw.item.RectangularItem
                      extended by edu.rit.draw.item.Rectangle
All Implemented Interfaces:
Externalizable, Serializable

public class Rectangle
extends RectangularItem

Class Rectangle provides a rectangle DrawingItem. The rectangle may have sharp corners or round corners.

If the rectangle has round corners, the round corner distance gives the distance from where the (sharp) corner would normally be to the starting and ending points of the round corner arc, as shown in the adjoining diagram. (The round corner distance is d.) A round corner distance of 0 results in a sharp corner. In a particular rectangle, the same round corner distance is used for every corner; that is, either all the corners are sharp or all the corners are rounded the same amount. Different rectangles can have different round corner distances.

The static defaultSize(), defaultWidth(), defaultHeight(), and defaultRound() methods are provided to set the default size, width, height, and round corner distance. If a rectangle's size, width, height, or round corner distance is not specified, the current default size, width, height, or round corner distance is used.

See Also:
Serialized Form

Field Summary
static double NORMAL_HEIGHT
          The normal height for rectangles (72).
static double NORMAL_ROUND
          The normal round corner distance (0), signifying sharp corners.
static double NORMAL_WIDTH
          The normal width for rectangles (72).
 
Fields inherited from class edu.rit.draw.item.FilledItem
NORMAL_FILL
 
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
 
Constructor Summary
Rectangle()
          Construct a new rectangle.
Rectangle(Rectangle theItem)
          Construct a new rectangle with the same outline, fill paint, location, and size as the given rectangle.
 
Method Summary
 Rectangle add()
          Add this rectangle to the end of the default drawing's sequence of drawing items.
 Rectangle add(Drawing theDrawing)
          Add this rectangle to the end of the given drawing's sequence of drawing items.
 Rectangle addFirst()
          Add this rectangle to the beginning of the default drawing's sequence of drawing items.
 Rectangle addFirst(Drawing theDrawing)
          Add this rectangle to the beginning of the given drawing's sequence of drawing items.
 Rectangle c(double x, double y)
          Set the center point of this rectangle's bounding box.
 Rectangle c(Point thePoint)
          Set the center point of this rectangle's bounding box.
static double defaultHeight()
          Returns the default height for rectangles.
static void defaultHeight(double theHeight)
          Set the default height for rectangles.
static double defaultRound()
          Returns the default round corner distance.
static void defaultRound(double theRound)
          Set the default round corner distance.
static Size defaultSize()
          Returns the default size for rectangles.
static void defaultSize(Size theSize)
          Set the default size for rectangles.
static double defaultWidth()
          Returns the default width for rectangles.
static void defaultWidth(double theWidth)
          Set the default width for rectangles.
 Rectangle e(double x, double y)
          Set the east middle point of this rectangle's bounding box.
 Rectangle e(Point thePoint)
          Set the east middle point of this rectangle's bounding box.
 Rectangle fill(Fill theFill)
          Set this rectangle's fill paint.
 Rectangle height(double theHeight)
          Set the height of this rectangle's bounding box.
 Rectangle n(double x, double y)
          Set the north middle point of this rectangle's bounding box.
 Rectangle n(Point thePoint)
          Set the north middle point of this rectangle's bounding box.
 Rectangle ne(double x, double y)
          Set the northeast corner point of this rectangle's bounding box.
 Rectangle ne(Point thePoint)
          Set the northeast corner point of this rectangle's bounding box.
 Rectangle nw(double x, double y)
          Set the northwest corner point of this rectangle's bounding box.
 Rectangle nw(Point thePoint)
          Set the northwest corner point of this rectangle's bounding box.
 Rectangle outline(Outline theOutline)
          Set this rectangle's outline.
 void readExternal(ObjectInput in)
          Read this rectangle from the given object input stream.
 double round()
          Returns this rectangle's round corner distance.
 Rectangle round(double theRound)
          Set this rectangle's round corner distance.
 Rectangle s(double x, double y)
          Set the south middle point of this rectangle's bounding box.
 Rectangle s(Point thePoint)
          Set the south middle point of this rectangle's bounding box.
 Rectangle se(double x, double y)
          Set the southeast corner point of this rectangle's bounding box.
 Rectangle se(Point thePoint)
          Set the southeast corner point of this rectangle's bounding box.
 Rectangle size(Size theSize)
          Set the size of this rectangle's bounding box.
 Rectangle sw(double x, double y)
          Set the southwest corner point of this rectangle's bounding box.
 Rectangle sw(Point thePoint)
          Set the southwest corner point of this rectangle's bounding box.
 Rectangle w(double x, double y)
          Set the west middle point of this rectangle's bounding box.
 Rectangle w(Point thePoint)
          Set the west middle point of this rectangle's bounding box.
 Rectangle width(double theWidth)
          Set the width of this rectangle's bounding box.
 void writeExternal(ObjectOutput out)
          Write this rectangle to the given object output stream.
 
Methods inherited from class edu.rit.draw.item.RectangularItem
height, nw, width
 
Methods inherited from class edu.rit.draw.item.ShapeItem
draw
 
Methods inherited from class edu.rit.draw.item.FilledItem
defaultFill, defaultFill, fill
 
Methods inherited from class edu.rit.draw.item.OutlinedItem
defaultOutline, defaultOutline, outline
 
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_WIDTH

public static final double NORMAL_WIDTH
The normal width for rectangles (72). Note: 72 points = 1 inch.

See Also:
Constant Field Values

NORMAL_HEIGHT

public static final double NORMAL_HEIGHT
The normal height for rectangles (72). Note: 72 points = 1 inch.

See Also:
Constant Field Values

NORMAL_ROUND

public static final double NORMAL_ROUND
The normal round corner distance (0), signifying sharp corners.

See Also:
Constant Field Values
Constructor Detail

Rectangle

public Rectangle()
Construct a new rectangle. The rectangle's northwest corner is located at (0,0). The rectangle's size is the default size. The rectangle has sharp corners.


Rectangle

public Rectangle(Rectangle theItem)
Construct a new rectangle with the same outline, fill paint, location, and size as the given rectangle.

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

defaultSize

public static Size defaultSize()
Returns the default size for rectangles.

Returns:
Default size.

defaultSize

public static void defaultSize(Size theSize)
Set the default size for rectangles.

Parameters:
theSize - Default size.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if the width or the height of theSize is less than 0.

defaultWidth

public static double defaultWidth()
Returns the default width for rectangles.

Returns:
Default width.

defaultWidth

public static void defaultWidth(double theWidth)
Set the default width for rectangles.

Parameters:
theWidth - Default width.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theWidth is less than 0.

defaultHeight

public static double defaultHeight()
Returns the default height for rectangles.

Returns:
Default height.

defaultHeight

public static void defaultHeight(double theHeight)
Set the default height for rectangles.

Parameters:
theHeight - Default height.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theHeight is less than 0.

defaultRound

public static double defaultRound()
Returns the default round corner distance. A value of 0 signifies sharp corners.

Returns:
Default round corner distance.

defaultRound

public static void defaultRound(double theRound)
Set the default round corner distance. A value of 0 signifies sharp corners. Before calling this method the first time, the default round corner distance is 0.

Parameters:
theRound - Default round corner distance.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theRound is less than 0.

outline

public Rectangle outline(Outline theOutline)
Set this rectangle's outline.

Overrides:
outline in class RectangularItem
Parameters:
theOutline - Outline, or Outline.NONE.
Returns:
This rectangle.

fill

public Rectangle fill(Fill theFill)
Set this rectangle's fill paint.

Overrides:
fill in class RectangularItem
Parameters:
theFill - Fill paint, or Fill.NONE.
Returns:
This rectangle.

size

public Rectangle size(Size theSize)
Set the size of this rectangle's bounding box.

Overrides:
size in class RectangularItem
Parameters:
theSize - Size.
Returns:
This rectangle.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if the width or the height of theSize is less than 0.

width

public Rectangle width(double theWidth)
Set the width of this rectangle's bounding box.

Overrides:
width in class RectangularItem
Parameters:
theWidth - Width.
Returns:
This rectangle.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theWidth is less than 0.

height

public Rectangle height(double theHeight)
Set the height of this rectangle's bounding box.

Overrides:
height in class RectangularItem
Parameters:
theHeight - Height.
Returns:
This rectangle.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theHeight is less than 0.

nw

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

Overrides:
nw in class RectangularItem
Parameters:
x - X coordinate of northwest corner point.
y - Y coordinate of northwest corner point.
Returns:
This rectangle.

nw

public Rectangle nw(Point thePoint)
Set the northwest corner point of this rectangle's bounding box.

Overrides:
nw in class RectangularItem
Parameters:
thePoint - Northwest corner point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

n

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

Overrides:
n in class RectangularItem
Parameters:
x - X coordinate of north middle point.
y - Y coordinate of north middle point.
Returns:
This rectangle.

n

public Rectangle n(Point thePoint)
Set the north middle point of this rectangle's bounding box.

Overrides:
n in class RectangularItem
Parameters:
thePoint - North middle point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

ne

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

Overrides:
ne in class RectangularItem
Parameters:
x - X coordinate of northeast corner point.
y - Y coordinate of northeast corner point.
Returns:
This rectangle.

ne

public Rectangle ne(Point thePoint)
Set the northeast corner point of this rectangle's bounding box.

Overrides:
ne in class RectangularItem
Parameters:
thePoint - Northeast corner point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

w

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

Overrides:
w in class RectangularItem
Parameters:
x - X coordinate of west middle point.
y - Y coordinate of west middle point.
Returns:
This rectangle.

w

public Rectangle w(Point thePoint)
Set the west middle point of this rectangle's bounding box.

Overrides:
w in class RectangularItem
Parameters:
thePoint - West middle point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

c

public Rectangle c(double x,
                   double y)
Set the center point of this rectangle's bounding box.

Overrides:
c in class RectangularItem
Parameters:
x - X coordinate of center point.
y - Y coordinate of center point.
Returns:
This rectangle.

c

public Rectangle c(Point thePoint)
Set the center point of this rectangle's bounding box.

Overrides:
c in class RectangularItem
Parameters:
thePoint - Center point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

e

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

Overrides:
e in class RectangularItem
Parameters:
x - X coordinate of east middle point.
y - Y coordinate of east middle point.
Returns:
This rectangle.

e

public Rectangle e(Point thePoint)
Set the east middle point of this rectangle's bounding box.

Overrides:
e in class RectangularItem
Parameters:
thePoint - East middle point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

sw

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

Overrides:
sw in class RectangularItem
Parameters:
x - X coordinate of southwest corner point.
y - Y coordinate of southwest corner point.
Returns:
This rectangle.

sw

public Rectangle sw(Point thePoint)
Set the southwest corner point of this rectangle's bounding box.

Overrides:
sw in class RectangularItem
Parameters:
thePoint - Southwest corner point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

s

public Rectangle s(double x,
                   double y)
Set the south middle point of this rectangle's bounding box.

Overrides:
s in class RectangularItem
Parameters:
x - X coordinate of south middle point.
y - Y coordinate of south middle point.
Returns:
This rectangle.

s

public Rectangle s(Point thePoint)
Set the south middle point of this rectangle's bounding box.

Overrides:
s in class RectangularItem
Parameters:
thePoint - South middle point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

se

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

Overrides:
se in class RectangularItem
Parameters:
x - X coordinate of southeast corner point.
y - Y coordinate of southeast corner point.
Returns:
This rectangle.

se

public Rectangle se(Point thePoint)
Set the southeast corner point of this rectangle's bounding box.

Overrides:
se in class RectangularItem
Parameters:
thePoint - Southeast corner point.
Returns:
This rectangle.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

round

public double round()
Returns this rectangle's round corner distance. A value of 0 signifies sharp corners.

Returns:
Round corner distance.

round

public Rectangle round(double theRound)
Set this rectangle's round corner distance. A value of 0 signifies sharp corners.

Parameters:
theRound - Round corner distance.
Returns:
This line.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theRound is less than 0.

add

public Rectangle add()
Add this rectangle to the end of the default drawing's sequence of drawing items.

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

add

public Rectangle add(Drawing theDrawing)
Add this rectangle to the end of the given drawing's sequence of drawing items.

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

addFirst

public Rectangle addFirst()
Add this rectangle to the beginning of the default drawing's sequence of drawing items.

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

addFirst

public Rectangle addFirst(Drawing theDrawing)
Add this rectangle to the beginning of the given drawing's sequence of drawing items.

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

writeExternal

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

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class RectangularItem
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 rectangle from the given object input stream.

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


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