talx x1.0.5

talx.controller
Class Controller

java.lang.Object
  extended bytalx.controller.Controller
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, GUIStateConstants

public class Controller
extends java.lang.Object
implements java.awt.event.ActionListener, GUIStateConstants

Determines the state and behaviors of the system.


Field Summary
static java.lang.String LOCK_LOCATION
           
static java.lang.String SAVE_LOCATION
           
 
Fields inherited from interface talx.model.GUIStateConstants
ACTIVE_COMMANDS, ARCHIVE_MESSAGE, CHOICE_DIALOG, COMPOSE_FOCUS, COMPOSE_WINDOW, COMPOSER_CAPTION, COMPOSER_DIRTY, CONFIRM_DIALOG, CURRENT_PEOPLE, CURRENT_PLAYER, DEFAULT_MESSAGE, DIALOG_FOCUS, DIALOG_TEXT, INBOX_FOCUS, INBOX_MAIL_COUNTS, INBOX_MAIL_COUNTS_ANSWERED, INBOX_MAIL_COUNTS_NEW, INBOX_PANEL, INBOX_PLAYER_CAPTIONS, NO_CHANGE, NO_MESSAGE, NO_PEOPLE, NO_PERSON, NO_PLAYER, READER_CAPTION, READER_FOCUS, READER_HEADERS, READER_WINDOW, STATE_ABBR, STATE_CONST, STATE_DESC
 
Constructor Summary
Controller(MailSystemDesktop ms, TransportToolkit tt, GameManager gm, Settings settings, java.lang.String userDir)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ev)
          Performs the given action provided no action is in progress or the action did not originate from a GUI component.
 void addControllerListener(ControllerListener l)
          Adds the specified listener to the controller change and illegal button events.
 void addInterceptor(Interceptor f)
          Adds the specified interceptor to the chain of responsibility.
 void doAction(java.awt.event.ActionEvent ev)
          Queues the given action to be performed.
 void fireControllerChange()
          Broadcasts the current visual state of the application to all listeners.
 ActionHandler getActionHandler()
          Returns the current behavioral state.
 GameLogger getGameLogger()
          Returns the logger that should listen to all games.
 GameManager getGameManager()
          Returns the game manager for the application.
 GUIState getGUIState()
          Returns the current visual state of the application.
 ActionHandler getInitialActionHandler()
          Return the initial action handler specified in the settings.
 TALLogger getLogger(ReceiverFilter instack, SenderFilter outstack)
          Return the TALLogger subclass specified in the settings.
 java.lang.String getRootDirectory()
          Returns the root directory for the current user.
 Settings getSettings()
          Returns the settings for the application.
 TransportToolkit getToolkit()
          Returns the transport toolkit for the application.
 MailSystemDesktop getView()
          Returns the visual component hierarchy.
 void initialize(ReceiverFilter instack, SenderFilter outstack)
          Attempts to restore saved state.
 void removeControllerListener(ControllerListener l)
          Removes the specified listener from the queue for this controller.
 void removeLock()
          Deletes the lock file so that restoreState will read state file.
 void restoreState()
           
 void saveState()
          Saves the current state of the machine.
 void setGUIState(GUIState s)
          Sets the current visual state to the given state.
 void stop()
          Clears any queued actions and stops the action processor thread.
static void sync()
          Hangs until all events in the AWT event queue have been processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SAVE_LOCATION

public static final java.lang.String SAVE_LOCATION
See Also:
Constant Field Values

LOCK_LOCATION

public static final java.lang.String LOCK_LOCATION
See Also:
Constant Field Values
Constructor Detail

Controller

public Controller(MailSystemDesktop ms,
                  TransportToolkit tt,
                  GameManager gm,
                  Settings settings,
                  java.lang.String userDir)
Method Detail

initialize

public void initialize(ReceiverFilter instack,
                       SenderFilter outstack)
Attempts to restore saved state. This method goes through the following steps:
  1. Checks that the lock file is missing
  2. Attempts to load a saved state
  3. If the restored state involved a composition, the draft is located.
  4. If the restored state involved a game, the game is reinstated.
  5. Otherwise, if the user was reading the default message, the initial handler is used with its initial state.
  6. The focusable controls in the restored state are located and made focusable
  7. If any of the preceding fails, the initial handler is used with its initial state.
  8. A lock file is put in place.
  9. The action processor thread is started.

      Throws:
      java.lang.IllegalStateException - if the handler has already been set.
      java.lang.NullPointerException - if the state cannot be restored and the initial handler in the settings is not a legal initial handler class.

stop

public void stop()
Clears any queued actions and stops the action processor thread.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ev)
Performs the given action provided no action is in progress or the action did not originate from a GUI component.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

sync

public static void sync()
Hangs until all events in the AWT event queue have been processed. This method is just a convenience for ActionHandlers so that they do not need to allocate a new empty Thread object each time they want to wait.


addInterceptor

public void addInterceptor(Interceptor f)
Adds the specified interceptor to the chain of responsibility.


addControllerListener

public void addControllerListener(ControllerListener l)
Adds the specified listener to the controller change and illegal button events.


removeControllerListener

public void removeControllerListener(ControllerListener l)
Removes the specified listener from the queue for this controller.


fireControllerChange

public void fireControllerChange()
Broadcasts the current visual state of the application to all listeners.


setGUIState

public void setGUIState(GUIState s)
Sets the current visual state to the given state. This method is public as an implementation side effect, but only ActionHandlers and GameHandlers should change this. Any thread that attempts to this method must own this controller's monitor lock. ActionHandler's handleAction methods automatically receive the controller's monitor lock when called by the controller. GameHandler's handleRemoteAction methods also receive the monitor lock automatically when called from the game manager.


getView

public MailSystemDesktop getView()
Returns the visual component hierarchy.


getGUIState

public GUIState getGUIState()
Returns the current visual state of the application.


getSettings

public Settings getSettings()
Returns the settings for the application.


getToolkit

public TransportToolkit getToolkit()
Returns the transport toolkit for the application.


getGameManager

public GameManager getGameManager()
Returns the game manager for the application.


getGameLogger

public GameLogger getGameLogger()
Returns the logger that should listen to all games. In general, it is the responsiblity of controller classes that handle start games buttons, to make sure that the game logger is logging the game.


getActionHandler

public ActionHandler getActionHandler()
Returns the current behavioral state.


getRootDirectory

public java.lang.String getRootDirectory()
Returns the root directory for the current user.


doAction

public void doAction(java.awt.event.ActionEvent ev)
Queues the given action to be performed. This method allows Interceptors and Handlers to send actions to the queue that might otherwise be filtered if they were sent through the normal action chanel. By having a reference to the controller itself, handlers and interceptors can cause actions to be queued (or requeued) even when the controller is busy and would not have accepted the action had it been delivered to the actionPerformed method.


getInitialActionHandler

public ActionHandler getInitialActionHandler()
Return the initial action handler specified in the settings. If the class cannot be instantiated for some reason , this returns null.


getLogger

public TALLogger getLogger(ReceiverFilter instack,
                           SenderFilter outstack)
Return the TALLogger subclass specified in the settings. If the class cannot be instantiated for some reason, this returns a TALLogger object, and logs the error to LoggerProxy.


saveState

public void saveState()
Saves the current state of the machine. First, a draft of the current composition (if any) is saved. Then the state is serialized and written to SAVE_LOCATION. The file contains:
  1. the current GUIState object
  2. the current ActionHandler object


removeLock

public void removeLock()
Deletes the lock file so that restoreState will read state file. This method should be called just prior to logging off. Failure to call this method before logging off will result in the system being unable to restore it state upon startup.


restoreState

public void restoreState()
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException,
                         javax.mail.MessagingException
Throws:
java.io.IOException
java.lang.ClassNotFoundException
javax.mail.MessagingException

talx x1.0.5

© 2001-2005 University of Oregon.
Eugene OR 97403, U.S.A. All Rights Reserved.