Package mome

This package is intended to simplify development of J2ME MIDlets.

See:
          Description

Interface Summary
XCommandListener Inter face XCommandListener is generalization of LCDUI CommandListener interfaces.
 

Class Summary
Executor Executor is a class where actual command events dispatching occurs.
MoMIDlet Class MoMIDlet is base abstract class that extends MIDlet.
MoXMIDlet Class MoXMIDlet is an abstract class.
 

Package mome Description

This package is intended to simplify development of J2ME MIDlets. It introduces commands execution thread. A thread for processing command events. This thread is separate from AMS (Application Management Software) callback thread. So there no need to worry about deadlocks with AMS and timing of callbacks implementations (deadlocks with other part of application are of course still possible). It is also possible to push user commands for processing programmaticaly. Command events are processed serially. A command events queue is maintained, so commands can be activated while another command is processed.

This package abstracts a term “command”. Command here means any object not necessarily LCDUI Command (including it of course). This simplifies definition and usage of commands. Recall commands are tested based on identity not equality. It is possible to push command – source association for processing in commands execution thread. Source in this case can be any object not necessarily LCDUI component on which this command occurred (including it of course). So, it is even possible to push any complementary argument to command.

Note Like with any J2ME library it is recommended to use obfuscator to minimize memory usage.

The use of this package is pretty simple. Developer should subclass MoXMIDlet and override method MoXMIDlet.xCommandAction( Object , Object ). The commands processing should be putted here. Then as usual define needed Commands and instantiate needed components. Set subclass of MoXMIDlet as CommandListener or/and ItemCommandListener or ItemStateListener of above components. Thats all. Method MoXMIDlet.xCommandAction( Object , Object ) will be called serially for each command event in thread separate from AMS callback thread. For example:

  //Define Commands.
    ... 
  private static final Command TEST = new Command("Run", "Run Tests", Command.SCREEN, 32); 
    ...
         
  // Initiate components.
    ...
  Form mainForm = new Form("AppName");
    ...
                    
  // Set this as CommandListener of component.
    ...
  mainForm.setCommandListener( this);
    ...
                 
  // Ovveride XCommandListener xCommandAction( Object cmd, Object src) method.
  public void xCommandAction(Object cmd, Object src)
  { 
    ...
    if (cmd == TEST) 
    {
      this.clearResult(this.suite.countTestCases());
      this.suite.run(this.getTestResult()); 
    } 
    ...
  }
    ...
 

Note For ItemStateChanged events command will be MoXMIDlet.ITEM_STATE_CHANGED and source will be item which state has changed.

It is also possible to process commands in AMS callback thread too. To do this just override action method of respective CommandListener, put commands processing code to be executed in AMS callback thread first and then call super method. For example:

    ...
  public void commandAction(Command cmd, Displayable src)
  {
    ...
    if (cmd == STOP) this.stopThread();
    else if (cmd == START) this.startThread();
    else super.commandAction( cmd, src);
  }
    ...
 

It is also possible to push command events (command - source association) to commands execution thread. Just call MoXMIDlet.pushCommand( Object cmd, Object src) method. Command can be any object and is tested based on identity, so it is easy to define user command like:

  private static final Object FIRE = new Object();
 

Source can also be any object. It needs not be only Displayable or Item on which command has occurred. It can be even complementary argument to command. For example:

in component:

    ...
  protected void keyPressed(int key)
  {
    switch (this.getGameAction(key))
    {
      case Canvas.FIRE:
        this.owner.pushCommand( FIRE, myBook);
        break;
      ...
     }
    ...
  }
 

in MoXMIDlet

    ...
  public void xCommandAction(Object cmd, Object src)
  { 
    if (cmd == FIRE) ((Book) src).burnIt();
    else
      ...
  }
    ...
 

Package consists of three classes and one interface.

Interface XCommandListener

Interface XCommandListener is generalization of LCDUI CommandListener interfaces. It consists of one method

  public void xCommandAction(Object cmd, Object src);
 
Class mome.MoMIDlet

Class MoMIDlet is base abstract class that extends MIDlet. Applications that want to use only base functionality common for almost all MIDlets should extend this class.

Class mome.MoXMIDlet

Class MoXMIDlet is an abstract class. It extends MoMIDlet. Applications that want to use commands execution thread should subclass this class.

Class mome.Executor

Executor is a class where actual command events dispatching occurs. It can be used separately from MoXMIDlet.

Version:
1.0
Author:
Sergio Morozov