if (cmd.getLabel().equals("Select")) { try { throw new IllegalStateException("Select command added"); } catch ( Exception e) { e.printStackTrace(); } }
	public void addCommand(Command cmd) {		//#debug		System.out.println("adding command [" + cmd.getLabel() + "].");		if (cmd.getLabel().equals("Select")) {			try {				throw new IllegalStateException("Select command added");			} catch ( Exception e) {				e.printStackTrace();			}		}		int cmdType = cmd.getCommandType();		//#if polish.Screen.FireTriggersOkCommand == true			if ( cmdType == Command.OK 					&&  (this.okCommand == null || this.okCommand.getPriority() < cmd.getPriority() ) ) 			{				this.okCommand = cmd;			}		//#endif		//#ifdef polish.key.ReturnKey:defined			//#if polish.blackberry			if ( cmdType == Command.BACK || cmdType == Command.CANCEL || 					(cmdType == Command.EXIT && this.backCommand == null) ) 			{							//#else				//# if ( cmd.getCommandType() == Command.BACK ) {			//#endif				this.backCommand = cmd;			}		//#endif		//#ifdef tmp.useExternalMenuBar			this.menuBar.addCommand(cmd);			if (this.isShown()) {				repaint();			}		//#else			if (this.menuCommands == null) {				this.menuCommands = new ArrayList( 6, 50 );				//#style menu, default				 this.menuContainer = new Container( true );			}			if ( (cmdType == Command.BACK || cmdType == Command.CANCEL ) ) 			{				if ( (this.menuSingleRightCommand == null)						|| (cmd.getPriority() < this.menuSingleRightCommand.getPriority())	)				{					// okay set the right menu command:					if (this.menuSingleRightCommand != null) {						// the right menu command is replaced by the new one,						// so insert the original one into the options-menu:						//#style menuitem, menu, default						StringItem menuItem = new StringItem( null, this.menuSingleRightCommand.getLabel(), Item.HYPERLINK );						this.menuContainer.add( menuItem );						if (this.menuContainer.size() == 1) {							this.menuSingleLeftCommand = this.menuSingleRightCommand;						} else {							this.menuSingleLeftCommand = null;						}						this.menuCommands.add( this.menuSingleRightCommand );					}										// this is a command for the right side of the menu:					this.menuSingleRightCommand = cmd;					if (isShown()) {						repaint();					}					return;				}			}			//#style menuitem, menu, default			StringItem menuItem = new StringItem( null, cmd.getLabel(), Item.HYPERLINK );			if ( this.menuCommands.size() == 0 ) {				this.menuCommands.add( cmd );				this.menuContainer.add( menuItem );				this.menuSingleLeftCommand = cmd;			} else {				this.menuSingleLeftCommand = null;				// there are already several commands,				// so add this cmd to the appropriate sorted position:				int priority = cmd.getPriority();				Command[] myCommands = (Command[]) this.menuCommands.toArray( new Command[ this.menuCommands.size() ]);				boolean inserted = false;				for (int i = 0; i < myCommands.length; i++) {					Command command = myCommands[i];					if ( cmd == command ) {						return;					}					if (command.getPriority() > priority ) {						this.menuCommands.add( i, cmd );						this.menuContainer.add(i, menuItem);						inserted = true;						break;					}				}				if (!inserted) {					this.menuCommands.add( cmd );					this.menuContainer.add( menuItem );				}			}//			this.menuContainer.add( menuItem );//			if (this.menuContainer.size() == 1) {//				this.menuSingleLeftCommand = cmd;//			} else {//				this.menuSingleLeftCommand = null;//			}//			this.menuCommands.add( cmd );			if (isShown()) {				repaint();			}		//#endif	}