javauis/lcdui_qt/src/javax/microedition/lcdui/Spacer.java
author hgs
Thu, 05 Aug 2010 16:07:57 +0300
changeset 57 59b3b4473dc8
parent 23 98ccebc37403
permissions -rw-r--r--
v2.2.9_1

/*
* Copyright (c) 2009 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 org.eclipse.swt.graphics.Point;

/**
 * Class representing the Spacer item.
 */
public class Spacer extends Item
{
    /**
     * If Spacer is changed, reasons for Re-layouting.
     */
	static final int UPDATE_MINIMUMSIZE = UPDATE_ITEM_MAX << 1;

    private int minimumWidth = -1;
    private int minimumHeight = -1;

    /**
     * Constructor.
     *
     * @param minW minimum width of the Spacer.
     * @param minH minimum height of the Spacer.
     */
    public Spacer(int minW, int minH)
    {
        setMinimumSize(minW, minH);
    }

    /**
     * Overrides setLabel in Item class.
     *
     * @param newLabel Spacer cannot have any label.
     */
    public void setLabel(String newLabel)
    {
        throw new IllegalStateException(
            MsgRepository.SPACER_EXCEPTION_INVALID_STATE_LABEL);
    }

    /**
     * Overrides method in Item class.
     *
     * @param cmd Spacer cannot have command associated with.
     */
    public void addCommand(Command cmd)
    {
        throw new IllegalStateException(
            MsgRepository.SPACER_EXCEPTION_INVALID_STATE_COMMAND);
    }

    /**
     * Overrides method in Item class.
     *
     * @param newCmd Spacer cannot have command associated with.
     */
    public void setDefaultCommand(Command newCmd)
    {
        throw new IllegalStateException(
            MsgRepository.SPACER_EXCEPTION_INVALID_STATE_COMMAND);
    }

    /**
     * Set minimum size for a spacer.
     *
     * @param minW new minimum width of spacer.
     * @param minH new minimum height of spacer.
     */
    public void setMinimumSize(int minW, int minH)
    {
        if(minW < 0 || minH < 0)
        {
            throw new IllegalArgumentException(
                MsgRepository.SPACER_EXCEPTION_INVALID_WIDTH_HEIGHT);
        }
        else
        {
            int updateReason = Item.UPDATE_NONE;
            if(minW != getMinimumWidth())
            {
                minimumWidth = minW;
                updateReason |= UPDATE_MINIMUMSIZE | UPDATE_SIZE_CHANGED;
            }
            if(minH != getMinimumHeight())
            {
                minimumHeight = minH;
                updateReason |= UPDATE_MINIMUMSIZE | UPDATE_SIZE_CHANGED;
            }
			if(updateReason != Item.UPDATE_NONE)
            {
            	updateParent(updateReason);
			}
        }
    }

    /**
     * Calculates minimum size of this item.
     *
     * @return Minimum size.
     */
    Point calculateMinimumSize()
    {
        return new Point(minimumWidth, minimumHeight);
    }

    /**
     * Calculates preferred size of this item.
     *
     * @return Preferred size.
     */
    Point calculatePreferredSize()
    {
        return new Point(minimumWidth, minimumHeight);
    }

}