Constructor and Description |
---|
GPolygon()
Constructs a new empty polygon at the origin.
|
GPolygon(double x,
double y)
Constructs a new empty polygon at (
x , y ). |
GPolygon(GPoint[] points)
Constructs a new polygon from the specified array of
GPoint
objects. |
Modifier and Type | Method and Description |
---|---|
void |
addArc(double arcWidth,
double arcHeight,
double start,
double sweep)
Adds a series of edges to the polygon that simulates the arc specified by the
parameters.
|
void |
addEdge(double dx,
double dy)
Adds an edge to the polygon whose components are given by the displacements
dx and dy from the last vertex. |
void |
addPolarEdge(double r,
double theta)
Adds an edge to the polygon specified in polar coordinates.
|
void |
addVertex(double x,
double y)
Adds a vertex at (
x , y ) relative to the polygon
origin. |
protected void |
clear()
Calling this method deletes all vertices from the polygon and resets the
scale and rotation factors to the their default values.
|
java.lang.Object |
clone()
Overrides
clone in Object to make sure that the
vertex list is copied rather than shared. |
boolean |
contains(double x,
double y)
Checks to see whether a point is inside the object.
|
GRectangle |
getBounds()
Returns the bounding box of this object, which is defined to be the smallest
rectangle that covers everything drawn by the figure.
|
GPoint |
getCurrentPoint()
Returns the coordinates of the last vertex added to the polygon, or
null if the polygon is empty. |
java.awt.Color |
getFillColor()
Returns the color used to display the filled region of this object.
|
protected java.awt.Polygon |
getPolygon()
Returns an AWT
Polygon whose points are as close as possible to
the ones in this GPolygon . |
boolean |
isFilled()
Returns whether this object is filled.
|
protected void |
markAsComplete()
Calling this method makes it illegal to add or remove vertices from the
polygon.
|
void |
paint(java.awt.Graphics g)
Implements the
paint operation for this graphical object. |
void |
recenter()
Recalculates the vertices of the polygon so that they are positioned relative
to the geometric center of the object.
|
protected void |
repaint()
Overrides
repaint in GObject to invalidate the
cached polygon. |
void |
rotate(double theta)
Rotates the polygon around its origin by the angle theta, measured in
degrees.
|
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 polygon by the scale factors
sx and sy . |
void |
setFillColor(java.awt.Color color)
Sets the color used to display the filled region of this object.
|
void |
setFilled(boolean fill)
Sets whether this object is filled.
|
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, move, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
public GPolygon()
public GPolygon(double x, double y)
x
, y
).x
- The x-coordinate of the origin of the polygony
- The y-coordinate of the origin of the polygonpublic GPolygon(GPoint[] points)
GPoint
objects. The polygon is automatically marked as complete.points
- An array of GPoint
objects specifying the verticespublic void addVertex(double x, double y)
x
, y
) relative to the polygon
origin.x
- The x-coordinate of the vertex relative to the polygon originy
- The y-coordinate of the vertex relative to the polygon originpublic void addEdge(double dx, double dy)
dx
and dy
from the last vertex.dx
- The x displacement through which the edge movesdy
- The y displacement through which the edge movespublic final void addPolarEdge(double r, double theta)
r
, and the edge extends in direction
theta
, measured in degrees counterclockwise from the +x axis.r
- The length of the edgetheta
- The angle at which the edge extends measured in degreespublic void addArc(double arcWidth, double arcHeight, double start, double sweep)
arcWidth
- The width of the oval from which the arc is takenarcHeight
- The height of the oval from which the arc is takenstart
- The angle at which the arc beginssweep
- The extent of the arcpublic GPoint getCurrentPoint()
null
if the polygon is empty.null
if emptypublic void scale(double sx, double sy)
sx
and sy
.public final void scale(double sf)
sf
, which
applies in both dimensions.public void rotate(double theta)
theta
- The angle of rotation in degrees counterclockwisepublic void setFilled(boolean fill)
public boolean isFilled()
public void setFillColor(java.awt.Color color)
setFillColor
in interface GFillable
color
- The color used to display the filled region of this objectpublic java.awt.Color getFillColor()
getFillColor
returns the color of the object.getFillColor
in interface GFillable
public GRectangle getBounds()
public boolean contains(double x, double y)
public void paint(java.awt.Graphics g)
paint
operation for this graphical object. This
method is not called directly by clients.public void recenter()
public java.lang.Object clone()
clone
in Object
to make sure that the
vertex list is copied rather than shared.clone
in class java.lang.Object
protected void repaint()
repaint
in GObject
to invalidate the
cached polygon.protected java.awt.Polygon getPolygon()
Polygon
whose points are as close as possible to
the ones in this GPolygon
.protected void markAsComplete()
protected void clear()