edu.rit.draw.item
Class Bow
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- edu.rit.draw.item.OutlinedItem
-
- edu.rit.draw.item.Bow
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Bow extends OutlinedItem implements java.io.Externalizable
Class Bow provides a DrawingItem that joins two points with a curved (bowed) line. The curve is specified by a "curve factor." If the curve factor is positive, the line curves to the right when going from the starting point to the ending point. If the curve factor is negative, the line curves to the left. The larger the magnitude of the curve factor, the farther the line curves. (The curve factor is the tangent of the angle at which the line leaves the starting point and approaches the ending point.) The line may have an Arrow at either or both ends. The line has an outline but no filled interior.The static defaultCurve(), defaultStartArrow(), and defaultEndArrow() methods are provided to set the default curve factor, starting arrow, and ending arrow. If the curve factor, starting arrow, or ending arrow is not specified, the current default curve factor, starting arrow, or ending arrow is used.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleNORMAL_CURVEThe normal curve factor (0.5).static ArrowNORMAL_END_ARROWThe normal ending arrow: None.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 Bow()Construct a new bowed line.Bow(Bow theBow)Construct a bowed line with the same points, outline, starting arrow, ending arrow, and curve factor as the given line.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Bowadd()Add this bowed line to the end of the default drawing's sequence of drawing items.Bowadd(Drawing theDrawing)Add this bowed line to the end of the given drawing's sequence of drawing items.BowaddFirst()Add this bowed line to the beginning of the default drawing's sequence of drawing items.BowaddFirst(Drawing theDrawing)Add this bowed line to the beginning of the given drawing's sequence of drawing items.doublecurve()Returns this bowed line's curve factor.Bowcurve(double theCurve)Set this bowed line's curve factor.static doubledefaultCurve()Returns the default curve factor.static voiddefaultCurve(double theCurve)Set the default curve factor.static ArrowdefaultEndArrow()Returns the default ending arrow.static voiddefaultEndArrow(Arrow theArrow)Set the default ending arrow.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.Pointend()Returns this bowed line's ending point.Bowend(double x, double y)Set this bowed line's ending point.Bowend(Point thePoint)Set this bowed line's ending point.ArrowendArrow()Returns this bowed line's ending arrow.BowendArrow(Arrow theArrow)Set this bowed line's ending arrow.Bowflip()Flip this bowed line from curving right to curving left or vice versa.doubleheight()Returns the height of this drawing item's bounding box.Pointnw()Returns the northwest corner point of this drawing item's bounding box.Bowoutline(Outline theOutline)Set this bowed line's outline.voidreadExternal(java.io.ObjectInput in)Read this bowed line from the given object input stream.Sizesize()Returns the size of this drawing item's bounding box.Pointstart()Returns this bowed line's starting point.Bowstart(double x, double y)Set this bowed line's starting point.Bowstart(Point thePoint)Set this bowed line's starting point.ArrowstartArrow()Returns this bowed line's starting arrow.BowstartArrow(Arrow theArrow)Set this bowed line's starting arrow.doublewidth()Returns the width of this drawing item's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this bowed 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_CURVE
public static final double NORMAL_CURVE
The normal curve factor (0.5).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Bow
public Bow()
Construct a new bowed line. The line has no points initially. The default outline, starting arrow, ending arrow, and curve factor are used.
-
Bow
public Bow(Bow theBow)
Construct a bowed line with the same points, outline, starting arrow, ending arrow, and curve factor as the given line.- Parameters:
theBow- Bowed line.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theBow 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.
-
defaultCurve
public static double defaultCurve()
Returns the default curve factor.- Returns:
- Default curve factor.
-
defaultCurve
public static void defaultCurve(double theCurve)
Set the default curve factor. Before calling this method the first time, the default curve factor is 0.5.- Parameters:
theCurve- Default curve factor.
-
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 Bow outline(Outline theOutline)
Set this bowed line's outline.- Overrides:
outlinein classOutlinedItem- Parameters:
theOutline- Outline, or Outline.NONE.- Returns:
- This bowed line.
-
start
public Point start()
Returns this bowed line's starting point.- Returns:
- Starting point.
-
start
public Bow start(double x, double y)
Set this bowed line's starting point.- Parameters:
x- Starting point X coordinate.y- Starting point Y coordinate.- Returns:
- This bowed line.
-
start
public Bow start(Point thePoint)
Set this bowed line's starting point.- Parameters:
thePoint- Starting point.- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null.
-
end
public Point end()
Returns this bowed line's ending point.- Returns:
- Ending point.
-
end
public Bow end(double x, double y)
Set this bowed line's ending point.- Parameters:
x- Ending point X coordinate.y- Ending point Y coordinate.- Returns:
- This bowed line.
-
end
public Bow end(Point thePoint)
Set this bowed line's ending point.- Parameters:
thePoint- Ending point.- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null.
-
startArrow
public Arrow startArrow()
Returns this bowed line's starting arrow.- Returns:
- Starting arrow.
-
startArrow
public Bow startArrow(Arrow theArrow)
Set this bowed line's starting arrow.- Parameters:
theArrow- Starting arrow.- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
endArrow
public Arrow endArrow()
Returns this bowed line's ending arrow.- Returns:
- Ending arrow.
-
endArrow
public Bow endArrow(Arrow theArrow)
Set this bowed line's ending arrow.- Parameters:
theArrow- Ending arrow.- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArrow is null.
-
curve
public double curve()
Returns this bowed line's curve factor.- Returns:
- Curve factor.
-
curve
public Bow curve(double theCurve)
Set this bowed line's curve factor.- Parameters:
theCurve- Curve factor.- Returns:
- This bowed line.
-
flip
public Bow flip()
Flip this bowed line from curving right to curving left or vice versa.- Returns:
- This bowed line.
-
add
public Bow add()
Add this bowed line to the end of the default drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
add
public Bow add(Drawing theDrawing)
Add this bowed line to the end of the given drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
addFirst
public Bow addFirst()
Add this bowed line to the beginning of the default drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Returns:
- This bowed line.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
addFirst
public Bow addFirst(Drawing theDrawing)
Add this bowed line to the beginning of the given drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This bowed 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 bowed 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 bowed 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