javauis/lcdui_akn/javalcdui/javasrc/javax/microedition/lcdui/ImageItem.java
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 13 Oct 2010 14:23:59 +0300
branchRCL_3
changeset 83 26b2b12093af
parent 19 04becd199f91
permissions -rw-r--r--
Revision: v2.2.17 Kit: 201041

/*
* Copyright (c) 1999 - 2004 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/


package javax.microedition.lcdui;

import com.nokia.mj.impl.rt.legacy.NativeError;

public class ImageItem extends Item
{
    private Image  iImage;
    private String iAltText;

    public ImageItem(String aLabel,Image aImage,int aLayout,String aAltText)
    {
        this(aLabel,aImage,aLayout,aAltText,PLAIN);
    }

    public ImageItem(String aLabel,Image aImage,int aLayout,String aAltText,int aAppearanceMode)
    {
        if (aAppearanceMode != PLAIN && aAppearanceMode != HYPERLINK && aAppearanceMode != BUTTON)
        {
            throw new IllegalArgumentException();
        }
        checkLayout(aLayout);

        iImage = aImage;
        iAppearance = aAppearanceMode;
        iLayout  = aLayout;
        iAltText = aAltText;
        iLabel   = aLabel;

        //
        // Create a snapshot in the case of mutable images. Don't need to keep
        // snapshot reference as native layer must copy or inc refcount
        //
        Image snapShot = aImage;
        if (null != aImage && aImage.isMutable())
        {
            snapShot = Image.createImage(aImage);
        }

        synchronized (iToolkit)
        {
            final String label = aLabel == null?"":aLabel;
            final int    image = snapShot == null ? 0 : snapShot.getHandle(false);
            iHandle = Toolkit.checkHandle(_create(iToolkit.getHandle(),this, label, image, aLayout, aAppearanceMode, aAltText));
        }
    }

    public Image getImage()
    {
        return iImage;
    }

    public void setImage(Image aImage)
    {
        //
        // Create a snapshot in the case of mutable images. Don't need to keep
        // snapshot reference as native layer must copy or inc refcount
        //
        Image snapShot = aImage;
        if (null != aImage && aImage.isMutable())
        {
            snapShot = Image.createImage(aImage);
        }

        synchronized (iToolkit)
        {
            final int image = (null != snapShot ? snapShot.getHandle(false) : 0);

            NativeError.check(_setImage(getHandle(), iToolkit.getHandle(), image));
            iImage = aImage;

            RefreshForm();
        }
    }

    public String getAltText()
    {
        return iAltText;
    }

    public void setAltText(String aAltText)
    {
        synchronized (iToolkit)
        {
            NativeError.check(_setAltText(getHandle(),iToolkit.getHandle(),aAltText==null?"":aAltText));
            iAltText = aAltText;
            RefreshForm();
        }
    }

    public int getAppearanceMode()
    {
        return iAppearance;
    }

    private native int _create(int aToolkit,ImageItem aImageItem,String aLabel,int aImage,int aLayout,int aAppearanceMode,String aAltText);
    private native int _setImage(int aImageItem,int aToolkit,int aImage);
    private native int _setAltText(int aImageItem,int aToolkit,String aAltText);
}