lt05_pkg
Class PolkaDot

java.lang.Object
  extended by lt05_pkg.PolkaDot
All Implemented Interfaces:
java.lang.Comparable<PolkaDot>

public class PolkaDot
extends java.lang.Object
implements java.lang.Comparable<PolkaDot>

This class encapsulates a polka dot shape, which has a diameter, a color, and a position. It is also understood that a polka dot shape belongs to a PolkaDotDataModel, and that the model should be notified anytime a polka dot's state changes.

Author:
mb

Constructor Summary
PolkaDot(int xPos, int yPos, java.awt.Color col, int diameter, PolkaDotDataModel dataModel)
          Construct a polka dot with the specified attributes.
PolkaDot(java.awt.Point point, java.awt.Color col, int diameter, PolkaDotDataModel dataModel)
          Construct a polka dot with the specified attributes.
 
Method Summary
 int compareTo(PolkaDot otherDot)
           
 boolean contains(java.awt.Point p)
          This method determines whether the passed point is contained within this polka dot
 void decreaseSize()
          Method that decreases the size of this dot by 10%, while maintaining position of centre.
 void drawComponent(java.awt.Graphics2D graphics2D)
          This method causes this polka dot to be drawn on the passed Graphics2D objects.
 boolean equals(java.lang.Object object)
           
 java.awt.Point getCentrePoint()
          This method returns the location of this polka dot, as denoted by the point that represents the centre point of this shape.
 java.awt.Point getLocationOfTopLeftAnchor()
          This method returns the location of this polka dot, as denoted by the point that represents the anchor point (which is the upper left corner of this shape).
static PolkaDot getRandom(int xDim, int yDim, PolkaDotDataModel dataModel)
          This method generates a random polka dot, with a color randomly chosen from within a palette of 6 basic colors (red, orange, yellow, green, blue, magenta).
static java.awt.Color getRandomColor()
          Returns a color randomly chosen from within a palette of 6 basic colors (red, orange, yellow, green, blue, magenta).
 java.awt.Color getTheColor()
          Get the color of this polka dot
 int getTheDiameter()
          Get the diameter of this polka dot
 int hashCode()
           
 void increaseSize()
          Method that increases the size of this dot by 10%, while maintaining position of centre.
 boolean isDuplicate(PolkaDot dot)
          Method that determines whether the passed dot is a duplicate of this dot.
 boolean isFilled()
          Method that indicates whether this polka dot is a shape that is meant to be filled or unfilled
 void setFilled(boolean isFilled)
          Method to specify whether this polka dot should be a filled or unfilled shape.
 void setTheColor(java.awt.Color newColor)
          Specify the color of this Polka Dot and notify that model has changed (only if new color is different than current color).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PolkaDot

public PolkaDot(int xPos,
                int yPos,
                java.awt.Color col,
                int diameter,
                PolkaDotDataModel dataModel)
Construct a polka dot with the specified attributes.

Parameters:
xPos - the x-coordinate of the upper left hand anchor point of the polka dot to be created.
yPos - the y-coordinate of the upper left hand anchor point of the polka dot to be created.
col - the colour of the polka dot to be created.
diameter - the diameter of the polka dot to be created.
dataModel - the PolkaDotDataModel object to which this new polka dot object will belong

PolkaDot

public PolkaDot(java.awt.Point point,
                java.awt.Color col,
                int diameter,
                PolkaDotDataModel dataModel)
Construct a polka dot with the specified attributes.

Parameters:
point - the upper left hand anchor point of the polka dot to be created.
col - the colour of the polka dot to be created.
diameter - the diameter of the polka dot to be created.
dataModel - the PolkaDotDataModel object to which this new polka dot object will belong
Method Detail

setTheColor

public void setTheColor(java.awt.Color newColor)
Specify the color of this Polka Dot and notify that model has changed (only if new color is different than current color).

Parameters:
newColor -

increaseSize

public void increaseSize()
Method that increases the size of this dot by 10%, while maintaining position of centre. Notify that the model has changed


decreaseSize

public void decreaseSize()
Method that decreases the size of this dot by 10%, while maintaining position of centre. Notify that the model has changed


getTheColor

public java.awt.Color getTheColor()
Get the color of this polka dot


getTheDiameter

public int getTheDiameter()
Get the diameter of this polka dot


drawComponent

public void drawComponent(java.awt.Graphics2D graphics2D)
This method causes this polka dot to be drawn on the passed Graphics2D objects.

Parameters:
graphics2D -

getRandom

public static PolkaDot getRandom(int xDim,
                                 int yDim,
                                 PolkaDotDataModel dataModel)
This method generates a random polka dot, with a color randomly chosen from within a palette of 6 basic colors (red, orange, yellow, green, blue, magenta). The position is chosen randomly, but subject to the constraint that the polka dot is drawable within the size of the passed canvas. The diameter is chosen randomly from the interval [20,50]

Parameters:
xDim -
yDim -
dataModel -
Returns:
a new polka dot object, as specified above

getRandomColor

public static java.awt.Color getRandomColor()
Returns a color randomly chosen from within a palette of 6 basic colors (red, orange, yellow, green, blue, magenta).

Returns:
a Color, as specified above

getLocationOfTopLeftAnchor

public java.awt.Point getLocationOfTopLeftAnchor()
This method returns the location of this polka dot, as denoted by the point that represents the anchor point (which is the upper left corner of this shape).

Returns:
as described above

getCentrePoint

public java.awt.Point getCentrePoint()
This method returns the location of this polka dot, as denoted by the point that represents the centre point of this shape.

Returns:
as described above

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

contains

public boolean contains(java.awt.Point p)
This method determines whether the passed point is contained within this polka dot

Parameters:
p -
Returns:
the boolean value as specifed above

isDuplicate

public boolean isDuplicate(PolkaDot dot)
Method that determines whether the passed dot is a duplicate of this dot. A duplicate is any polka dot with the same centre point (even if the diameters are different)

Parameters:
dot -
Returns:
a boolean value, as specified above

isFilled

public boolean isFilled()
Method that indicates whether this polka dot is a shape that is meant to be filled or unfilled

Returns:
a boolean value as specified above

setFilled

public void setFilled(boolean isFilled)
Method to specify whether this polka dot should be a filled or unfilled shape.

Parameters:
isFilled - as described above (true for filled version)

compareTo

public int compareTo(PolkaDot otherDot)
Specified by:
compareTo in interface java.lang.Comparable<PolkaDot>

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object