listlabel.java

来自「j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件」· Java 代码 · 共 110 行

JAVA
110
字号
package com.jmobilecore.ui.core;

import javax.microedition.lcdui.Font;

/**
 * Provides a text label for display as part of <code>List</code> component.  <code>ListLabel</code> is focusable.
 *
 * @author Greg Gridin
 */
public class ListLabel extends Label implements ListComponent {

    /**
     * A key stoke that ia associated with a list label.
     * To remove you have to assign to it <code>PlatformCanvas.KEY_UNDEFINED</code> value
     */
    protected int shortcut = PlatformCanvas.KEY_UNDEFINED;

    /**
     * This field indicates the command has been issued
     * by a  particular list label.
     * By default the <code>actionCommand</code>
     * is the label of the list label, unless it has been
     * explicitly set to a different value.
     */
    protected Object actionCommand = null;

    /**
     * Create a list label
     *
     * @param label    the label for this list label.
     */
    public ListLabel(String label) {
        this(label, Style.TEXT_FONT, PlatformCanvas.KEY_UNDEFINED, label);
    }

    /**
     * Create a list label of specified font with an associated keyboard shortcut.
     *
     * @param label    the label for this list label.
     * @param font     the label font
     * @param shortcut key code associated with list label
     */
    public ListLabel(String label, Font font, int shortcut) {
        this(label, font, shortcut, label);
    }

    /**
     * Create a list label with an associated keyboard shortcut and custom action.
     *
     * @param label    the label for this list label.
     * @param font     the label font
     * @param shortcut key code associated witha list label
     * @param action   custom action for the <code>ListLabel</code>
     */
    public ListLabel(String label, Font font, int shortcut, Object action) {
        super(label, font, Label.LEFT);
        setShortcut(shortcut);
        setAction(action);
        focusable = true;
    }

    /**
     * Get the key code shortcut for this <code>ListLabel</code>
     * This method is required by <code>ListComponent</code> interface
     *
     * @return the keycode shortcut
     */
    public int getShortcut() {
        return shortcut;
    }

    /**
     * Sets the key code shortcut for this <code>ListLabel</code>
     * This method is required by <code>ListComponent</code> interface
     *
     * @param shortcut the keycode - new shortcut value
     */
    public void setShortcut(int shortcut) {
        this.shortcut = shortcut;
    }

    /**
     * Get the object representing the <code>ListLabel</code>'s action
     * This method is required by <code>ListComponent</code> interface
     *
     * @return the object associated with this <code>ListLabel</code>
     */
    public Object getAction() {
        return actionCommand;
    }

    /**
     * Sets the object as <code>ListLabel</code>'s action
     * This method is required by <code>ListComponent</code> interface
     *
     * @param action the object - new action value
     */
    public void setAction(Object action) {
        this.actionCommand = action;
    }

    /**
     * Class destructor. Helps VM to perform garbage collection
     */
    public void destructor() {
        actionCommand = null;
    }

} // class ListLabel

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?