packageForLT06
Class DotModel

java.lang.Object
  extended by packageForLT06.DotModel

public class DotModel
extends java.lang.Object

The class encapsulates a data model that consists of a set of dots. The dots are uniquely identified by an integer index. The first dot's identifier is 0, the second's is 1, and so on until the final dot.

Each dot is understood to have a diameter (of a certain number of units, where the actual physical size of the unit is left unspecified and is abstracted away). Each dot is understood to have a location, which is specified as an x, y coordinate in a two-dimensional plane that has its origin in the upper left corner. A two-dimensional plane of 200x600 units is assumed. Each dot is understood to be associated with a color.

Each dot is randomly assigned a position, diameter and color. The positions are chosen randomly from among the visible positions. The diameters are chosen randomly from among the possible values in the interval [50,100]. The colors are chosen randomly from the colors red, blue, and green.

This model is capable of having listeners installed upon it. Anytime this model changes, the listener's changed() method will be invoked.

Author:
mb

Constructor Summary
DotModel(int numberOfDots)
          Creates a default version of this data model with the specified number of dots.
 
Method Summary
 void addListener(DotModelListener listener)
          Installs the passed listener on this model.
 void changeDiameter(int dotIdentifier, int newDiameter)
          Causes the indicated dot to have a new diameter as specified by the passed value.
 int getClosestDotToPoint(java.awt.Point point)
          Gets the dot that is closest to the specified point, as measured to the dot's center point.
 java.awt.Color getColour(int dotIdentifier)
          Gets the colour that corresponds to the specified dot.
 int getDiameter(int dotIdentifier)
          Gets the diameter of the specified dot.
 java.awt.geom.Ellipse2D getDot(int dotIdentifier)
          Gets the dot that corresponds to the specified dot Identifier.
 int getMaxX()
          Gets the maximum horizontal dimension.
 int getMaxY()
          Gets the maximum vertical dimension.
 int getNumberOfDots()
           
 void nudgeToRight(int dotIdentifier)
          Causes the indicated dot to be nudged to the right by a small amount.
 void setColour(int dotIdentifier, java.awt.Color newColor)
          Sets the colour of the specified dot to the passed color.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DotModel

public DotModel(int numberOfDots)
         throws java.lang.RuntimeException
Creates a default version of this data model with the specified number of dots. Each dot is randomly assigned a position, diameter and color. The positions are chosen randomly from among the visible positions. The diameters are chosen randomly from among the possible values in the interval [50,100]. The colors are chosen randomly from the colors red, blue, and green.

Parameters:
numberOfDots - the number of dots this model should contain. Must be a number between 2 and 10.
Throws:
java.lang.RuntimeException - if the number of dots is invalid
Method Detail

nudgeToRight

public void nudgeToRight(int dotIdentifier)
Causes the indicated dot to be nudged to the right by a small amount. If any listeners are installed on this model, they will be informed that the model has changed.


changeDiameter

public void changeDiameter(int dotIdentifier,
                           int newDiameter)
Causes the indicated dot to have a new diameter as specified by the passed value. The location point of the specified dot will not be changed. If any listeners are installed on this model, they will be informed that the model has changed.


getMaxX

public int getMaxX()
Gets the maximum horizontal dimension.

Returns:

getMaxY

public int getMaxY()
Gets the maximum vertical dimension.

Returns:

addListener

public void addListener(DotModelListener listener)
Installs the passed listener on this model.

Parameters:
listener -

getNumberOfDots

public int getNumberOfDots()

getColour

public java.awt.Color getColour(int dotIdentifier)
                         throws java.lang.RuntimeException
Gets the colour that corresponds to the specified dot.

Parameters:
dotIdentifier - the identifier of the dot
Throws:
java.lang.RuntimeException - if the identifier for the dots is invalid

setColour

public void setColour(int dotIdentifier,
                      java.awt.Color newColor)
               throws java.lang.RuntimeException
Sets the colour of the specified dot to the passed color.

Parameters:
dotIdentifier - the identifier of the dot
Throws:
java.lang.RuntimeException - if the identifier for the dots is invalid

getDiameter

public int getDiameter(int dotIdentifier)
Gets the diameter of the specified dot.

Parameters:
dotIdentifier - the identifier of the dot
Throws:
java.lang.RuntimeException - if the identifier for the dots is invalid

getDot

public java.awt.geom.Ellipse2D getDot(int dotIdentifier)
                               throws java.lang.RuntimeException
Gets the dot that corresponds to the specified dot Identifier.

Parameters:
dotIdentifier - the identifier of the dot
Throws:
java.lang.RuntimeException - if the identifier for the dots is invalid

getClosestDotToPoint

public int getClosestDotToPoint(java.awt.Point point)
Gets the dot that is closest to the specified point, as measured to the dot's center point.

Parameters:
point - the Point