lt05_pkg
Class PolkaDotDataModel

java.lang.Object
  extended by lt05_pkg.PolkaDotDataModel

public class PolkaDotDataModel
extends java.lang.Object

This class encapsulates a data model of a collection of polka dots. It initializes itself with 6 randomly selected polka dots. Duplicate polka dots are not permitted. Two polka dots are considered duplicate if they have the same centre points.

Author:
mb

Constructor Summary
PolkaDotDataModel()
          Creates a collection and initialized it with three polka dots
 
Method Summary
 boolean addDot(PolkaDot theDot)
          Add the passed polka dot to this collection.
 void addListener(ModelListener listener)
          Add a listener to this model.
 PolkaDot getClosestShape(java.awt.Point p)
          This method returns the polka dot in this model that is closest to the passed point.
 java.util.Set<PolkaDot> getDots()
          Return this collection as a List of PolkaDot objects.
 PolkaDot getMatchingDot(java.awt.Point p)
          This method returns the polka dot in this model that the passed point hits.
 void notifyModelHasChanged()
           
 void setTheColor(PolkaDot p, java.awt.Color c)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolkaDotDataModel

public PolkaDotDataModel()
Creates a collection and initialized it with three polka dots

Method Detail

addListener

public void addListener(ModelListener listener)
Add a listener to this model.

Parameters:
listener -

notifyModelHasChanged

public void notifyModelHasChanged()

getDots

public java.util.Set<PolkaDot> getDots()
Return this collection as a List of PolkaDot objects.

Returns:
as described above

addDot

public boolean addDot(PolkaDot theDot)
Add the passed polka dot to this collection. The model notifies its listeners (if any) that it has changed. As well, a statement is printed to the console "Model is changing." This method will not permit a duplicate polka dot to be added. See the PolkaDot's method equals() to see what constitutes a duplicate.

Parameters:
theDot - a non-null Polka Dot object
Returns:
whether the dot was added or not

getClosestShape

public PolkaDot getClosestShape(java.awt.Point p)
This method returns the polka dot in this model that is closest to the passed point. If this model has no polka dots, this method will return null.

Parameters:
p -
Returns:
as specified above

getMatchingDot

public PolkaDot getMatchingDot(java.awt.Point p)
This method returns the polka dot in this model that the passed point hits. If the passed point does not intersect with any polka dot in this model, then this method returns null. If the passed point intersects with multiple polka dots, then the polka dot with the centre point that is closest to the passed point is selected.

Parameters:
p -
Returns:
the polka dot that is hit, according to the specification above, or null if no polka dot is hit

setTheColor

public void setTheColor(PolkaDot p,
                        java.awt.Color c)