📄 binarypageitem.java
字号:
// Copyright (c) 2005 Sony Ericsson Mobile Communications AB
//
// This software is provided "AS IS," without a warranty of any kind.
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
//
// THIS SOFTWARE IS COMPLEMENTARY OF JAYWAY AB (www.jayway.se)
package bluegammon.gui.menu;
import javax.microedition.lcdui.Image;
/**
* An abstract item that can be set to true or false. An image is
* used to represent each state.
* The method <code>getBoolean</code> must be implemented
* to get the state of the item. The method <code>setBoolean</code> is
* called with the new state when user selects this item.
* @author Peter Andersson
*/
public abstract class BinaryPageItem extends PageItem
implements ItemAction
{
/** Image for true flag */
protected Image m_imgTrue;
/** Image for false flag */
protected Image m_imgFalse;
/** Action that will be called after this action has been executed */
protected ItemAction m_dispatchAction;
/**
* Constructor for <code>BinaryPageItem</code>.
* @param label The label of the item or null.
* @param imageTrue Image for true value or null.
* @param imageFalse Image for false value or null.
* @param subPage The page that will be navigated to when activating this item,
* or null of no such page.
*/
public BinaryPageItem(char[] label, Image imageTrue, Image imageFalse,
MenuPage subPage)
{
super(label, null, null, subPage);
m_imgTrue = imageTrue;
m_imgFalse = imageFalse;
setAction(this);
setLayout(LAYOUT_ALIGN_RIGHT);
}
/**
* Constructor for <code>BinaryPageItem</code>.
* @param label The label of the item or null.
* @param imageTrue Image for true value or null.
* @param imageFalse Image for false value or null.
* @param subPage The page that will be navigated to when activating this item,
* or null of no such page.
* @param dispatchAction
* The action that is called when activating this item,
* or null if no action.
* @param id The id of this item.
*/
public BinaryPageItem(char[] label, Image imageTrue, Image imageFalse,
MenuPage subPage, ItemAction dispatchAction, int id)
{
super(label, null, null, subPage, id);
m_imgTrue = imageTrue;
m_imgFalse = imageFalse;
m_dispatchAction = dispatchAction;
setAction(this);
setLayout(LAYOUT_ALIGN_RIGHT);
}
/**
* Initializes this item with correct image.
*/
public void addedToPage()
{
setImage(getBoolean() ? m_imgTrue: m_imgFalse);
}
/**
* Toggles the boolean value by calling
* <code>getBoolean</code> and <code>setBoolean</code>.
* If a dispatch action is given in constructor, this is
* called after switching flags.
*
* @param page The page this action is called from.
* @param item The item this action is called from.
*/
public void itemAction(MenuPage page, PageItem item)
{
boolean b = !getBoolean();
setBoolean(b);
setImage(b ? m_imgTrue: m_imgFalse);
if (m_dispatchAction != null)
{
m_dispatchAction.itemAction(page, item);
}
}
/**
* Implement this to return the state of the flag.
* @return The state of the flag.
*/
public abstract boolean getBoolean();
/**
* Implement this to set the state of the flag.
* @param value The new boolean value of the flag.
*/
public abstract void setBoolean(boolean value);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -