Just An Application

June 25, 2009

What’s New In MIDP 3.0 ? Part 19: LCDUI – Commands

Filed under: Java, JME, LCDUI, MIDP, MIDP3, MIDP3LCDUI — Tags: , , , , , — Simon Lewis @ 7:43 pm

1. Changes To The Command Class

  • Commands are partially mutable. It is possible to set a Command’s

    • label
    • long label
  • A Command can have an associated Image which can be used in conjunction with the label. The implementation can choose to ignore the Image.

  • A Command can have an associated Font. If a Command has a Font it may be used to render the Command’s text, but an implementation may choose to ignore it.

  • A Command can be disabled or enabled. If a Command is disabled then it is not available to the user and its appearance will reflect this.

2. New Functionality

2.1 Constructing A Command With An Image

A Command can be constructed with an image using the

    public Command(
               String shortLabel,
               String longLabel,
               Image  image,
               int    commandType,
               int    priority)

constructor.

The image argument may be immutable or mutable. If the Image is mutable then as is conventional an immutable copy will be used.

The other arguments are the same as for the existing constructors.

2.2 Disabling And Enabling A Command

A Command can be disabled/enabled by calling it’s

    public void setEnabled(boolean enabled)

method with an argument of false/true respectively.

2.3 Is A Command Enabled ?

Whether a Command is enabled can be determined by calling it’s

    public boolean getEnabled()

method.

Note

  • Standard naming conventions would require that this method be called isEnabled which might be better

2.4 Getting The Font

The Font, if any, associated with a Command can be obtained by calling it’s

    public Font getFont()

method.

2.5 Setting The Font

The Font associated with a Command can be set by calling it’s

    public void setFont(Font font)

method.

2.6 Getting The Image

The Image, if any, associated with a Command can be obtained by calling it’s

    public Image getImage()

method.

2.7 Setting The Image

The Image associated with a Command can be set calling it’s

    public void setImage(Image image)

method.

The Image may be immutable or mutable. If the Image is mutable then as is conventional an immutable copy will be used.

2.8 Setting The Label

The label of a Command can be set by calling it’s

    public void setLabel(String label)

method.

It is an error if label is null and a NullPointerException will be thrown.

2.9 Setting The Long Label

The long label of a Command can be set by calling it’s

    public void setLongLabel(String longLabel)

method.

3. Notes

  1. There are number of Commands defined as class constants which are now presumably mutable. For example,

    • Alert.DISMISS_COMMAND
    • List.SELECT_COMMAND

    A MIDlet could disable the Alert.DISMISS_COMMAND if it chose to. Its not clear why it would want to, and any adverse effects are entirely self-inflicted, but nonetheless it is now possible for it to do so. Caveat implementor.

  2. A Command now has an onParentEnabled(boolean) method. The method documentation says

    Informs the command of a change in its parent’s enabled value. The application must itself decide how the Command should handle this information, the default is to do nothing.

    Unfortunately that is all it says.

    Presumably it is intended that it be over-ridden in sub-classes of Command. Its just not clear why.


Copyright (c) 2009 By Simon Lewis. All Rights Reserved.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: