uwcse.graphics
Class PolyShape
java.lang.Object
|
+--uwcse.graphics.ShapeImpl
|
+--uwcse.graphics.PolyShape
- All Implemented Interfaces:
- Shape
- Direct Known Subclasses:
- Line, Polygon, Triangle
- public abstract class PolyShape
- extends ShapeImpl
An abstract superclass of various polygonal shapes. A polygon
consisting of N vertices will have N sides. The final side is
drawn between vertex 0 and N-1. The main operations are to add a
new vertex to the polygon (addPoint(...)), to read the x and y
coordinates of the upper-left corner and the center of the bounding
rectangle around the polygon (getX(), getY(), getCenterX(), and
getCenterY()), to change the position of the upper-left corner
(moveBy(...) and moveTo(...)), to rotate the polygon around some
point (rotateAround(...)), to read and change the color of the
polygon (getColor() and setColor(...)), to read and change the
width and height of the polygon (getWidth(), getHeight(), and
resize(...)), and add to and remove from a GWindow (addTo(...) and
removeFromWindow()). Other operations are mainly for internal use,
and should not be called by regular client programs.
Constructor Summary |
PolyShape(java.awt.Color c,
boolean filled)
Create a new polygon of the given color and filledness. |
Method Summary |
void |
addPoint(int x,
int y)
Add a new vertex to the polygon. |
void |
moveTo(int x,
int y)
Move the polygon so that the upper-left corner of its bounding
rectangle is the given coordinates. |
void |
paint(java.awt.Graphics g)
Paint this shape onto the given graphics context. |
void |
resize(int newWidth,
int newHeight)
Change the width and height of the polygon |
void |
rotateAround(int pivotX,
int pivotY,
double degrees)
Rotate the shape around the argument coordinates by the given
number of degrees, counter-clockwise. |
java.lang.String |
toString()
Answer the printed representation of this shape. |
Methods inherited from class uwcse.graphics.ShapeImpl |
addTo, currentWindow, getBoundingBox, getCenterX, getCenterY, getColor, getHeight, getWidth, getX, getY, intersects, moveBy, recordWindow, removeFromWindow, setColor |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
PolyShape
public PolyShape(java.awt.Color c,
boolean filled)
- Create a new polygon of the given color and filledness.
Initially, the polygon has no vertices.
- Parameters:
c
- the color of the polygonfilled
- should it be filled?
addPoint
public void addPoint(int x,
int y)
- Add a new vertex to the polygon.
- Parameters:
x
- the X coordinate of the new vertexy
- the Y coordinate of the new vertex
moveTo
public void moveTo(int x,
int y)
- Move the polygon so that the upper-left corner of its bounding
rectangle is the given coordinates.
- Overrides:
moveTo
in class ShapeImpl
- Parameters:
x
- new X coordinatey
- new Y coordinate
paint
public void paint(java.awt.Graphics g)
- Description copied from interface:
Shape
- Paint this shape onto the given graphics context. For internal
use only.
resize
public void resize(int newWidth,
int newHeight)
- Change the width and height of the polygon
- Parameters:
newWidth
- the new widthnewHeight
- the new height
rotateAround
public void rotateAround(int pivotX,
int pivotY,
double degrees)
- Description copied from interface:
Shape
- Rotate the shape around the argument coordinates by the given
number of degrees, counter-clockwise. For some shapes,
e.g. polygons (including lines and triangles), the shape itself
will rotate as well, but for other shapes (e.g. rectangles,
ovals, arcs, images, and text shapes), the shape itself won't
rotate, only its location will be shifted. Note: for many kinds
of shapes, this method introduces some loss of accuracy of
position, since the position of most shapes is only recorded at
integer coordinates. Use polygons (including lines and
triangles), which remember positions of vertices using doubles,
to avoid these losses of accuracy.
- Overrides:
rotateAround
in class ShapeImpl
- Following copied from interface:
uwcse.graphics.Shape
- Parameters:
pivotX
- the X coordinate of the point around which to
rotate the shapepivotY
- the Y coordinate of the point around which to
rotate the shapedegrees
- the angle to rotate by counter-clockwise, in degrees
toString
public java.lang.String toString()
- Description copied from class:
ShapeImpl
- Answer the printed representation of this shape.
- Overrides:
toString
in class ShapeImpl