uwcse.graphics
Class ShapeImpl

java.lang.Object
  |
  +--uwcse.graphics.ShapeImpl
All Implemented Interfaces:
Shape
Direct Known Subclasses:
CurvedShape, ImageShape, PolyShape, Rectangle, TextShape

public abstract class ShapeImpl
extends java.lang.Object
implements Shape

This is an abstract superclass of all shape objects. All dimensions are in pixels. Shapes are either filled or unfilled. If they are unfilled they are drawn as outlines of the shape. Shapes are always drawn/filled in their color.


Constructor Summary
ShapeImpl(java.awt.Color c, boolean filled)
          A new shaped, possibly filled with the given color.
 
Method Summary
 void addTo(GWindow gw)
          Add the shape to the given graphics window, if non-null.
 uwcse.graphics.InternalGWindow currentWindow()
          Return the window this shape is currently displayed on, or null if not displayed on any window.
 Rectangle getBoundingBox()
          Return the shape's bounding box (the smallest rectangle enclosing the shape).
 int getCenterX()
          Return the X coordinate of the shape's center
 int getCenterY()
          Return the Y coordinate of the shape's center
 java.awt.Color getColor()
          Answer the color of this shape.
 int getHeight()
          Return the height of the shape's bounding box (the smallest rectangle enclosing the shape).
 int getWidth()
          Return the width of the shape's bounding box (the smallest rectangle enclosing the shape).
 int getX()
          Return the X coordinate of the shape's upper-left corner
 int getY()
          Return the Y coordinate of the shape's upper-left corner
 boolean intersects(Shape s)
          Return whether this shape's bounding box intersects with the argument shape's bounding box.
 void moveBy(int deltaX, int deltaY)
          Change this shape's position.
 void moveTo(int x, int y)
          Change this shape's position.
 void recordWindow(uwcse.graphics.InternalGWindow gw)
          Tell the shape that it belongs to the given window.
 void removeFromWindow()
          Remove the shape from its graphics window, if it is added to one.
 void rotateAround(int pivotX, int pivotY, double degrees)
          Rotate the shape around the argument coordinates by the given number of degrees, counter-clockwise.
 void setColor(java.awt.Color c)
          Set the color of this shape.
 java.lang.String toString()
          Answer the printed representation of this shape.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface uwcse.graphics.Shape
paint
 

Constructor Detail

ShapeImpl

public ShapeImpl(java.awt.Color c,
                 boolean filled)
A new shaped, possibly filled with the given color.
Parameters:
c - the color of the shape
filled - whether or not to fill the shape's outline with color
Method Detail

addTo

public void addTo(GWindow gw)
Description copied from interface: Shape
Add the shape to the given graphics window, if non-null.
Specified by:
addTo in interface Shape
Following copied from interface: uwcse.graphics.Shape
Parameters:
gw - the graphics window to add the shape to

currentWindow

public uwcse.graphics.InternalGWindow currentWindow()
Description copied from interface: Shape
Return the window this shape is currently displayed on, or null if not displayed on any window. For internal use only.
Specified by:
currentWindow in interface Shape

getBoundingBox

public Rectangle getBoundingBox()
Description copied from interface: Shape
Return the shape's bounding box (the smallest rectangle enclosing the shape).
Specified by:
getBoundingBox in interface Shape

getCenterX

public int getCenterX()
Description copied from interface: Shape
Return the X coordinate of the shape's center
Specified by:
getCenterX in interface Shape

getCenterY

public int getCenterY()
Description copied from interface: Shape
Return the Y coordinate of the shape's center
Specified by:
getCenterY in interface Shape

getColor

public java.awt.Color getColor()
Description copied from interface: Shape
Answer the color of this shape.
Specified by:
getColor in interface Shape

getHeight

public int getHeight()
Description copied from interface: Shape
Return the height of the shape's bounding box (the smallest rectangle enclosing the shape).
Specified by:
getHeight in interface Shape

getWidth

public int getWidth()
Description copied from interface: Shape
Return the width of the shape's bounding box (the smallest rectangle enclosing the shape).
Specified by:
getWidth in interface Shape

getX

public int getX()
Description copied from interface: Shape
Return the X coordinate of the shape's upper-left corner
Specified by:
getX in interface Shape

getY

public int getY()
Description copied from interface: Shape
Return the Y coordinate of the shape's upper-left corner
Specified by:
getY in interface Shape

intersects

public boolean intersects(Shape s)
Description copied from interface: Shape
Return whether this shape's bounding box intersects with the argument shape's bounding box.
Specified by:
intersects in interface Shape

moveBy

public void moveBy(int deltaX,
                   int deltaY)
Description copied from interface: Shape
Change this shape's position.
Specified by:
moveBy in interface Shape
Following copied from interface: uwcse.graphics.Shape
Parameters:
deltaX - offset in the X direction
deltaY - offset in the Y direction

moveTo

public void moveTo(int x,
                   int y)
Description copied from interface: Shape
Change this shape's position.
Specified by:
moveTo in interface Shape
Following copied from interface: uwcse.graphics.Shape
Parameters:
x - new X coordinate
y - new Y coordinate

recordWindow

public void recordWindow(uwcse.graphics.InternalGWindow gw)
Description copied from interface: Shape
Tell the shape that it belongs to the given window. For internal use only.
Specified by:
recordWindow in interface Shape

removeFromWindow

public void removeFromWindow()
Description copied from interface: Shape
Remove the shape from its graphics window, if it is added to one.
Specified by:
removeFromWindow in interface Shape

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.
Specified by:
rotateAround in interface Shape
Following copied from interface: uwcse.graphics.Shape
Parameters:
pivotX - the X coordinate of the point around which to rotate the shape
pivotY - the Y coordinate of the point around which to rotate the shape
degrees - the angle to rotate by counter-clockwise, in degrees

setColor

public void setColor(java.awt.Color c)
Description copied from interface: Shape
Set the color of this shape.
Specified by:
setColor in interface Shape
Following copied from interface: uwcse.graphics.Shape
Parameters:
c - the new color of the shape

toString

public java.lang.String toString()
Answer the printed representation of this shape.
Overrides:
toString in class java.lang.Object