edu.rit.draw.item
Class Line
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- edu.rit.draw.item.OutlinedItem
-
- edu.rit.draw.item.Line
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Line extends OutlinedItem implements java.io.Externalizable
Class Line provides a DrawingItem that consists of one or more straight line segments. The line may have an Arrow at either or both ends. The line may have sharp corners or round corners. The line has an outline but no filled interior.If the line 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 line, 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 lines can have different round corner distances. 
The static defaultStartArrow(), defaultEndArrow(), and defaultRound() methods are provided to set the default starting arrow, ending arrow, and round corner distance. If the starting arrow, ending arrow, or round corner distance is not specified, the current default starting arrow, ending arrow, or round corner distance is used.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static ArrowNORMAL_END_ARROWThe normal ending arrow: None.static doubleNORMAL_ROUNDThe normal round corner distance (0), signifying sharp corners.static ArrowNORMAL_START_ARROWThe normal starting arrow: None.-
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
-
-
Constructor Summary
Constructors Constructor and Description Line()Construct a new line.Line(Line theLine)Construct a new line with the same points, outline, starting arrow, ending arrow, and round corner distance as the given line.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Lineadd()Add this line to the end of the default drawing's sequence of drawing items.Lineadd(Drawing theDrawing)Add this line to the end of the given drawing's sequence of drawing items.LineaddFirst()Add this line to the beginning of the default drawing's sequence of drawing items.LineaddFirst(Drawing theDrawing)Add this line to the beginning of the given drawing's sequence of drawing items.Lineby(double dx, double dy)Add a line segment to this line.Lineby(Size theSize)Add a line segment to this line.Lineclear()Clear this line.static ArrowdefaultEndArrow()Returns the default ending arrow.static voiddefaultEndArrow(Arrow theArrow)Set the default ending arrow.static doubledefaultRound()Returns the default round corner distance.static voiddefaultRound(double theRound)Set the default round corner distance.static ArrowdefaultStartArrow()Returns the default starting arrow.static voiddefaultStartArrow(Arrow theArrow)Set the default starting arrow.voiddraw(java.awt.Graphics2D g2d)Draw this drawing item in the given graphics context.ArrowendArrow()Returns this line's ending arrow.LineendArrow(Arrow theArrow)Set this line's ending arrow.Linehby(double dx)Add a horizontal line segment to this line.Linehby(Size theSize)Add a horizontal line segment to this line.doubleheight()Returns the height of this drawing item's bounding box.Linehto(double x)Add a horizontal line segment to this line.Linehto(Point thePoint)Add a horizontal line segment to this line.Pointnw()Returns the northwest corner point of this drawing item's bounding box.Lineoutline(Outline theOutline)Set this line's outline.voidreadExternal(java.io.ObjectInput in)Read this line from the given object input stream.doubleround()Returns this line's round corner distance.Lineround(double theRound)Set this line's round corner distance.Sizesize()Returns the size of this drawing item's bounding box.ArrowstartArrow()Returns this line's starting arrow.LinestartArrow(Arrow theArrow)Set this line's starting arrow.Lineto(double x, double y)Add a line segment to this line.Lineto(Point thePoint)Add a line segment to this line.Linevby(double dy)Add a vertical line segment to this line.Linevby(Size theSize)Add a vertical line segment to this line.Linevto(double y)Add a vertical line segment to this line.Linevto(Point thePoint)Add a vertical line segment to this line.doublewidth()Returns the width of this drawing item's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this line to the given object output stream.-
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, sw, w
-
-
-
-
Field Detail
-
NORMAL_START_ARROW
public static final Arrow NORMAL_START_ARROW
The normal starting arrow: None.
-
NORMAL_END_ARROW
public static final Arrow NORMAL_END_ARROW
The normal ending arrow: None.
-
NORMAL_ROUND
public static final double NORMAL_ROUND
The normal round corner distance (0), signifying sharp corners.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Line
public Line()
Construct a new line. The line has no points initially. The default outline, starting arrow, ending arrow, and round corner distance are used.
-
Line
public Line(Line theLine)
Construct a new line with the same points, outline, starting arrow, ending arrow, and round corner distance as the given line.- Parameters:
theLine- Line.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theLine is null.
-
-
Method Detail
-
defaultStartArrow
public static Arrow defaultStartArrow()
Returns the default starting arrow.- Returns:
- Default starting arrow.
-
defaultStartArrow
public static void defaultStartArrow(Arrow theArrow)
Set the default starting arrow. Before calling this method the first time, the default starting arrow is Arrow.NONE.- Parameters:
theArrow- Default starting arrow.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
defaultEndArrow
public static Arrow defaultEndArrow()
Returns the default ending arrow.- Returns:
- Default ending arrow.
-
defaultEndArrow
public static void defaultEndArrow(Arrow theArrow)
Set the default ending arrow. Before calling this method the first time, the default ending arrow is Arrow.NONE.- Parameters:
theArrow- Default ending arrow.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
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.
-
size
public Size size()
Returns the size of this drawing item's bounding box.- Overrides:
sizein classDrawingItem- Returns:
- Size.
-
width
public double width()
Returns the width of this drawing item's bounding box.- Specified by:
widthin classDrawingItem- Returns:
- Width.
-
height
public double height()
Returns the height of this drawing item's bounding box.- Specified by:
heightin classDrawingItem- Returns:
- Height.
-
nw
public Point nw()
Returns the northwest corner point of this drawing item's bounding box.- Specified by:
nwin classDrawingItem- Returns:
- Northwest corner point.
-
outline
public Line outline(Outline theOutline)
Set this line's outline.- Overrides:
outlinein classOutlinedItem- Parameters:
theOutline- Outline, or Outline.NONE.- Returns:
- This line.
-
clear
public Line clear()
Clear this line. All of this point's line segments are removed.- Returns:
- This line.
-
to
public Line to(double x, double y)
Add a line segment to this line. The new endpoint is (x, y). If this line has no line segments, the to() method specifies this line's starting endpoint.- Parameters:
x- Endpoint's X coordinate.y- Endpoint's Y coordinate.- Returns:
- This line.
-
to
public Line to(Point thePoint)
Add a line segment to this line. The new endpoint is thePoint. If this line has no line segments, the to() method specifies this line's starting endpoint.- Parameters:
thePoint- Endpoint.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null.
-
hto
public Line hto(double x)
Add a horizontal line segment to this line. The new endpoint is (x, previous endpoint's Y coordinate).- Parameters:
x- Endpoint's X coordinate.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
hto
public Line hto(Point thePoint)
Add a horizontal line segment to this line. The new endpoint is (thePoint's X coordinate, previous endpoint's Y coordinate).- Parameters:
thePoint- Endpoint.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
-
vto
public Line vto(double y)
Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, y).- Parameters:
y- Endpoint's Y coordinate.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
vto
public Line vto(Point thePoint)
Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, thePoint's Y coordinate).- Parameters:
thePoint- Endpoint.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
-
by
public Line by(double dx, double dy)
Add a line segment to this line. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate + dy).- Parameters:
dx- X distance.dy- Y distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
by
public Line by(Size theSize)
Add a line segment to this line. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate + theSize.height()).- Parameters:
theSize- Distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
hby
public Line hby(double dx)
Add a horizontal line segment to this line. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate).- Parameters:
dx- X distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
hby
public Line hby(Size theSize)
Add a horizontal line segment to this line. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate).- Parameters:
theSize- Distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
vby
public Line vby(double dy)
Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + dy).- Parameters:
dy- Y distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
vby
public Line vby(Size theSize)
Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + theSize.height()).- Parameters:
theSize- Distance.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
startArrow
public Arrow startArrow()
Returns this line's starting arrow.- Returns:
- Starting arrow.
-
startArrow
public Line startArrow(Arrow theArrow)
Set this line's starting arrow.- Parameters:
theArrow- Starting arrow.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
endArrow
public Arrow endArrow()
Returns this line's ending arrow.- Returns:
- Ending arrow.
-
endArrow
public Line endArrow(Arrow theArrow)
Set this line's ending arrow.- Parameters:
theArrow- Ending arrow.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
round
public double round()
Returns this line's round corner distance. A value of 0 signifies sharp corners.- Returns:
- Round corner distance.
-
round
public Line round(double theRound)
Set this line'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 Line add()
Add this line to the end of the default drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
add
public Line add(Drawing theDrawing)
Add this line to the end of the given drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
addFirst
public Line addFirst()
Add this line to the beginning of the default drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
addFirst
public Line addFirst(Drawing theDrawing)
Add this line to the beginning of the given drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this line to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classOutlinedItem- 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 line from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classOutlinedItem- 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 line cannot be found.
-
draw
public void draw(java.awt.Graphics2D g2d)
Draw this drawing 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:
drawin classDrawingItem- Parameters:
g2d- 2-D graphics context.
-
-
DMelt 3.0 © DataMelt by jWork.ORG