edu.rit.draw.item
Class Arc

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

public class Arc
extends OutlinedItem
implements Externalizable

Class Arc provides a DrawingItem that is a circular arc. The arc has an outline but no filled interior. The arc is defined by the following attributes:

Angles increase from the positive X axis towards the positive Y axis. Since the positive X axis points to the right and the positive Y axis points down, angles increase in the clockwise direction. (This is the opposite of the usual mathematical convention, where the positive Y axis points upwards.)

The static defaultCenter(), defaultRadius(), defaultStart(), and defaultExtent() methods are provided to set the default center point, radius, starting angle, and angular extent. If the center point, radius, starting angle, or angular extent is not specified, the current default center point, radius, starting angle, or angular extent is used.

See Also:
Serialized Form

Field Summary
static Point NORMAL_CENTER
          The normal center point: (0,0).
static double NORMAL_EXTENT
          The normal angular extent: π/2.
static double NORMAL_RADIUS
          The normal radius: 1.
static double NORMAL_START
          The normal starting angle: 0.
 
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
 
Constructor Summary
Arc()
          Construct a new arc.
Arc(Arc theArc)
          Construct a new arc with the same center point, radius, starting angle, and angular extent as the given arc.
 
Method Summary
 Arc add()
          Add this arc to the end of the default drawing's sequence of drawing items.
 Arc add(Drawing theDrawing)
          Add this arc to the end of the given drawing's sequence of drawing items.
 Arc addFirst()
          Add this arc to the beginning of the default drawing's sequence of drawing items.
 Arc addFirst(Drawing theDrawing)
          Add this arc to the beginning of the given drawing's sequence of drawing items.
 Point center()
          Returns this arc's center point.
 Arc center(Point theCenter)
          Set this arc's center point.
static Point defaultCenter()
          Returns the default center point.
static void defaultCenter(Point theCenter)
          Set the default center point.
static double defaultExtent()
          Returns the default angular extent.
static void defaultExtent(double theExtent)
          Set the default angular extent.
static double defaultRadius()
          Returns the default radius.
static void defaultRadius(double theRadius)
          Set the default radius.
static double defaultStart()
          Returns the default starting angle.
static void defaultStart(double theStart)
          Set the default starting angle.
 void draw(Graphics2D g2d)
          Draw this drawing item in the given graphics context.
 double extent()
          Returns this arc's angular extent.
 Arc extent(double theExtent)
          Set this arc's angular extent.
 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.
 Arc outline(Outline theOutline)
          Set this arc's outline.
 double radius()
          Returns this arc's radius.
 Arc radius(double theRadius)
          Set this arc's radius.
 void readExternal(ObjectInput in)
          Read this arc from the given object input stream.
 Size size()
          Returns the size of this drawing item's bounding box.
 double start()
          Returns this arc's starting angle.
 Arc start(double theStart)
          Set this arc's starting angle.
 double width()
          Returns the width of this drawing item's bounding box.
 void writeExternal(ObjectOutput out)
          Write this arc 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_CENTER

public static final Point NORMAL_CENTER
The normal center point: (0,0).


NORMAL_RADIUS

public static final double NORMAL_RADIUS
The normal radius: 1.

See Also:
Constant Field Values

NORMAL_START

public static final double NORMAL_START
The normal starting angle: 0.

See Also:
Constant Field Values

NORMAL_EXTENT

public static final double NORMAL_EXTENT
The normal angular extent: π/2.

See Also:
Constant Field Values
Constructor Detail

Arc

public Arc()
Construct a new arc. The default center point, radius, starting angle, and angular extent are used.


Arc

public Arc(Arc theArc)
Construct a new arc with the same center point, radius, starting angle, and angular extent as the given arc.

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

defaultCenter

public static Point defaultCenter()
Returns the default center point.

Returns:
Default center point.

defaultCenter

public static void defaultCenter(Point theCenter)
Set the default center point. Before calling this method the first time, the default center point is (0,0).

Parameters:
theCenter - Default center point.
Throws:
NullPointerException - (unchecked exception) Thrown if theCenter is null.

defaultRadius

public static double defaultRadius()
Returns the default radius.

Returns:
Default radius.

defaultRadius

public static void defaultRadius(double theRadius)
Set the default radius. Before calling this method the first time, the default radius is 1.

Parameters:
theRadius - Default radius.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theRadius <= 0.

defaultStart

public static double defaultStart()
Returns the default starting angle.

Returns:
Default starting angle (radians).

defaultStart

public static void defaultStart(double theStart)
Set the default starting angle. Before calling this method the first time, the default starting angle is 0.

Parameters:
theStart - Default starting angle (radians).

defaultExtent

public static double defaultExtent()
Returns the default angular extent.

Returns:
Default angular extent (radians).

defaultExtent

public static void defaultExtent(double theExtent)
Set the default angular extent. Before calling this method the first time, the default angular extent is π/2.

Parameters:
theExtent - Default angular extent (radians).

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 Arc outline(Outline theOutline)
Set this arc's outline.

Overrides:
outline in class OutlinedItem
Parameters:
theOutline - Outline, or Outline.NONE.
Returns:
This arc.

center

public Point center()
Returns this arc's center point.

Returns:
Center point.

center

public Arc center(Point theCenter)
Set this arc's center point.

Parameters:
theCenter - Center point.
Returns:
This arc.
Throws:
NullPointerException - (unchecked exception) Thrown if theCenter is null.

radius

public double radius()
Returns this arc's radius.

Returns:
Radius.

radius

public Arc radius(double theRadius)
Set this arc's radius.

Parameters:
theRadius - Radius.
Returns:
This arc.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theRadius <= 0.

start

public double start()
Returns this arc's starting angle.

Returns:
Starting angle (radians).

start

public Arc start(double theStart)
Set this arc's starting angle.

Parameters:
theStart - Starting angle (radians).
Returns:
This arc.

extent

public double extent()
Returns this arc's angular extent.

Returns:
Angular extent (radians).

extent

public Arc extent(double theExtent)
Set this arc's angular extent.

Parameters:
theExtent - Angular extent (radians).
Returns:
This arc.

add

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

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

add

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

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

addFirst

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

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

addFirst

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

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

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this arc 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 arc 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.