uwcse.graphics
Interface Shape

All Known Implementing Classes:
CurvedShape, ImageShape, Line, Rectangle, ShapeImpl, TextShape, Triangle

public interface Shape

All shapes implement this interface. The main operations are to read the x and y coordinates of the upper-left corner and the center of the shape (getX(), getY(), getCenterX(), and getCenterY()), to change the position of the shape (moveBy(...) and moveTo(...)), to rotate the position of the shape around some point (rotateAround(...)), to read and change the color of the shape (getColor() and setColor(...)), 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.


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 other)
          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 paint(java.awt.Graphics g)
          Paint this shape onto the given graphics context.
 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.
 

Method Detail

addTo

public void addTo(GWindow gw)
Add the shape to the given graphics window, if non-null.
Parameters:
gw - the graphics window to add the shape to

currentWindow

public uwcse.graphics.InternalGWindow currentWindow()
Return the window this shape is currently displayed on, or null if not displayed on any window. For internal use only.

getBoundingBox

public Rectangle getBoundingBox()
Return the shape's bounding box (the smallest rectangle enclosing the shape).

getCenterX

public int getCenterX()
Return the X coordinate of the shape's center

getCenterY

public int getCenterY()
Return the Y coordinate of the shape's center

getColor

public java.awt.Color getColor()
Answer the color of this shape.

getHeight

public int getHeight()
Return the height of the shape's bounding box (the smallest rectangle enclosing the shape).

getWidth

public int getWidth()
Return the width of the shape's bounding box (the smallest rectangle enclosing the shape).

getX

public int getX()
Return the X coordinate of the shape's upper-left corner

getY

public int getY()
Return the Y coordinate of the shape's upper-left corner

intersects

public boolean intersects(Shape other)
Return whether this shape's bounding box intersects with the argument shape's bounding box.

moveBy

public void moveBy(int deltaX,
                   int deltaY)
Change this shape's position.
Parameters:
deltaX - offset in the X direction
deltaY - offset in the Y direction

moveTo

public void moveTo(int x,
                   int y)
Change this shape's position.
Parameters:
x - new X coordinate
y - new Y coordinate

paint

public void paint(java.awt.Graphics g)
Paint this shape onto the given graphics context. For internal use only.

recordWindow

public void recordWindow(uwcse.graphics.InternalGWindow gw)
Tell the shape that it belongs to the given window. For internal use only.

removeFromWindow

public void removeFromWindow()
Remove the shape from its graphics window, if it is added to one.

rotateAround

public void rotateAround(int pivotX,
                         int pivotY,
                         double degrees)
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.
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)
Set the color of this shape.
Parameters:
c - the new color of the shape