edu.rit.draw.item
Class Bow

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

public class Bow
extends OutlinedItem
implements 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
static double NORMAL_CURVE
          The normal curve factor (0.5).
static Arrow NORMAL_END_ARROW
          The normal ending arrow: None.
static Arrow NORMAL_START_ARROW
          The normal starting arrow: None.
 
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
 
Constructor Summary
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
 Bow add()
          Add this bowed line to the end of the default drawing's sequence of drawing items.
 Bow add(Drawing theDrawing)
          Add this bowed line to the end of the given drawing's sequence of drawing items.
 Bow addFirst()
          Add this bowed line to the beginning of the default drawing's sequence of drawing items.
 Bow addFirst(Drawing theDrawing)
          Add this bowed line to the beginning of the given drawing's sequence of drawing items.
 double curve()
          Returns this bowed line's curve factor.
 Bow curve(double theCurve)
          Set this bowed line's curve factor.
static double defaultCurve()
          Returns the default curve factor.
static void defaultCurve(double theCurve)
          Set the default curve factor.
static Arrow defaultEndArrow()
          Returns the default ending arrow.
static void defaultEndArrow(Arrow theArrow)
          Set the default ending arrow.
static Arrow defaultStartArrow()
          Returns the default starting arrow.
static void defaultStartArrow(Arrow theArrow)
          Set the default starting arrow.
 void draw(Graphics2D g2d)
          Draw this drawing item in the given graphics context.
 Point end()
          Returns this bowed line's ending point.
 Bow end(double x, double y)
          Set this bowed line's ending point.
 Bow end(Point thePoint)
          Set this bowed line's ending point.
 Arrow endArrow()
          Returns this bowed line's ending arrow.
 Bow endArrow(Arrow theArrow)
          Set this bowed line's ending arrow.
 Bow flip()
          Flip this bowed line from curving right to curving left or vice versa.
 double height()
          Returns the height of this drawing item's bounding box.
 Point nw()
          Returns the northwest corner point of this drawing item's bounding box.
 Bow outline(Outline theOutline)
          Set this bowed line's outline.
 void readExternal(ObjectInput in)
          Read this bowed line from the given object input stream.
 Size size()
          Returns the size of this drawing item's bounding box.
 Point start()
          Returns this bowed line's starting point.
 Bow start(double x, double y)
          Set this bowed line's starting point.
 Bow start(Point thePoint)
          Set this bowed line's starting point.
 Arrow startArrow()
          Returns this bowed line's starting arrow.
 Bow startArrow(Arrow theArrow)
          Set this bowed line's starting arrow.
 double width()
          Returns the width of this drawing item's bounding box.
 void writeExternal(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
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:
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:
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:
size in class DrawingItem
Returns:
Size.

width

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

Specified by:
width in class DrawingItem
Returns:
Width.

height

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

Specified by:
height in class DrawingItem
Returns:
Height.

nw

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

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

outline

public Bow outline(Outline theOutline)
Set this bowed line's outline.

Overrides:
outline in class OutlinedItem
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:
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:
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:
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:
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:
add in class OutlinedItem
Returns:
This bowed line.
Throws:
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:
add in class OutlinedItem
Parameters:
theDrawing - Drawing.
Returns:
This bowed line.
Throws:
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:
addFirst in class OutlinedItem
Returns:
This bowed line.
Throws:
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:
addFirst in class OutlinedItem
Parameters:
theDrawing - Drawing.
Returns:
This bowed line.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

writeExternal

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

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

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

draw

public void draw(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:
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.