mome
Class MoXMIDlet

java.lang.Object
  extended by javax.microedition.midlet.MIDlet
      extended by mome.MoMIDlet
          extended by mome.MoXMIDlet
All Implemented Interfaces:
CommandListener, ItemCommandListener, ItemStateListener, XCommandListener

public abstract class MoXMIDlet
extends MoMIDlet
implements XCommandListener

Class MoXMIDlet is an abstract class. It extends MoMIDlet. Applications that want to use commands execution thread should subclass this class. This Class implements CommandListener, ItemCommandListener, ItemStateListener and XCommandListener. Action methods of LCDUI CommandListeners just push command events (command associated with source on which it has occurred) to commands execution thread. ItemStateListener.itemStateChanged(Item) method uses constant ITEM_STATE_CHANGED as command object. Method XCommandListener.xCommandAction(Object, Object) is the method where the actual command events processing should occur. Implementation of this method in MoXMIDlet does nothing. Subclasses should override this method. It is executed in commands execution thread. This class also introduces a pushCommand(Object, Object) method via which application can push user command events to the commands execution thread. Commands execution thread is of course started when application enters the active state and stopped when application is paused or exits.

Version:
1.0
Author:
Sergio Morozov

Field Summary
static Object ITEM_STATE_CHANGED
          Command passed to xCommandAction method on ItemStateChanged event.
 
Constructor Summary
MoXMIDlet()
           
 
Method Summary
 void commandAction(Command cmd, Displayable src)
          Indicates that command event cmd has occurred on Displayable src.
 void commandAction(Command cmd, Item src)
          Indicates that command event cmd has occurred on Item src.
protected  void destroyApp(boolean unconditional)
          Signals the MIDlet to terminate and enter the Destroyed state.
 Executor getExecutor()
          Returns the Executor associated with this MoxMIDlet instance.
protected  void initApp()
          Initialization method called from startApp.
 void itemStateChanged(Item i)
          Indicates that items state has changed.
protected  void pauseApp()
          Signals the MIDlet to enter the Paused state.
 void pushCommand(Object cmd, Object src)
          Pushes the command event (command associated with object) to the commands execution thread.
protected  void setCommandEventsHeapSize(int commandEventsHeapSize)
          Sets the size of CommandEvents heap of executor.
protected  void startApp()
          Signals the MIDlet that it has entered the Active state.
 void startExecutor()
          Starts the commands execution thread.
 void stopExecutor()
          Stops the commands execution thread.
 void xCommandAction(Object cmd, Object src)
          Indicates that a command event has occurred.
 
Methods inherited from class mome.MoMIDlet
exit, getDisplay, isInitialized
 
Methods inherited from class javax.microedition.midlet.MIDlet
checkPermission, getAppProperty, notifyDestroyed, notifyPaused, platformRequest, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ITEM_STATE_CHANGED

public static final Object ITEM_STATE_CHANGED
Command passed to xCommandAction method on ItemStateChanged event.

Constructor Detail

MoXMIDlet

public MoXMIDlet()
Method Detail

getExecutor

public Executor getExecutor()
Returns the Executor associated with this MoxMIDlet instance. Should not be used for ordinary uses - methods of the MoxMIDlet should be sufficient

Returns:
Executor instance associated with current MIDlet.

initApp

protected void initApp()
                throws MIDletStateChangeException
Initialization method called from startApp. Work that must be done only the first time MIDlet enters the active state should be putted here. This implementation instantiates executor. To have use of command events processing in separate thread, subclasses overriding this method must call the super method.
  protected void initApp() throws MIDletStateChangeException
  {
    ....
  
    super.initApp();
    
    ...
                   
  }
 

Note

As method is called from StartApp: MIDletStateChangeException thrown indicates transient failure; runtime exception - non transient failure. Any exception will prevent setting initialized flag to true. This method is called after Display instance was saved.

Overrides:
initApp in class MoMIDlet
Throws:
MIDletStateChangeException - is thrown if the MIDlet cannot start now but might be able to start at a later time.
See Also:
MoMIDlet.initApp()

setCommandEventsHeapSize

protected void setCommandEventsHeapSize(int commandEventsHeapSize)
Sets the size of CommandEvents heap of executor. This method to take effect should be called in subclasses constructor or at least before the super.initApp().

Parameters:
commandEventsHeapSize - Size of CommandEvents heap in executor

startExecutor

public void startExecutor()
Starts the commands execution thread.


stopExecutor

public void stopExecutor()
Stops the commands execution thread.


startApp

protected void startApp()
                 throws MIDletStateChangeException
Signals the MIDlet that it has entered the Active state. Starts commands execution thread.

Note To maintain the proper invocation of initApp method subclasses overriding this method must call super method before other operations.

  protected void startApp() throws MIDletStateChangeException
  {
    super.startApp();
    
    ...
  }
 

Overrides:
startApp in class MoMIDlet
Throws:
MIDletStateChangeException
See Also:
MIDlet.startApp()

pauseApp

protected void pauseApp()
Signals the MIDlet to enter the Paused state. Stops the commands execution thread. Subclasses that override this method should invoke super method.
  protected void pauseApp()
  {
    ...
    super.pauseApp();
    ...
    
  }
 

Specified by:
pauseApp in class MIDlet
See Also:
MIDlet.pauseApp()

destroyApp

protected void destroyApp(boolean unconditional)
                   throws MIDletStateChangeException
Signals the MIDlet to terminate and enter the Destroyed state. Stops the commands execution thread. Subclasses that override this method should invoke super method.
  protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
  {
    ...
    super.destroyApp(unconditional);
    ...
    
  }
 

Specified by:
destroyApp in class MIDlet
Throws:
MIDletStateChangeException
See Also:
MIDlet.destroyApp(boolean)

pushCommand

public void pushCommand(Object cmd,
                        Object src)
Pushes the command event (command associated with object) to the commands execution thread.

Parameters:
cmd - An object identifying the command. This can be any object.
src - An object associated with command object. Can be Displayable or Item on which this command has occurred or any other object.

commandAction

public void commandAction(Command cmd,
                          Displayable src)
Indicates that command event cmd has occurred on Displayable src. Pushes event to the execution thread. Subclasses overriding this method and still wanted to use execution of commands in separate thread should call super method.

Specified by:
commandAction in interface CommandListener
See Also:
CommandListener.commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)

commandAction

public void commandAction(Command cmd,
                          Item src)
Indicates that command event cmd has occurred on Item src. Pushes event to the execution thread. Subclasses overriding this method and still wanted to use execution of commands in separate thread should call super method.

Specified by:
commandAction in interface ItemCommandListener
See Also:
ItemCommandListener.commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Item)

itemStateChanged

public void itemStateChanged(Item i)
Indicates that items state has changed. Pushes event to the execution thread. ITEM_STATE_CHANGED constant is used as a command in this case. Subclasses overriding this method and still wanted to use execution of commands in separate thread should call super method.

Specified by:
itemStateChanged in interface ItemStateListener
See Also:
ItemStateListener.itemStateChanged(javax.microedition.lcdui.Item)

xCommandAction

public void xCommandAction(Object cmd,
                           Object src)
Indicates that a command event has occurred. This method is invoked in commands execution thread.

Specified by:
xCommandAction in interface XCommandListener
Parameters:
cmd - An object identifying the command. This can be any object. Implementation should test on specific command by identity not equality.
src - An object on which this event has occurred. Either Displayable or Item or can be used as parameter for any user command.
See Also:
XCommandListener.xCommandAction(java.lang.Object, java.lang.Object)