if (cmdsToAdd.size() > 0) {  SoftButton menuSB = (SoftButton)sbArray.elementAt(nSoftButtons-1); Command cmd = menuSB.getCommand(); if (cmd != null) { boolean inserted = false; for (int i = 0; i < cmdsToAdd.size(); i++) { if (cmd.getPriority() < ((Command) cmdsToAdd.elementAt(i)).getPriority()) { cmdsToAdd.insertElementAt(cmd, i); inserted = true; break; } } if (inserted == false) {  cmdsToAdd.addElement(cmd); } menuSB.removeCommand(); }
for (int i = 0; i < unmappedCmds.size(); ++i) { ((SoftButton)softButtons.elementAt(i)).setCommand((Command) unmappedCmds.elementAt(i)); }
  public void updateCommands(Vector commands)  {    // Verify that the list is ordered    // Really an assert condition leave till all working    if (commands != null) {      for (int i=0; i<commands.size()-1; i++) {        Command cmda = (Command)commands.elementAt(i);        Command cmdb = (Command)commands.elementAt((i+1));        if (cmda.getPriority() > cmdb.getPriority()) {          System.err.println("Assert: CommandManager.updateCommands commands out of order");        }      }    }    // Count how many soft buttons we have and remove the    // old commands while we are there    Vector devButtons = DeviceFactory.getDevice().getSoftButtons();    Vector sbArray = new Vector(3);    for (int i=0; i<devButtons.size(); i++) {      SoftButton button = (SoftButton) devButtons.elementAt(i);      if (button instanceof SoftButton) {        sbArray.addElement(button);        button.removeCommand();        button.setMenuActivate(false);      }    }           if (commands == null) {      return;    }    int nSoftButtons = sbArray.size();    if (isMenuCommands(commands, nSoftButtons) == true) {      /* Special case if we have our BACK, SELECT commands */      ((SoftButton)sbArray.elementAt(0)).setCommand(BACK_COMMAND);			((SoftButton)sbArray.elementAt(nSoftButtons-1)).setCommand(SELECT_COMMAND);    } else {      Vector cmdsToAdd = (Vector) commands.clone();      // Fill out the most important ones we can      for (int i=0; i < nSoftButtons; i++) {        for (int j = 0; j < cmdsToAdd.size(); j++) {          Command tmpC = (Command) cmdsToAdd.elementAt(j);          if (((SoftButton) sbArray.elementAt(i)).setCommand(tmpC)) {            cmdsToAdd.remove(tmpC);            break;          }        }      }      if (cmdsToAdd.size() > 0) {        /* Menu needed */        SoftButton menuSB = (SoftButton)sbArray.elementAt(nSoftButtons-1);        Command cmd = menuSB.getCommand();        if (cmd != null) {          boolean inserted = false;          for (int i = 0; i < cmdsToAdd.size(); i++) {            if (cmd.getPriority() < ((Command) cmdsToAdd.elementAt(i)).getPriority()) {              cmdsToAdd.insertElementAt(cmd, i);              inserted = true;              break;            }          }          if (inserted == false) {            // Not inserted just place it at the end            cmdsToAdd.addElement(cmd);          }          menuSB.removeCommand();        }        // Now we need a menu for the rest of the items        // Clear the commandList        while (commandList.size() > 0) {          commandList.delete(0);        }        menuCommands.removeAllElements();        for (int i = 0; i < cmdsToAdd.size(); i++) {          Command tmpC = (Command) cmdsToAdd.elementAt(i);          menuCommands.addElement(tmpC);          commandList.append(tmpC.getLabel(), null);        }        // Now set it up to be a menu button, and select button        menuSB.setMenuActivate(true);        menuSB.setCommand(MENU_COMMAND);      }    }  }