FileDocCategorySizeDatePackage
SubMenuCommand.javaAPI DocphoneME MR2 API (J2ME)6910Wed May 02 18:00:20 BST 2007com.sun.midp.chameleon

SubMenuCommand

public class SubMenuCommand extends javax.microedition.lcdui.Command
The SubMenuCommand is an extension of LCDUI's Command object. It represents a collection of Commands which should be made available as a type of "sub menu" under a single Command heading.

Fields Summary
protected javax.microedition.lcdui.Command[]
subCommands
An array holding the Commands that are part of the "submenu".
protected javax.microedition.lcdui.CommandListener
listener
The CommandListener to notify when a sub command is selected.
Constructors Summary
public SubMenuCommand(String label, int commandType, int priority)
Creates a new command object with the given short label, type, and priority. The newly created command has no long label. This constructor is identical to Command(label, null, commandType, priority).

param
label the command's short label
param
commandType the command's type
param
priority the command's priority value
throws
NullPointerException if label is null
throws
IllegalArgumentException if the commandType is an invalid type
see
#Command(String, String, int, int)

        super(label, commandType, priority);
    
public SubMenuCommand(String shortLabel, String longLabel, int commandType, int priority)
Creates a new command object with the given labels, type, and priority.

The short label is required and must not be null. The long label is optional and may be null if the command is to have no long label.

param
shortLabel the command's short label
param
longLabel the command's long label, or null if none
param
commandType the command's type
param
priority the command's priority value
throws
NullPointerException if shortLabel is null
throws
IllegalArgumentException if the commandType is an invalid type

        super(shortLabel, longLabel, commandType, priority);
    
Methods Summary
public synchronized voidaddSubCommand(javax.microedition.lcdui.Command cmd)
Adds the given Command to the list of sub commands.

param
cmd The Command to add to the current list of submenu commands
throws
IllegalArgumentException if the given Command is null

        if (cmd == null) {
            throw new IllegalArgumentException("Added command was null");
        }
        
        if (subCommands == null) {
            subCommands = new Command[] { cmd };
        } else {
            Command[] newCommands = new Command[subCommands.length + 1];
            System.arraycopy(subCommands, 0, newCommands, 0, 
                             subCommands.length);
            newCommands[subCommands.length] = cmd;
            subCommands = newCommands;
            newCommands = null;
        }
    
public synchronized voidaddSubCommands(javax.microedition.lcdui.Command[] cmds)
Adds the given set of Commands to the list of sub commands.

param
cmds An array of Commands to add to the current list of submenu commands
throws
IllegalArgumentException if the given array is null

        if (cmds == null) {
            throw new IllegalArgumentException("Added command array was null");
        }
        
        if (subCommands == null) {
            subCommands = new Command[cmds.length];
            System.arraycopy(cmds, 0, subCommands, 0, cmds.length);
        } else {
            Command[] newCommands = 
                new Command[subCommands.length + cmds.length];
            System.arraycopy(subCommands, 0, newCommands, 0, 
                             subCommands.length);
            System.arraycopy(cmds, 0, newCommands, subCommands.length,
                             cmds.length);
            subCommands = newCommands;
            newCommands = null;
        }
    
public synchronized javax.microedition.lcdui.Command[]getSubCommands()
Retrieves the set of subcommands from this SubMenuCommand. This method will return a copy of the internal array holding the set of sub menu Commands.

return
an array holding the set of Commands to be shown on the "submenu" for this SubMenuCommand. 'null' means this SubMenuCommand has no sub commands.

	if (subCommands == null) {
	    return null;
	}

        Command[] cmdCopy = new Command[subCommands.length];
        System.arraycopy(subCommands, 0, cmdCopy, 0, subCommands.length);
        return cmdCopy;
    
public synchronized voidnotifyListener(javax.microedition.lcdui.Command c)
Called to notify the CommandListener of this SubMenuCommand that a sub command has been selected.

param
c the Command that was selected

        if (listener != null) {
            listener.commandAction(c, null);
        }
    
public synchronized voidremoveAll()
Removes all commands that are currently in the list of sub commands.

        subCommands = null;
    
public voidsetListener(javax.microedition.lcdui.CommandListener listener)
Sets the CommandListener of this SubMenuCommand to notify when one of the sub commands is selected.

param
listener the CommandListener to notify when a sub command is selected

        this.listener = listener;