public class BallModel
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private Dispatcher |
_dispatcher
The dispatcher that updates all the balls.
|
private IPaintStrategyFac |
_errorPaintStrategyFac |
private IUpdateStrategyFac |
_errorUpdateStrategyFac
A factory for a beeping error strategy that beeps the speaker every 25 updates.
|
private int |
_MaxRadius
The maximum radius for a new ball
|
private int |
_MaxSpeed
The maximum speed for a new ball.
|
private java.awt.Rectangle |
_MaxVel
The bounds for the velocity of a new ball
|
private int |
_MinRadius
The minimum radius for a new ball
|
private javax.swing.Timer |
_paintTimer
The timer that controls when the balls are periodically painted.
|
private int |
_paintTimeSlice
The paint time interval between timer ticks, in milliseconds
|
private SwitcherStrategy |
_switcher
The one switcher strategy instance in the system.
|
private javax.swing.Timer |
_updateTimer
The timer that controls when the balls are periodically updated.
|
private int |
_updateTimeSlice
The update time interval between timer ticks, in milliseconds
|
private IRandomizer |
rand
Randomizer utility object, used for random values for new balls
|
private IViewControlAdapter |
viewCtrlAdpt
Adapter to the view for control tasks.
|
private IViewUpdateAdapter |
viewUpdateAdpt
Adapter to the view for updating tasks
|
Constructor and Description |
---|
BallModel(IViewControlAdapter viewCtrlAdpt,
IViewUpdateAdapter viewUpdateAdpt)
Constructor for the model
|
Modifier and Type | Method and Description |
---|---|
void |
clearBalls()
Clear all the ball from the system.
|
IUpdateStrategyFac |
combineStrategyFacs(IUpdateStrategyFac stratFac1,
IUpdateStrategyFac stratFac2)
Returns an IStrategyFac that can instantiate a MultiStrategy with the two
strategies made by the two given IUpdateStrategyFac objects.
|
private java.lang.String |
fixName(java.lang.String folder,
java.lang.Object classname,
java.lang.String append)
Fixes abbreviated, shortened names by adding the
"ballworld.model.strategy." package part of the name and adding a
"Strategy" suffix to the name.
|
SwitcherStrategy |
getSwitcherStrategy()
Getter for the one switcher strategy instance
|
void |
loadBall(IUpdateStrategy updateStrategy,
IPaintStrategy paintStrategy)
Load a ball into the system, where the ball uses the given update strategy instance.
|
IPaintStrategy |
loadPaintStrategy(java.lang.String className)
Uses dynamic class loading to load and instantiate an IUpdateStrategy implementation,
given its class name.
|
IUpdateStrategy |
loadUpdateStrategy(java.lang.String className)
Uses dynamic class loading to load and instantiate an IUpdateStrategy implementation,
given its class name.
|
IPaintStrategyFac |
makePaintStrategyFac(java.lang.String classname)
Returns an IPaintStrategyFac that can instantiate the strategy specified by
classname.
|
IUpdateStrategyFac |
makeUpdateStrategyFac(java.lang.String classname)
Returns an IUpdateStrategyFac that can instantiate the strategy specified by
classname.
|
void |
start()
Start the model, in particular, start the timer.
|
void |
switchSwitcherStrategy(IUpdateStrategy strat)
Change the switcher strategy's decoree to the supplied strategy
|
void |
update(java.lang.Object g)
Update all the balls in the system, passing the given input parameter.
|
private SwitcherStrategy _switcher
private IRandomizer rand
private int _MaxRadius
private int _MinRadius
private int _MaxSpeed
private java.awt.Rectangle _MaxVel
private Dispatcher _dispatcher
private int _paintTimeSlice
private javax.swing.Timer _paintTimer
private int _updateTimeSlice
private javax.swing.Timer _updateTimer
private IViewControlAdapter viewCtrlAdpt
private IViewUpdateAdapter viewUpdateAdpt
private IUpdateStrategyFac _errorUpdateStrategyFac
private IPaintStrategyFac _errorPaintStrategyFac
public BallModel(IViewControlAdapter viewCtrlAdpt, IViewUpdateAdapter viewUpdateAdpt)
viewCtrlAdpt
- The view adapter for control tasksviewUpdateAdpt
- The view adapter for updating taskspublic void loadBall(IUpdateStrategy updateStrategy, IPaintStrategy paintStrategy)
updateStrategy
- An IUpdateStrategy for the new ball to use.paintStrategy
- An IPaintStrategy for the new ball to use.public void start()
public void clearBalls()
public void update(java.lang.Object g)
g
- An input parameter to give to each ball's update method.private java.lang.String fixName(java.lang.String folder, java.lang.Object classname, java.lang.String append)
folder
- TODOclassname
- The abbreviated, shortened nameappend
- TODOpublic IUpdateStrategy loadUpdateStrategy(java.lang.String className)
className
- The fully qualified classname of a strategypublic IPaintStrategy loadPaintStrategy(java.lang.String className)
className
- The fully qualified classname of a strategypublic IUpdateStrategyFac makeUpdateStrategyFac(java.lang.String classname)
classname
- Shortened name of desired strategypublic IUpdateStrategyFac combineStrategyFacs(IUpdateStrategyFac stratFac1, IUpdateStrategyFac stratFac2)
stratFac1
- An IUpdateStrategyFac for a strategystratFac2
- An IUpdateStrategyFac for a strategypublic SwitcherStrategy getSwitcherStrategy()
public void switchSwitcherStrategy(IUpdateStrategy strat)
strat
- the new decoree for the switcherpublic IPaintStrategyFac makePaintStrategyFac(java.lang.String classname)
classname
- Shortened name of desired strategy