FileDocCategorySizeDatePackage
ImageItemLFImpl.javaAPI DocphoneME MR2 API (J2ME)10677Wed May 02 18:00:20 BST 2007javax.microedition.lcdui

ImageItemLFImpl

public class ImageItemLFImpl extends ItemLFImpl implements ImageItemLF
Platform widget look and feel of ImageItem.

Fields Summary
private final ImageItem
imgItem
The ImageItem associated with this view.
private final ImageData
itemImageData
The ImageData associated with the item.
private int
appearanceMode
Appearance mode. The actual appearance of an ImageItem could be different to the one set in ImageItem. An ImageItem created with PLAIN appearance will look like a HYPERLINK if commands were added.
Constructors Summary
ImageItemLFImpl(ImageItem imageItem)
Creates look & feel for an ImageItem.

param
imageItem the ImageItem associated with this look & feel

        super(imageItem);
        
        ImageData imageData = null;
        if (imageItem != null) {
          Image image = imageItem.immutableImg;
          if (image != null) {
            imageData = image.getImageData();
          }
        }

        this.imgItem = imageItem;

        this.itemImageData = imageData;

        // when no commands are added, the actual appearance
        // is PLAIN; the actual appearance will be the same
        // as appearance set in ImageItem if a command is added
        // to this ImageItem
        appearanceMode = Item.PLAIN;
    
Methods Summary
voidcreateNativeResource(int ownerId)
Create native resource for current ImageItem. Override function in ItemLFImpl.

param
ownerId Owner screen's native resource id

        nativeId = createNativeResource0(ownerId,
                                         imgItem.label, 
                                         imgItem.layout,
                                         itemImageData,
                                         imgItem.altText, 
                                         appearanceMode);
    
private native intcreateNativeResource0(int ownerId, java.lang.String label, int layout, ImageData imageData, java.lang.String altText, int appearanceMode)
KNI function that creates native resource for current ImageItem.

param
ownerId Owner screen's native resource id (MidpDisplayable *)
param
label label to be used for this Item
param
layout layout directive associated with this Item
param
imageData ImageData to be used for this ImageItem
param
altText alternative text to be used for this ImageItem
param
appearanceMode should be PLAIN, HYPERLINK or BUTTON
return
native resource id (MidpItem *) of this ImageItem

booleanequateNLB()
Determine if this Item should have a newline before it.

return
true if it should have a newline before

        // MIDP1.0 already had an ability to set LAYOUT_NEWLINE_BEFORE.
        // Hence there is no need to check for LAYOUT_2 (as in StringItem)
        if (super.equateNLB()) {
            return true;
        }

        // LAYOUT_NEWLINE_BEFORE is not set but LAYOUT_2 is set
        // which means that items could be positioned side by side
        if ((imgItem.layout & Item.LAYOUT_2) == Item.LAYOUT_2) {
            return false;
        }
        
        // LAYOUT_2 was not set, hence we need to provide backward 
        // compatibility with MIDP1.0 where any ImageItem with a 
        // non-null label would go on a new line.
        return imgItem.label != null && imgItem.label.length() > 0;
    
public voidlAddCommand(Command cmd, int i)
Notifies L&F of a command addition in the corresponding ImageItem.

param
cmd the newly added command
param
i the index of the added command in the ImageItem's commands[] array

        super.lAddCommand(cmd, i);

        if ((imgItem.numCommands >= 1) && (appearanceMode == Item.PLAIN)) {
            appearanceMode = imgItem.appearanceMode == Item.BUTTON ?
                             Item.BUTTON : Item.HYPERLINK;
            if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
                setContent0(nativeId, itemImageData, imgItem.altText, 
                            appearanceMode);
            }
            lRequestInvalidate(true, true);
        }
    
public voidlRemoveCommand(Command cmd, int i)
Notifies L&F of a command removal in the corresponding ImageItem.

param
cmd the newly removed command
param
i the index of the removed command in the ImageItem's commands[] array

        super.lRemoveCommand(cmd, i);

        // restore the value of the original appearanceMode
        if (imgItem.numCommands < 1) {
            appearanceMode = Item.PLAIN;
            if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
                setContent0(nativeId, itemImageData, imgItem.altText, 
                            appearanceMode);
            }
            lRequestInvalidate(true, true);
        }
    
public voidlSetAltText(java.lang.String altText)
Notifies L&F of an alternative text change in the corresponding ImageItem.

param
altText the new alternative text set in the ImageItem

        // Only update native resource if it exists.
        if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
            setContent0(nativeId, itemImageData, altText, 
                        appearanceMode);
        }
        lRequestInvalidate(true, true);
    
public voidlSetImage(Image img)
Notifies L&F of an image change in the corresponding ImageItem.

param
img the new image set in the ImageItem

        // Only update native resource if it exists.
        if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
            ImageData imageData = null;
            if (img != null) {
              imageData = img.getImageData();
            }
            setContent0(nativeId, imageData, 
                        imgItem.altText, appearanceMode);
        }
        lRequestInvalidate(true, true);
    
private native voidsetContent0(int nativeId, ImageData imageData, java.lang.String text, int appearanceMode)
KNI function that sets image on the native resource corresponding to the current ImageItem.

param
nativeId native resource id for this item
param
imgData ImageData instance associated with a new Image set on the current ImageItem
param
text new alternative text set on the current ImageItem
param
appearanceMode the actual appearance mode to be used

booleanuCallPeerStateChanged(int hint)
Called by event delivery to notify an ItemLF in current FormLF of a change in its peer state. Handle special gesture of default command.

param
hint -1 signals that user performed the special gesture of default command
return
always false so ItemStateListener will not be notified

 
        // activate default command if hint is -1
        if (hint == -1) {

            Command defaultCommand;
            ItemCommandListener commandListener;

            synchronized (Display.LCDUILock) {

                defaultCommand  = imgItem.defaultCommand;
                commandListener = imgItem.commandListener;
            }

            if (defaultCommand != null && commandListener != null) {

                // Protect from any unexpected application exceptions
                try {
                    synchronized (Display.calloutLock) {
                        commandListener.commandAction(defaultCommand, imgItem);
                    }
                } catch (Throwable thr) {
                    Display.handleThrowable(thr);
                }
            }
        }

        // Indicate to Form to not notify ItemStateListener
        return false;