edu.rit.draw.item
Class Rectangle
- java.lang.Object
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.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
Fields Modifier and Type Field and Description static doubleNORMAL_HEIGHTThe normal height for rectangles (72).static doubleNORMAL_ROUNDThe normal round corner distance (0), signifying sharp corners.static doubleNORMAL_WIDTHThe 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
Constructors Constructor and Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Rectangleadd()Add this rectangle to the end of the default drawing's sequence of drawing items.Rectangleadd(Drawing theDrawing)Add this rectangle to the end of the given drawing's sequence of drawing items.RectangleaddFirst()Add this rectangle to the beginning of the default drawing's sequence of drawing items.RectangleaddFirst(Drawing theDrawing)Add this rectangle to the beginning of the given drawing's sequence of drawing items.Rectanglec(double x, double y)Set the center point of this rectangle's bounding box.Rectanglec(Point thePoint)Set the center point of this rectangle's bounding box.static doubledefaultHeight()Returns the default height for rectangles.static voiddefaultHeight(double theHeight)Set the default height for rectangles.static doubledefaultRound()Returns the default round corner distance.static voiddefaultRound(double theRound)Set the default round corner distance.static SizedefaultSize()Returns the default size for rectangles.static voiddefaultSize(Size theSize)Set the default size for rectangles.static doubledefaultWidth()Returns the default width for rectangles.static voiddefaultWidth(double theWidth)Set the default width for rectangles.Rectanglee(double x, double y)Set the east middle point of this rectangle's bounding box.Rectanglee(Point thePoint)Set the east middle point of this rectangle's bounding box.Rectanglefill(Fill theFill)Set this rectangle's fill paint.Rectangleheight(double theHeight)Set the height of this rectangle's bounding box.Rectanglen(double x, double y)Set the north middle point of this rectangle's bounding box.Rectanglen(Point thePoint)Set the north middle point of this rectangle's bounding box.Rectanglene(double x, double y)Set the northeast corner point of this rectangle's bounding box.Rectanglene(Point thePoint)Set the northeast corner point of this rectangle's bounding box.Rectanglenw(double x, double y)Set the northwest corner point of this rectangle's bounding box.Rectanglenw(Point thePoint)Set the northwest corner point of this rectangle's bounding box.Rectangleoutline(Outline theOutline)Set this rectangle's outline.voidreadExternal(java.io.ObjectInput in)Read this rectangle from the given object input stream.doubleround()Returns this rectangle's round corner distance.Rectangleround(double theRound)Set this rectangle's round corner distance.Rectangles(double x, double y)Set the south middle point of this rectangle's bounding box.Rectangles(Point thePoint)Set the south middle point of this rectangle's bounding box.Rectanglese(double x, double y)Set the southeast corner point of this rectangle's bounding box.Rectanglese(Point thePoint)Set the southeast corner point of this rectangle's bounding box.Rectanglesize(Size theSize)Set the size of this rectangle's bounding box.Rectanglesw(double x, double y)Set the southwest corner point of this rectangle's bounding box.Rectanglesw(Point thePoint)Set the southwest corner point of this rectangle's bounding box.Rectanglew(double x, double y)Set the west middle point of this rectangle's bounding box.Rectanglew(Point thePoint)Set the west middle point of this rectangle's bounding box.Rectanglewidth(double theWidth)Set the width of this rectangle's bounding box.voidwriteExternal(java.io.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.FilledItem
defaultFill, defaultFill, fill
-
Methods inherited from class edu.rit.draw.item.OutlinedItem
defaultOutline, defaultOutline, outline
-
-
-
-
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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException- (unchecked exception) Thrown if theRound is less than 0.
-
outline
public Rectangle outline(Outline theOutline)
Set this rectangle's outline.- Overrides:
outlinein classRectangularItem- Parameters:
theOutline- Outline, or Outline.NONE.- Returns:
- This rectangle.
-
fill
public Rectangle fill(Fill theFill)
Set this rectangle's fill paint.- Overrides:
fillin classRectangularItem- 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:
sizein classRectangularItem- Parameters:
theSize- Size.- Returns:
- This rectangle.
- Throws:
java.lang.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:
widthin classRectangularItem- Parameters:
theWidth- Width.- Returns:
- This rectangle.
- Throws:
java.lang.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:
heightin classRectangularItem- Parameters:
theHeight- Height.- Returns:
- This rectangle.
- Throws:
java.lang.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:
nwin classRectangularItem- 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:
nwin classRectangularItem- Parameters:
thePoint- Northwest corner point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
nin classRectangularItem- 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:
nin classRectangularItem- Parameters:
thePoint- North middle point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
nein classRectangularItem- 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:
nein classRectangularItem- Parameters:
thePoint- Northeast corner point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
win classRectangularItem- 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:
win classRectangularItem- Parameters:
thePoint- West middle point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
cin classRectangularItem- 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:
cin classRectangularItem- Parameters:
thePoint- Center point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
ein classRectangularItem- 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:
ein classRectangularItem- Parameters:
thePoint- East middle point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
swin classRectangularItem- 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:
swin classRectangularItem- Parameters:
thePoint- Southwest corner point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
sin classRectangularItem- 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:
sin classRectangularItem- Parameters:
thePoint- South middle point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
sein classRectangularItem- 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:
sein classRectangularItem- Parameters:
thePoint- Southeast corner point.- Returns:
- This rectangle.
- Throws:
java.lang.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:
java.lang.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:
addin classRectangularItem- Returns:
- This rectangle.
- Throws:
java.lang.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:
addin classRectangularItem- Parameters:
theDrawing- Drawing.- Returns:
- This rectangle.
- Throws:
java.lang.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:
addFirstin classRectangularItem- Returns:
- This rectangle.
- Throws:
java.lang.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:
addFirstin classRectangularItem- Parameters:
theDrawing- Drawing.- Returns:
- This rectangle.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this rectangle to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classRectangularItem- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this rectangle from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classRectangularItem- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize this rectangle cannot be found.
-
-
DMelt 3.0 © DataMelt by jWork.ORG