acm.graphics
Class GArc

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GArc
All Implemented Interfaces:
GFillable, GScalable, Serializable, Cloneable

public class GArc
extends GObject
implements GFillable, GScalable

The GArc class is a graphical object whose appearance consists of an arc. If unfilled, the arc is simply a portion of the circumference of an ellipse; if filled, the arc is a pie-shaped wedge connected to the center of the figure.

See Also:
Serialized Form

Field Summary
static double ARC_TOLERANCE
          This constant defines how close (measured in pixel units) a point has to be to an arc before that point is considered to be "contained" within the arc.
 
Constructor Summary
GArc(double width, double height, double start, double sweep)
          Creates a new GArc object consisting of an elliptical arc located at the point (0, 0).
GArc(double x, double y, double width, double height, double start, double sweep)
          Creates a new GArc object consisting of an elliptical arc inscribed in a rectangle located at the point (xy) with the specified width and height.
 
Method Summary
 boolean contains(double x, double y)
          Checks to see whether a point is inside the object.
protected  Rectangle getAWTBounds()
          Returns an AWT Rectangle that specifies the bounds of this object.
 GRectangle getBounds()
          Returns the bounding box of the arc.
 GPoint getEndPoint()
          Returns the point at which the arc ends.
 Color getFillColor()
          Returns the color used to display the filled region of this object.
 GRectangle getFrameRectangle()
          Returns the bounds of the GRectangle in which this arc is inscribed.
 double getStartAngle()
          Returns the starting angle for this GArc object.
 GPoint getStartPoint()
          Returns the point at which the arc starts.
 double getSweepAngle()
          Returns the sweep angle for this GArc object.
 boolean isFilled()
          Returns whether this object is filled.
 void paint(Graphics g)
          Implements the paint operation for this graphical object.
 String paramString()
          Returns a string indicating the parameters of this object.
 void scale(double sf)
          Scales the object on the screen by the scale factor sf, which applies in both dimensions.
 void scale(double sx, double sy)
          Scales the object on the screen by the scale factors sx and sy.
 void setFillColor(Color color)
          Sets the color used to display the filled region of this object.
 void setFilled(boolean fill)
          Sets whether this object is filled.
 void setFrameRectangle(double x, double y, double width, double height)
          Changes the arc bounds to the specified values.
 void setFrameRectangle(GRectangle bounds)
          Changes the arc bounds to the values from the specified GRectangle.
 void setStartAngle(double start)
          Sets the starting angle for this GArc object.
 void setSweepAngle(double sweep)
          Sets the sweep angle for this GArc object.
 
Methods inherited from class acm.graphics.GObject
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, move, movePolar, paintObject, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ARC_TOLERANCE

public static final double ARC_TOLERANCE
This constant defines how close (measured in pixel units) a point has to be to an arc before that point is considered to be "contained" within the arc.

See Also:
Constant Field Values
Constructor Detail

GArc

public GArc(double width,
            double height,
            double start,
            double sweep)
Creates a new GArc object consisting of an elliptical arc located at the point (0, 0). For complete descriptions of the other parameters, see the entry for the GArc constructor that includes explicit x and y parameters.

Parameters:
width - The width of the rectangle in which the arc is inscribed
height - The height of the rectangle in which the arc is inscribed
start - The angle at which the arc begins measured in degrees counterclockwise from the +x axis
sweep - The extent of the arc, measured in degrees counterclockwise

GArc

public GArc(double x,
            double y,
            double width,
            double height,
            double start,
            double sweep)
Creates a new GArc object consisting of an elliptical arc inscribed in a rectangle located at the point (xy) with the specified width and height. The start parameter indicates the angle at which the arc begins and is measured in degrees counterclockwise from the +x axis. Thus, a start angle of 0 indicates an arc that begins along the line running eastward from the center (the 3:00 o’clock position), a start angle of 135 begins along the line running northwest, and a start angle of -90 begins along the line running south (the 6:00 o’clock position). The sweep parameter indicates the extent of the arc and is also measured in degrees counterclockwise. A sweep angle of 90 defines a quarter circle extending counterclockwise from the start angle, and a sweep angle of -180 defines a semicircle extending clockwise.

Parameters:
x - The x-coordinate for the rectangle in which the arc is inscribed
y - The y-coordinate for the rectangle in which the arc is inscribed
width - The width of the rectangle in which the arc is inscribed
height - The height of the rectangle in which the arc is inscribed
start - The angle at which the arc begins measured in degrees counterclockwise from the +x axis
sweep - The extent of the arc, measured in degrees counterclockwise
Method Detail

contains

public boolean contains(double x,
                        double y)
Checks to see whether a point is inside the object. For the GArc class, containment depends on whether the arc is filled. Filled arcs are a wedge in which containment can be defined in a natural way; unfilled arcs are essentially lines, which means that containment is defined to mean that the point is within ARC_TOLERANCE pixels of the arc.

Overrides:
contains in class GObject
Parameters:
x - The x-coordinate of the point being tested
y - The y-coordinate of the point being tested
Returns:
true if the point (xy) is inside

getAWTBounds

protected Rectangle getAWTBounds()
Returns an AWT Rectangle that specifies the bounds of this object.

Returns:
A Rectangle that specifies the bounds of this object

getBounds

public GRectangle getBounds()
Returns the bounding box of the arc. Note that this method returns the bounds of the visible portion of the arc and will therefore not contain the same values as specified in setFrameRectangle. To obtain the bounds used to describe the Java arc, use getFrameRectangle.

Specified by:
getBounds in class GObject
Returns:
The bounding box of this object

getEndPoint

public GPoint getEndPoint()
Returns the point at which the arc ends.

Returns:
The point at which the arc ends

getFillColor

public Color getFillColor()
Returns the color used to display the filled region of this object. If none has been set, getFillColor returns the color of the object.

Specified by:
getFillColor in interface GFillable
Returns:
The color used to display the filled region of this object

getFrameRectangle

public GRectangle getFrameRectangle()
Returns the bounds of the GRectangle in which this arc is inscribed. Note that this is usually different from the bounding box returned by getBounds, which returns the bounding box in which the displayed portion of the arc is contained.

Returns:
The GRectangle in which this arc is inscribed

getStartAngle

public double getStartAngle()
Returns the starting angle for this GArc object.

Returns:
The starting angle for this arc

getStartPoint

public GPoint getStartPoint()
Returns the point at which the arc starts.

Returns:
The point at which the arc starts

getSweepAngle

public double getSweepAngle()
Returns the sweep angle for this GArc object.

Returns:
The sweep angle for this arc

isFilled

public boolean isFilled()
Returns whether this object is filled.

Specified by:
isFilled in interface GFillable
Returns:
The color used to display the object

paint

public void paint(Graphics g)
Implements the paint operation for this graphical object. This method is not called directly by clients.

Specified by:
paint in class GObject
Parameters:
g - The graphics context into which the painting is done

paramString

public String paramString()
Returns a string indicating the parameters of this object.

Overrides:
paramString in class GObject

scale

public final void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.

Specified by:
scale in interface GScalable
Parameters:
sf - The factor used to scale all coordinates in both dimensions

scale

public void scale(double sx,
                  double sy)
Scales the object on the screen by the scale factors sx and sy.

Specified by:
scale in interface GScalable
Parameters:
sx - The factor used to scale all coordinates in the x direction
sy - The factor used to scale all coordinates in the y direction

setFillColor

public void setFillColor(Color color)
Sets the color used to display the filled region of this object.

Specified by:
setFillColor in interface GFillable
Parameters:
color - The color used to display the filled region of this object

setFilled

public void setFilled(boolean fill)
Sets whether this object is filled.

Specified by:
setFilled in interface GFillable
Parameters:
fill - true if the object should be filled, false for an outline

setFrameRectangle

public void setFrameRectangle(double x,
                              double y,
                              double width,
                              double height)
Changes the arc bounds to the specified values.

Parameters:
x - The x-coordinate for the rectangle in which the arc is inscribed
y - The y-coordinate for the rectangle in which the arc is inscribed
width - The width of the rectangle in which the arc is inscribed
height - The height of the rectangle in which the arc is inscribed

setFrameRectangle

public final void setFrameRectangle(GRectangle bounds)
Changes the arc bounds to the values from the specified GRectangle.

Parameters:
bounds - A GRectangle specifying the new arc bounds

setStartAngle

public void setStartAngle(double start)
Sets the starting angle for this GArc object.

Parameters:
start - The new starting angle

setSweepAngle

public void setSweepAngle(double sweep)
Sets the sweep angle for this GArc object.

Parameters:
sweep - The new sweep angle