package profilesj2me;

import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.bluetooth.*;

public class MainForm extends Form implements CommandListener {
  TextField actualValue;
  TextField requestedValue;
  StringItem stringItem2;

  public MainForm() {
    super("J2ME Profiles");
    try {
      jbInit();

      addCommand(new Command("Show RoutingTable", Command.ITEM, 1));
      addCommand(new Command("Update profile", Command.ITEM, 1));
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    actualValue = new TextField("", "", 15,TextField.ANY);
    requestedValue = new TextField("", "", 15,TextField.ANY);
    requestedValue.setLabel("Requested value");
    actualValue.setLabel("Actual value");
    setCommandListener(this);

    addCommand(new Command("Exit", Command.EXIT, 1));
    this.append(requestedValue);
    this.append(actualValue);
  }

  public void commandAction(Command command, Displayable displayable) {
    if (command.getCommandType() == Command.EXIT) {
      // stop the MIDlet
      ProfilesJ2ME.quitApp();
    } else {
      if (command.getLabel().equals("Show RoutingTable")) {
        Alert info = new Alert("Routing Table",
                               ProfilesJ2ME.getInstance().getTheDevice().toString(),
                               null,
                               AlertType.INFO);
        info.setTimeout(Alert.FOREVER);
        Display d = Display.getDisplay(ProfilesJ2ME.getInstance());
        d.setCurrent(info, this);
      } else if (command.getLabel().equals("Update profile")) {
        ProfilesJ2ME.getInstance().getProfile()
            .setActualValue(actualValue.getString());
        ProfilesJ2ME.getInstance().getProfile()
            .setRequestedValue(requestedValue.getString());
      }


    }
  }

}
