/*
 * LABCommander.java
 *
 * Created on 7 marzo 2007, 9.50
 */

import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class LABCommander
        extends MIDlet
        implements CommandListener {
    
    private TextBox mTextBox;
    private Alert modalAlert, timeAlert;
    private Ticker ticker;
    private Display mDisplay;
    private Command mTOn, mTOff, mModalAlert, mExit;
    
    public LABCommander() {
        mTextBox = new TextBox("TextBox", "LABCommander", 20, TextField.ANY);
        ticker = new Ticker("Hi, I'm a ticker...");
        modalAlert = new Alert("Modal Alert", "This is a Modal Alert.", null, AlertType.INFO);
        timeAlert = new Alert("Exit", "See you...", null, AlertType.INFO);
        
        modalAlert.setTimeout(Alert.FOREVER);
        timeAlert.setTimeout(2000);
        
        mExit = new Command("Exit", Command.EXIT, 0);
        mTOn = new Command("Ticker ON", Command.SCREEN, 1);
        mTOff = new Command("Ticker OFF", Command.SCREEN, 1);
        mModalAlert = new Command("Modal Alert", Command.SCREEN, 1);
        
        mTextBox.addCommand(mExit);
        mTextBox.addCommand(mTOn);
        mTextBox.addCommand(mTOff);
        mTextBox.addCommand(mModalAlert);
        
          
        //timeAlert.setCommandListener(this);
        
        mTextBox.setCommandListener(this);
        timeAlert.setCommandListener(this);
    }
    
    public void startApp() {
        mDisplay = Display.getDisplay(this);
        mDisplay.setCurrent(mTextBox);
    }
    
    public void commandAction(Command c, Displayable s) {
        if (c == mTOn) {
            mTextBox.setTicker(ticker);
        } else if (c == mTOff) {
            mTextBox.setTicker(null);
        } else if (c == mModalAlert) {
            mDisplay.setCurrent(modalAlert, mTextBox);
        } else if (c == mExit) {
           mDisplay.setCurrent(timeAlert, mTextBox);
           //notifyDestroyed(); it does not work!
        } else if (c == Alert.DISMISS_COMMAND & s == timeAlert) {
            notifyDestroyed();
        }
    }
    
    public void pauseApp() {}
    
    public void destroyApp(boolean unconditional) {}
}


