Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

AbstractAppController Class Reference

Inheritance diagram for AbstractAppController:

Inheritance graph
[legend]
Collaboration diagram for AbstractAppController:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

Author:
Author
tvaline
Version:
Revision
1.3
,
Date
2005/05/31 20:10:59

Definition at line 31 of file AbstractAppController.java.

Public Member Functions

 AbstractAppController (AbstractAppModel model, AbstractAppView view, AppOption options[]) throws AppException
 Creates a new AppController object.
final void actionPerformed (ActionEvent evt)
 ActionEvent perform method.
synchronized void addView (AppControllerEventListener view)
 Registers ActionListener to receive events.
abstract ActionEvent processEvent (ActionEvent evt)
 Event processing method.
synchronized void removeView (AppControllerEventListener view)
 Removes ActionListener from the list of listeners.
abstract void startController ()
 This method starts the controller and should perform any application initialization that is required.
String toString ()
 Returns a string representation of this object.

Protected Member Functions

void notifyModel (ActionEvent event)
 Sends notification to update the model.
void notifyViews (ActionEvent event)
 Sends notification to update the views.
synchronized void setModel (AppControllerEventListener model) throws TooManyListenersException
 Registers ActionListener to receive events.

Protected Attributes

transient AppControllerEventListener model = null
 The application model.
AppOption options [] = null
 Command line options.
ThreadFactory pool = Executors.defaultThreadFactory()
 The application thread pool.
transient List< AppControllerEventListenerviews
 The application views.


Constructor & Destructor Documentation

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
Exceptions:
AppException If an error in processing occurs

Definition at line 57 of file AbstractAppController.java.

References AbstractAppController.addView(), AbstractAppController.model, AbstractAppController.options, and AbstractAppController.setModel().

00059                         {
00060     this.options = options;
00061     try {
00062       model.setController(this);
00063       view.setController(this);
00064       setModel(model);
00065       addView(view);
00066     } catch(TooManyListenersException e) {
00067       throw new AppException(e.getMessage());
00068     }
00069   }


Member Function Documentation

final void actionPerformed ActionEvent  evt  ) 
 

ActionEvent perform method.

This method passes events to the processEvent method for dispatch.

Parameters:
evt The event to process

Definition at line 97 of file AbstractAppController.java.

References AbstractAppController.notifyModel(), AbstractAppController.notifyViews(), and AbstractAppController.processEvent().

00097                                                      {
00098     ActionEvent event = processEvent(evt);
00099     notifyModel(event);
00100     notifyViews(event);
00101   }

synchronized void addView AppControllerEventListener  view  ) 
 

Registers ActionListener to receive events.

Parameters:
view The listener to register.

Definition at line 108 of file AbstractAppController.java.

References AbstractAppController.views.

Referenced by AbstractAppController.AbstractAppController().

00108                                                                     {
00109     if(views == null){views = new ArrayList<AppControllerEventListener>();}
00110     views.add(view);
00111   }

void notifyModel ActionEvent  event  )  [protected]
 

Sends notification to update the model.

Parameters:
event The event to send to the model

Definition at line 134 of file AbstractAppController.java.

References AbstractAppController.model, and AbstractAppController.pool.

Referenced by AbstractAppController.actionPerformed().

00134                                                 {
00135     if((model == null) || (event == null)){return;}
00136     final AppControllerEventListener mod = model;
00137     final ActionEvent                evt = event;
00138     pool.newThread(new Runnable() {
00139         public void run(){mod.actionPerformed(evt);}
00140       }).start();
00141   }

void notifyViews ActionEvent  event  )  [protected]
 

Sends notification to update the views.

Parameters:
event The event to send to the views

Definition at line 148 of file AbstractAppController.java.

Referenced by AbstractAppController.actionPerformed().

00148                                                 {
00149     List list;
00150     synchronized(this) {
00151       if((views == null) || (event == null)){return;}
00152       list = (List)((ArrayList)views).clone();
00153     }
00154     final ActionEvent evt = event;
00155     for(int i = 0;i < list.size();i++) {
00156       final AppControllerEventListener view = (AppControllerEventListener)list
00157           .get(i);
00158       pool.newThread(new Runnable() {
00159           public void run(){view.actionPerformed(evt);}
00160         }).start();
00161     }
00162   }

abstract ActionEvent processEvent ActionEvent  evt  )  [pure virtual]
 

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.

Referenced by AbstractAppController.actionPerformed().

synchronized void removeView AppControllerEventListener  view  ) 
 

Removes ActionListener from the list of listeners.

Parameters:
view The listener to remove.

Definition at line 118 of file AbstractAppController.java.

References AbstractAppController.views.

00118                                                                        {
00119     if(views != null){views.remove(view);}
00120   }

synchronized void setModel AppControllerEventListener  model  )  throws TooManyListenersException [protected]
 

Registers ActionListener to receive events.

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

Definition at line 172 of file AbstractAppController.java.

Referenced by AbstractAppController.AbstractAppController().

00173                                      {
00174     if(model == null){this.model = null;}
00175     else {
00176       if(this.model != null){throw new TooManyListenersException();}
00177       this.model = model;
00178     }
00179   }

abstract void startController  )  [pure virtual]
 

This method starts the controller and should perform any application initialization that is required.

This method must be implemented by all subclasses.

Referenced by AbstractApp.run().

String toString  ) 
 

Returns a string representation of this object.

Returns:
The physical address of this instance.

Definition at line 127 of file AbstractAppController.java.

00127 {return super.toString();}


Member Data Documentation

transient AppControllerEventListener model = null [protected]
 

The application model.

Definition at line 34 of file AbstractAppController.java.

Referenced by AbstractAppController.AbstractAppController(), and AbstractAppController.notifyModel().

AppOption options[] = null [protected]
 

Command line options.

Definition at line 37 of file AbstractAppController.java.

Referenced by AbstractAppController.AbstractAppController().

ThreadFactory pool = Executors.defaultThreadFactory() [protected]
 

The application thread pool.

Definition at line 40 of file AbstractAppController.java.

Referenced by AbstractAppController.notifyModel().

transient List<AppControllerEventListener> views [protected]
 

The application views.

Definition at line 43 of file AbstractAppController.java.

Referenced by AbstractAppController.addView(), and AbstractAppController.removeView().


The documentation for this class was generated from the following file:
Generated on Tue Nov 1 23:43:36 2005 for JavaBasicApplicationFrameworkAPI(JBAF) by  doxygen 1.4.2