MenuItem.java

/**
 * Copyright (c) 2012-2013 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.amaze.ui;

import com.nokia.example.amaze.model.MyTimer;

/**
 * A menu item that can be added to menu implemented in Menu.java.
 */
public class MenuItem implements MyTimer.Listener {
    // Constants
    public static final int MENU_ITEM_HEIGHT = 50;
    public static final int COLOR = MazeCanvas.TEXT_COLOR;
    public static final int BLINK_INTEVAL = 500; // Milliseconds

    // Members
    private String _text = null;
    private boolean _pressed = false;
    private boolean _disabled = false;

    /**
     * Constructor.
     * @param text
     */
    public MenuItem(String text) {
        _text = text;
    }

    /**
     * From MyTimer.Listener.
     * Makes the menu item blink by changing the state between pressed and
     * not pressed.
     */
    public void onTimeout() {
        _pressed = !_pressed;
    }

    /** 
     * @param text The text to set for this item.
     */
    public void setText(final String text) {
        _text = text;
    }

    /** 
     * @return The text of this item.
     */
    public final String text() {
        return _text;
    }

    /** 
     * @param pressed
     */
    public void setPressed(boolean pressed) {
        _pressed = pressed;
    }

    /** 
     * @return True if the item is pressed, false otherwise.
     */
    public final boolean pressed() {
        return _pressed;
    }

    /** 
     * @param disabled If true, will disable the item.
     */
    public void setDisabled(boolean disabled) {
        _disabled = disabled;
    }

    /** 
     * @return True if the item is disabled, false otherwise.
     */
    public final boolean disabled() {
        return _disabled;
    }
}