Package coffeedraw
Class FramedPolygon
- java.lang.Object
-
- coffeedraw.ObjectDrawObject
-
- coffeedraw.ObjectDrawShape
-
- coffeedraw.ObjectDrawPolygon
-
- coffeedraw.FramedPolygon
-
- All Implemented Interfaces:
Dependent,Drawable2DInterface,DrawableInterface,LocatableInterface,Resizable2DInterface
public class FramedPolygon extends ObjectDrawPolygon
AFramedPolygonis a polygon, framed with some color. Like other shapes that implement theDrawable2DInterface, its shape is defined by a top left corner, plus a width and height (and a possible rotation). You can specify the number of sides being the first parameter in the constructor.- Author:
- Noah Coetsee (noahcoder77@gmail.com)
-
-
Field Summary
-
Fields inherited from class coffeedraw.ObjectDrawShape
ROTATE_FLAG
-
-
Constructor Summary
Constructors Constructor Description FramedPolygon(int numSides, double x, double y, double width, double height, double rotation, DrawingCanvas canvas)FramedPolygon(int numSides, double x, double y, double width, double height, double rotation, java.awt.Color c, DrawingCanvas canvas)FramedPolygon(int numSides, double x, double y, double width, double height, DrawingCanvas canvas)FramedPolygon(int numSides, Location startLoc, double width, double height, DrawingCanvas canvas)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToCanvas(DrawingCanvas c)Place this object on the specified canvas.booleancontains(Location point)Returntrueif the given location is inside this object,falseotherwise.DrawingCanvasgetCanvas()Return the canvas that this object is on.java.awt.ColorgetColor()Return the color of this objectdoublegetDoubleHeight()Return the height of the rectangle bounding this object, in double precision.doublegetDoubleWidth()Return the height of the rectangle bounding this object, in double precision.doublegetDoubleX()Get this object's x coordinate, in double precision.doublegetDoubleY()Get this object's y coordinate, in double precision.intgetHeight()Return the width of the rectangle bounding this object.LocationgetLocation()Get this object's location.intgetWidth()Return the height of the rectangle bounding this object.intgetX()Get this object's x coordinate.intgetY()Get this object's y coordinate.voidhide()Make this object invisible.booleanisHidden()Returntrueif this object has been rendered invisible with a call to itshide()method,falseif it is still being drawn.java.awt.ShapemakeShape()voidmove(double dx, double dy)Shift (translate) this object left or right by an amountdx, and up or down by an amountdy.voidmoveTo(double x, double y)Move the reference point of this object to the given location.voidmoveTo(Location point)Move the reference point of this object to the given location.booleanoverlaps(Drawable2DInterface other)Returntrueif the rectangle bounding this object overlaps with the rectangle bounding another object;falseotherwise.voidremoveFromCanvas()Remove this object from its canvas.voidsendBackward()Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it.voidsendForward()Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it.voidsendToBack()Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects.voidsendToFront()Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects.voidsetColor(java.awt.Color c)Change the color of this object.voidsetColor(java.awt.Color c, float a)Change the color of this object with an alpha.voidsetHeight(double h)Set the height of this object, leaving its top edge in place and stretching the bottom.voidsetSize(double width, double height)Set the width and height of this object.voidsetWidth(double w)Set the width of this object, leaving its left edge in place and stretching the right.voidshow()Make an object visible again after it had been hidden.java.lang.StringtoString()Return a string describing how this object might be constructed.-
Methods inherited from interface coffeedraw.DrawableInterface
draw, getRotation, getShape, rotate, setRotation
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class coffeedraw.ObjectDrawObject
deferUpdates, depend, runUpdates, undepend
-
Methods inherited from class coffeedraw.ObjectDrawPolygon
getBounds, getPoints, getSides
-
Methods inherited from class coffeedraw.ObjectDrawShape
clearCanvas, draw, draw, draw, getDrawables, getRotation, getShape, internalRotate, removeCanvas, rotate, setMyShape, setRotation, staticRotate, update
-
-
-
-
Constructor Detail
-
FramedPolygon
public FramedPolygon(int numSides, double x, double y, double width, double height, double rotation, java.awt.Color c, DrawingCanvas canvas)
-
FramedPolygon
public FramedPolygon(int numSides, double x, double y, double width, double height, double rotation, DrawingCanvas canvas)
-
FramedPolygon
public FramedPolygon(int numSides, double x, double y, double width, double height, DrawingCanvas canvas)
-
FramedPolygon
public FramedPolygon(int numSides, Location startLoc, double width, double height, DrawingCanvas canvas)
-
-
Method Detail
-
makeShape
public java.awt.Shape makeShape()
- Overrides:
makeShapein classObjectDrawPolygon
-
setSize
public void setSize(double width, double height)Set the width and height of this object. Its upper left corner will stay fixed in place, and the opposite corner will move to make it the new size.- Specified by:
setSizein interfaceResizable2DInterface- Overrides:
setSizein classObjectDrawPolygon- Parameters:
width- new widthheight- new height
-
setWidth
public void setWidth(double w)
Set the width of this object, leaving its left edge in place and stretching the right.- Specified by:
setWidthin interfaceResizable2DInterface- Overrides:
setWidthin classObjectDrawPolygon- Parameters:
w- new width
-
setHeight
public void setHeight(double h)
Set the height of this object, leaving its top edge in place and stretching the bottom.- Specified by:
setHeightin interfaceResizable2DInterface- Overrides:
setHeightin classObjectDrawPolygon- Parameters:
h- new height
-
getX
public int getX()
Get this object's x coordinate.- Specified by:
getXin interfaceLocatableInterface- Overrides:
getXin classObjectDrawPolygon- Returns:
- this object's x coordinate
-
getY
public int getY()
Get this object's y coordinate.- Specified by:
getYin interfaceLocatableInterface- Overrides:
getYin classObjectDrawPolygon- Returns:
- this object's y coordinate
-
getDoubleX
public double getDoubleX()
Get this object's x coordinate, in double precision.- Specified by:
getDoubleXin interfaceLocatableInterface- Overrides:
getDoubleXin classObjectDrawPolygon- Returns:
- this object's x coordinate, in double precision
-
getDoubleY
public double getDoubleY()
Get this object's y coordinate, in double precision.- Specified by:
getDoubleYin interfaceLocatableInterface- Overrides:
getDoubleYin classObjectDrawPolygon- Returns:
- this object's y coordinate, in double precision
-
getLocation
public Location getLocation()
Get this object's location. Translating thisLocationobject will have the same effect as moving the object. So, the following two lines of code are equivalent:object.move(10, 20);
object.getLocation().translate(10, 20);
If you want to create aLocationoffset by some amount from theLocationof this object, without actually moving this object, use theoffset()method inLocation, which creates a newLocation.- Specified by:
getLocationin interfaceLocatableInterface- Overrides:
getLocationin classObjectDrawPolygon- Returns:
- the
Locationof this object.
-
getWidth
public int getWidth()
Return the height of the rectangle bounding this object.- Specified by:
getWidthin interfaceDrawable2DInterface- Overrides:
getWidthin classObjectDrawPolygon- Returns:
- the height of the rectangle bounding this object.
-
getHeight
public int getHeight()
Return the width of the rectangle bounding this object.- Specified by:
getHeightin interfaceDrawable2DInterface- Overrides:
getHeightin classObjectDrawPolygon- Returns:
- the width of the rectangle bounding this object.
-
getDoubleWidth
public double getDoubleWidth()
Return the height of the rectangle bounding this object, in double precision.- Specified by:
getDoubleWidthin interfaceDrawable2DInterface- Overrides:
getDoubleWidthin classObjectDrawPolygon- Returns:
- the height of the rectangle bounding this object, in double precision.
-
getDoubleHeight
public double getDoubleHeight()
Return the height of the rectangle bounding this object, in double precision.- Specified by:
getDoubleHeightin interfaceDrawable2DInterface- Overrides:
getDoubleHeightin classObjectDrawPolygon- Returns:
- the height of the rectangle bounding this object, in double precision.
-
overlaps
public boolean overlaps(Drawable2DInterface other)
Returntrueif the rectangle bounding this object overlaps with the rectangle bounding another object;falseotherwise.- Specified by:
overlapsin interfaceDrawable2DInterface- Overrides:
overlapsin classObjectDrawPolygon- Parameters:
other- another two dimensional object to check for overlapping with- Returns:
- whether the bounding rectangles of the two objects overlap
-
hide
public void hide()
Make this object invisible. It stays in position on its canvas; it is simply not drawn. This method has no effect if the object was already hidden.- Specified by:
hidein interfaceDrawableInterface- Overrides:
hidein classObjectDrawShape
-
show
public void show()
Make an object visible again after it had been hidden. This method has no effect if the object was already visible.- Specified by:
showin interfaceDrawableInterface- Overrides:
showin classObjectDrawShape
-
isHidden
public boolean isHidden()
Returntrueif this object has been rendered invisible with a call to itshide()method,falseif it is still being drawn.- Specified by:
isHiddenin interfaceDrawableInterface- Overrides:
isHiddenin classObjectDrawShape- Returns:
- whether this object is hidden
-
addToCanvas
public void addToCanvas(DrawingCanvas c)
Place this object on the specified canvas. The object will be removed from its current canvas, if it is on a canvas that is not the one it is being moved to. The object will be at the front of the canvas, as if it had just been drawn. If the given canvas isnullthe object is simply removed from its current canvas.- Specified by:
addToCanvasin interfaceDrawableInterface- Overrides:
addToCanvasin classObjectDrawShape- Parameters:
c-DrawingCanvasto place this object on
-
removeFromCanvas
public void removeFromCanvas()
Remove this object from its canvas.- Specified by:
removeFromCanvasin interfaceDrawableInterface- Overrides:
removeFromCanvasin classObjectDrawShape
-
getCanvas
public DrawingCanvas getCanvas()
Return the canvas that this object is on. If it has been removed from its canvas, this method will returnnull.- Specified by:
getCanvasin interfaceDrawableInterface- Overrides:
getCanvasin classObjectDrawShape- Returns:
- the
DrawingCanvasthat this object is on.
-
moveTo
public void moveTo(Location point)
Move the reference point of this object to the given location. For a Drawable2D object, the reference point is the top left corner; for a line, it is the start point.- Specified by:
moveToin interfaceDrawableInterface- Overrides:
moveToin classObjectDrawShape- Parameters:
point-Locationto move to
-
moveTo
public void moveTo(double x, double y)Move the reference point of this object to the given location. For a Drawable2D object, the reference point is the top left corner; for a line, it is the start point.- Specified by:
moveToin interfaceDrawableInterface- Overrides:
moveToin classObjectDrawShape- Parameters:
x- x coordinate to move toy- y coordinate to move to
-
move
public void move(double dx, double dy)Shift (translate) this object left or right by an amountdx, and up or down by an amountdy. A negativedxindicates a shift to the left; a negativedyindicates a shift up- Specified by:
movein interfaceDrawableInterface- Overrides:
movein classObjectDrawShape- Parameters:
dx- amount of x translationdy- amount of y translation
-
getColor
public java.awt.Color getColor()
Return the color of this object- Specified by:
getColorin interfaceDrawableInterface- Overrides:
getColorin classObjectDrawShape- Returns:
- the
Colorof this object
-
setColor
public void setColor(java.awt.Color c)
Change the color of this object.- Specified by:
setColorin interfaceDrawableInterface- Overrides:
setColorin classObjectDrawShape- Parameters:
c- newColorfor this object
-
setColor
public void setColor(java.awt.Color c, float a)Change the color of this object with an alpha.- Overrides:
setColorin classObjectDrawShape- Parameters:
c- newColorfor this objecta- transparency of color.
-
sendForward
public void sendForward()
Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it.- Specified by:
sendForwardin interfaceDrawableInterface- Overrides:
sendForwardin classObjectDrawShape
-
sendBackward
public void sendBackward()
Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it.- Specified by:
sendBackwardin interfaceDrawableInterface- Overrides:
sendBackwardin classObjectDrawShape
-
sendToFront
public void sendToFront()
Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects.- Specified by:
sendToFrontin interfaceDrawableInterface- Overrides:
sendToFrontin classObjectDrawShape
-
sendToBack
public void sendToBack()
Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects.- Specified by:
sendToBackin interfaceDrawableInterface- Overrides:
sendToBackin classObjectDrawShape
-
contains
public boolean contains(Location point)
Returntrueif the given location is inside this object,falseotherwise. BecauseLines andFramedArcs have no "inside", a point is considered to be contained in one of them as long as it is within a few pixels of the line.- Specified by:
containsin interfaceDrawableInterface- Overrides:
containsin classObjectDrawPolygon- Parameters:
point-Locationto test- Returns:
- whether the given location is inside this shape
-
toString
public java.lang.String toString()
Return a string describing how this object might be constructed.- Overrides:
toStringin classObjectDrawObject
-
-