net.kbox
Class ActionController

java.lang.Object
  extended by net.kbox.ActionController
All Implemented Interfaces:
javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemCommandListener

public class ActionController
extends java.lang.Object
implements javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemCommandListener

ActionController provides the "controller" in the Model-View-Controller (MVC) design pattern that is commonly known as "Model 2".

Author:
blackBox

Field Summary
protected static KConfiguration config
          The config used to represent the configuration file.
protected  boolean gcCmdEvent
          The flag representing if need to gc when dealing command event
protected  boolean gcItemEvent
          The flag representing if need to gc when dealing item event
protected  boolean gcKeyEvent
          The flag representing if need to gc when dealing key event
protected  boolean isCacheConfig
          The flag representing if need to cache the configuration file.
 
Constructor Summary
protected ActionController(boolean isCacheConfig)
          Create a new ActionController
 
Method Summary
 void clearCache()
          Clear the configuration cache.
 void commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable display)
          Forward the menu command event.
 void commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Item item)
          Forward the item event.
 ActionForward getActionForward()
          Get an ActionForward object
protected  KConfiguration getConfig()
          Create a KConfiguration.
static ActionController getInstance()
          Create an ActionController(if necessary) without cache configuration data.
static ActionController getInstance(boolean isCacheConfig)
          Create an ActionController(if necessary).
static ActionController getInstance(boolean isCacheConfig, boolean gcCmdEvent, boolean gcKeyEvent, boolean gcItemEvent)
          Create an ActionController(if necessary).
protected  void handleException(java.lang.String msg, ActionForward forward, java.lang.Exception e)
          Handle a Exception, and show it in the mobile phone.
 void keyPressedAction(java.lang.String type, java.lang.String keyName, Unique uniuqe)
          Forward the key pressed event.
 void registerViewer(javax.microedition.midlet.MIDlet midlet)
          Register a Midlet which the result of a action should be forward to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

protected static KConfiguration config
The config used to represent the configuration file.


isCacheConfig

protected boolean isCacheConfig
The flag representing if need to cache the configuration file.


gcCmdEvent

protected boolean gcCmdEvent
The flag representing if need to gc when dealing command event


gcKeyEvent

protected boolean gcKeyEvent
The flag representing if need to gc when dealing key event


gcItemEvent

protected boolean gcItemEvent
The flag representing if need to gc when dealing item event

Constructor Detail

ActionController

protected ActionController(boolean isCacheConfig)
Create a new ActionController

Parameters:
isCacheConfig - if it is true,the configuration data will be cached.
Method Detail

getInstance

public static ActionController getInstance()
Create an ActionController(if necessary) without cache configuration data. Note: this method is the same as getInstance(false).

Returns:
an instance of ActionController.

getInstance

public static ActionController getInstance(boolean isCacheConfig)
Create an ActionController(if necessary).

Parameters:
isCacheConfig - The flag representing if needed to cache the configuration file.
Returns:
an instance of ActionController.

getInstance

public static ActionController getInstance(boolean isCacheConfig,
                                           boolean gcCmdEvent,
                                           boolean gcKeyEvent,
                                           boolean gcItemEvent)
Create an ActionController(if necessary).

Parameters:
isCacheConfig - The flag representing if needed to cache the configuration file.
gcCmdEvent - The flag representing if need to gc when dealing command event
gcKeyEvent - The flag representing if need to gc when dealing key event
gcItemEvent - The flag representing if need to gc when dealing item event
Returns:
a ActionController object

getConfig

protected KConfiguration getConfig()
Create a KConfiguration. If isCacheConfig field is false, it just create and return a KConfiguration; If isCacheConfig field is true, it create, cache and return a KConfiguration.

Returns:
An KConfiguration representing the Configuration file

commandAction

public void commandAction(javax.microedition.lcdui.Command cmd,
                          javax.microedition.lcdui.Displayable display)
Forward the menu command event. The rule of forward base on the kbox.cfg.property file.

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener

keyPressedAction

public void keyPressedAction(java.lang.String type,
                             java.lang.String keyName,
                             Unique uniuqe)
Forward the key pressed event. The rule of forward base on the kbox.cfg.property file.

See Also:
KGameCanvas

commandAction

public void commandAction(javax.microedition.lcdui.Command cmd,
                          javax.microedition.lcdui.Item item)
Forward the item event. The rule of forward base on the kbox.cfg.property file.

Specified by:
commandAction in interface javax.microedition.lcdui.ItemCommandListener

registerViewer

public void registerViewer(javax.microedition.midlet.MIDlet midlet)
Register a Midlet which the result of a action should be forward to.

Parameters:
midlet -

clearCache

public void clearCache()
Clear the configuration cache.


handleException

protected void handleException(java.lang.String msg,
                               ActionForward forward,
                               java.lang.Exception e)
Handle a Exception, and show it in the mobile phone.

Parameters:
msg -
forward -
e -

getActionForward

public ActionForward getActionForward()
Get an ActionForward object

Returns:
an ActionForward object