Package coffeedraw

Class FramedPolygon

  • All Implemented Interfaces:
    Dependent, Drawable2DInterface, DrawableInterface, LocatableInterface, Resizable2DInterface

    public class FramedPolygon
    extends ObjectDrawPolygon
    A FramedPolygon is a polygon, framed with some color. Like other shapes that implement the Drawable2DInterface, 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)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addToCanvas​(DrawingCanvas c)
      Place this object on the specified canvas.
      boolean contains​(Location point)
      Return true if the given location is inside this object, false otherwise.
      DrawingCanvas getCanvas()
      Return the canvas that this object is on.
      java.awt.Color getColor()
      Return the color of this object
      double getDoubleHeight()
      Return the height of the rectangle bounding this object, in double precision.
      double getDoubleWidth()
      Return the height of the rectangle bounding this object, in double precision.
      double getDoubleX()
      Get this object's x coordinate, in double precision.
      double getDoubleY()
      Get this object's y coordinate, in double precision.
      int getHeight()
      Return the width of the rectangle bounding this object.
      Location getLocation()
      Get this object's location.
      int getWidth()
      Return the height of the rectangle bounding this object.
      int getX()
      Get this object's x coordinate.
      int getY()
      Get this object's y coordinate.
      void hide()
      Make this object invisible.
      boolean isHidden()
      Return true if this object has been rendered invisible with a call to its hide() method, false if it is still being drawn.
      java.awt.Shape makeShape()  
      void move​(double dx, double dy)
      Shift (translate) this object left or right by an amount dx, and up or down by an amount dy.
      void moveTo​(double x, double y)
      Move the reference point of this object to the given location.
      void moveTo​(Location point)
      Move the reference point of this object to the given location.
      boolean overlaps​(Drawable2DInterface other)
      Return true if the rectangle bounding this object overlaps with the rectangle bounding another object; false otherwise.
      void removeFromCanvas()
      Remove this object from its canvas.
      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.
      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.
      void sendToBack()
      Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects.
      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.
      void setColor​(java.awt.Color c)
      Change the color of this object.
      void setColor​(java.awt.Color c, float a)
      Change the color of this object with an alpha.
      void setHeight​(double h)
      Set the height of this object, leaving its top edge in place and stretching the bottom.
      void setSize​(double width, double height)
      Set the width and height of this object.
      void setWidth​(double w)
      Set the width of this object, leaving its left edge in place and stretching the right.
      void show()
      Make an object visible again after it had been hidden.
      java.lang.String toString()
      Return a string describing how this object might be constructed.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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

      • 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:
        setSize in interface Resizable2DInterface
        Overrides:
        setSize in class ObjectDrawPolygon
        Parameters:
        width - new width
        height - 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:
        setWidth in interface Resizable2DInterface
        Overrides:
        setWidth in class ObjectDrawPolygon
        Parameters:
        w - new width
      • getLocation

        public Location getLocation()
        Get this object's location. Translating this Location object 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 a Location offset by some amount from the Location of this object, without actually moving this object, use the offset() method in Location, which creates a new Location.
        Specified by:
        getLocation in interface LocatableInterface
        Overrides:
        getLocation in class ObjectDrawPolygon
        Returns:
        the Location of this object.
      • getDoubleWidth

        public double getDoubleWidth()
        Return the height of the rectangle bounding this object, in double precision.
        Specified by:
        getDoubleWidth in interface Drawable2DInterface
        Overrides:
        getDoubleWidth in class ObjectDrawPolygon
        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:
        getDoubleHeight in interface Drawable2DInterface
        Overrides:
        getDoubleHeight in class ObjectDrawPolygon
        Returns:
        the height of the rectangle bounding this object, in double precision.
      • overlaps

        public boolean overlaps​(Drawable2DInterface other)
        Return true if the rectangle bounding this object overlaps with the rectangle bounding another object; false otherwise.
        Specified by:
        overlaps in interface Drawable2DInterface
        Overrides:
        overlaps in class ObjectDrawPolygon
        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:
        hide in interface DrawableInterface
        Overrides:
        hide in class ObjectDrawShape
      • 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:
        show in interface DrawableInterface
        Overrides:
        show in class ObjectDrawShape
      • isHidden

        public boolean isHidden()
        Return true if this object has been rendered invisible with a call to its hide() method, false if it is still being drawn.
        Specified by:
        isHidden in interface DrawableInterface
        Overrides:
        isHidden in class ObjectDrawShape
        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 is null the object is simply removed from its current canvas.
        Specified by:
        addToCanvas in interface DrawableInterface
        Overrides:
        addToCanvas in class ObjectDrawShape
        Parameters:
        c - DrawingCanvas to place this object 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:
        moveTo in interface DrawableInterface
        Overrides:
        moveTo in class ObjectDrawShape
        Parameters:
        point - Location to 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:
        moveTo in interface DrawableInterface
        Overrides:
        moveTo in class ObjectDrawShape
        Parameters:
        x - x coordinate to move to
        y - y coordinate to move to
      • move

        public void move​(double dx,
                         double dy)
        Shift (translate) this object left or right by an amount dx, and up or down by an amount dy. A negative dx indicates a shift to the left; a negative dy indicates a shift up
        Specified by:
        move in interface DrawableInterface
        Overrides:
        move in class ObjectDrawShape
        Parameters:
        dx - amount of x translation
        dy - amount of y translation
      • setColor

        public void setColor​(java.awt.Color c,
                             float a)
        Change the color of this object with an alpha.
        Overrides:
        setColor in class ObjectDrawShape
        Parameters:
        c - new Color for this object
        a - transparency of color.
      • contains

        public boolean contains​(Location point)
        Return true if the given location is inside this object, false otherwise. Because Lines and FramedArcs 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:
        contains in interface DrawableInterface
        Overrides:
        contains in class ObjectDrawPolygon
        Parameters:
        point - Location to 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:
        toString in class ObjectDrawObject