com.ohrasys.app
Class AbstractAppController

java.lang.Object
  extended by com.ohrasys.app.AbstractAppController
All Implemented Interfaces:
AppModelEventListener, AppViewEventListener, java.awt.event.ActionListener, java.util.EventListener

public abstract class AbstractAppController
extends java.lang.Object
implements AppViewEventListener, AppModelEventListener

A basic controller that negotiates the state between a model and one or more views.


Field Summary
protected  AppControllerEventListener model
          The application model
protected  AppOption[] options
          Command line options
protected  java.util.concurrent.ThreadFactory pool
          The application thread pool
protected  java.util.List<AppControllerEventListener> views
          The application views
 
Constructor Summary
AbstractAppController(AbstractAppModel model, AbstractAppView view, AppOption[] options)
          Creates a new AppController object.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          ActionEvent perform method.
 void addView(AppControllerEventListener view)
          Registers ActionListener to receive events.
protected  void notifyModel(java.awt.event.ActionEvent event)
          Sends notification to update the model
protected  void notifyViews(java.awt.event.ActionEvent event)
          Sends notification to update the views
abstract  java.awt.event.ActionEvent processEvent(java.awt.event.ActionEvent evt)
          Event processing method.
 void removeView(AppControllerEventListener view)
          Removes ActionListener from the list of listeners.
protected  void setModel(AppControllerEventListener model)
          Registers ActionListener to receive events.
abstract  void startController()
          This method starts the controller and should perform any application initialization that is required.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

model

protected transient AppControllerEventListener model
The application model


options

protected AppOption[] options
Command line options


pool

protected java.util.concurrent.ThreadFactory pool
The application thread pool


views

protected transient java.util.List<AppControllerEventListener> views
The application views

Constructor Detail

AbstractAppController

public AbstractAppController(AbstractAppModel model,
                             AbstractAppView view,
                             AppOption[] options)
                      throws AppException
Creates a new AppController object. Adds the controller as a listener to both the application model and the application view. Also adds the application model and the application view as event listeners of the controller.

Parameters:
model - The application model to control
view - The application view to control
options - The applications command line options
Throws:
AppException - If an error in processing occurs
Method Detail

processEvent

public abstract java.awt.event.ActionEvent processEvent(java.awt.event.ActionEvent evt)
Event processing method. This method is responsible for handling all events processed by the controller. This method must be implemented by all subclasses.

Parameters:
evt - The event to process.
Returns:
An event sent to update the model and views in response to the received event. This method should return null if no response is required.

startController

public abstract void startController()
This method starts the controller and should perform any application initialization that is required. This method must be implemented by all subclasses.


actionPerformed

public final void actionPerformed(java.awt.event.ActionEvent evt)
ActionEvent perform method. This method passes events to the processEvent method for dispatch.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt - The event to process

addView

public void addView(AppControllerEventListener view)
Registers ActionListener to receive events.

Parameters:
view - The listener to register.

removeView

public void removeView(AppControllerEventListener view)
Removes ActionListener from the list of listeners.

Parameters:
view - The listener to remove.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The physical address of this instance.

notifyModel

protected void notifyModel(java.awt.event.ActionEvent event)
Sends notification to update the model

Parameters:
event - The event to send to the model

notifyViews

protected void notifyViews(java.awt.event.ActionEvent event)
Sends notification to update the views

Parameters:
event - The event to send to the views

setModel

protected void setModel(AppControllerEventListener model)
                 throws java.util.TooManyListenersException
Registers ActionListener to receive events.

Parameters:
model - The listener to register.
Throws:
java.util.TooManyListenersException - If an attempt is made to associate more than one model with this controller.