|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.enough.polish.ui.Item
de.enough.polish.ui.StringItem
de.enough.polish.ui.IconItem
de.enough.polish.ui.ChoiceItem
public class ChoiceItem
Paints a single item of a choice group.
As forIconItem,
ChoiceItem is a de.enough.polish extension to group
in a same Object text and image, ChoiceItems being aimed at
choice items of lists, e.g. List or ChoiceGroup.
Hence, arguments of type ChoiceItem are found in the constructors
of these lists, and in all methods for adding items to them, or retrieving
items from them.
This is a much better alternative to methods passing separately string and image parts, for (at least) 2 reasons:
Strings and Images,
such as:
List(String title, int listType, String[] stringElements, Image[] imageElements)
ChoiceGroup(String label, int choiceType, String[] stringElements, Image[] imageElements)
ChoiceItem, each of them containing
its image and text, solves this error-prone constraint.
ChoiceItem is a much
robust approach, as shown in this example:
import javax.microedition.lcdui.*;
import de.enough.polish.ui.ChoiceItem;
class ListExample extends List implements CommandListener
{
static class Entry extends ChoiceItem {
String data;
Entry(String text, Image img, String data) {
//#style default
super(text, img, List.IMPLICIT);
this.data = data;
}
}
static final Entry[] entries = {
new Entry("Item #1", null, "data 1"),
new Entry("Item #2", null, "data 2"),
new Entry("Item #3", null, "data 3")
};
ListExample() {
//#style default
super("A List", List.IMPLICIT, entries);
setCommandListener(this);
display.setCurrent(this);
}
public void commandAction(Command c, Displayable d)
{
int sel;
if ((c == List.SELECT_COMMAND) && (-1 != (sel = getSelectedIndex()))) {
System.out.println("Selected data: " + ((Entry)getItem(sel)).data);
}
}
}
(Example and JavaDoc provided by Pierre G. Richard)
Copyright Enough Software 2004 - 2008
history
05-May-2004 - rob creation
| Field Summary | |
|---|---|
boolean |
drawBox
determines whether an image is drawn before the item |
boolean |
isSelected
determines whether this item is currently selected |
protected javax.microedition.lcdui.Font |
preferredFont
|
| Fields inherited from class de.enough.polish.ui.IconItem |
|---|
horizontalAdjustment, image, imageAlign, imageHeight, imageWidth, isTextVisible, relativeIconX, relativeIconY, scaleData, scaleFinished, verticalAdjustment, yAdjustText |
| Fields inherited from class de.enough.polish.ui.StringItem |
|---|
animateTextWrap, bitMapFont, bitMapFontViewer, clipText, font, text, textColor, textEffect, textHorizontalAdjustment, textLines, textVerticalAdjustment, textWrapDirection, textWrapSpeed, useSingleLine, xOffset |
| Constructor Summary | |
|---|---|
ChoiceItem(java.lang.String text,
javax.microedition.lcdui.Image image,
int choiceType)
Creates a new ChoiceItem. |
|
ChoiceItem(java.lang.String text,
javax.microedition.lcdui.Image image,
int choiceType,
Style style)
Creates a new ChoiceItem. |
|
| Method Summary | |
|---|---|
void |
adjustProperties(Item lastItem)
|
protected java.lang.String |
createCssSelector()
Retrieves the CSS selector for this item. |
javax.microedition.lcdui.Image |
getPlainImage()
Gets the image representing the "not selected" state of this choice item. |
javax.microedition.lcdui.Image |
getSelectedImage()
Gets the image representing the "selected" state of this choice item. |
protected void |
initContent(int firstLineWidth,
int lineWidth)
Initialises this item. |
void |
paintContent(int x,
int y,
int leftBorder,
int rightBorder,
javax.microedition.lcdui.Graphics g)
Paints the content of this item. |
void |
select(boolean select)
Selects or deselects this item. |
void |
setChoiceType(int choiceType)
Changes the type of this ChoiceItem |
void |
setImage(java.lang.String name,
javax.microedition.lcdui.Image image)
sets the image which has been loaded in the background. |
void |
setPlainImage(javax.microedition.lcdui.Image image)
Sets the image representing the "not selected" state of this choice item. |
void |
setPreferredFont(javax.microedition.lcdui.Font font)
Sets the preferred font. |
void |
setSelectedImage(javax.microedition.lcdui.Image image)
Sets the image representing the "selected" state of this choice item. |
void |
setStyle(Style style)
Sets the style of this item. |
void |
toggleSelect()
Changes the selected-state to the opposite state. |
| Methods inherited from class de.enough.polish.ui.IconItem |
|---|
animate, defocus, getImage, isTextVisible, releaseResources, setImage, setImage, setImage, setImageAlign, setTextVisible, toString |
| Methods inherited from class de.enough.polish.ui.StringItem |
|---|
getFont, getFontHeight, getText, hideNotify, setFont, setText, setText, setTextColor, showNotify, stringWidth |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public boolean isSelected
public boolean drawBox
protected javax.microedition.lcdui.Font preferredFont
| Constructor Detail |
|---|
public ChoiceItem(java.lang.String text,
javax.microedition.lcdui.Image image,
int choiceType)
text - the text of the itemimage - the image of the itemchoiceType - the type of this item, either
Choice.EXCLUSIVE, Choice.MULTIPLE, Choice.IMPLICIT or Choice.POPUP.
When IMPLICIT or POPUP is used, no selection-box will be drawn.
public ChoiceItem(java.lang.String text,
javax.microedition.lcdui.Image image,
int choiceType,
Style style)
text - the text of the itemimage - the image of the itemchoiceType - the type of this item, either
Choice.EXCLUSIVE, Choice.MULTIPLE, Choice.IMPLICIT or Choice.POPUP.
When IMPLICIT or POPUP is used, no selection-box will be drawn.style - the CSS style of this item| Method Detail |
|---|
public void setChoiceType(int choiceType)
choiceType - eithe Choice.EXCLUSIVE, Choice.MULTPIPLE or Choice.IMPLICITprotected java.lang.String createCssSelector()
Item
createCssSelector in class IconItem
protected void initContent(int firstLineWidth,
int lineWidth)
Item
initContent in class IconItemfirstLineWidth - the maximum width of the first linelineWidth - the maximum width of any following linesItem.contentWidth,
Item.contentHeight,
Item.preferredWidth,
Item.preferredHeight
public void paintContent(int x,
int y,
int leftBorder,
int rightBorder,
javax.microedition.lcdui.Graphics g)
Item
paintContent in class IconItemx - the left start positiony - the upper start positionleftBorder - the left border, nothing must be painted left of this positionrightBorder - the right border, nothing must be painted right of this positiong - the Graphics on which this item should be painted.public void setStyle(Style style)
Item
setStyle in class IconItemstyle - the new style for this item.
public void setImage(java.lang.String name,
javax.microedition.lcdui.Image image)
ImageConsumer
setImage in interface ImageConsumersetImage in class IconItemname - the name of the image.
This allows the image-consumer to differentiate between several images.image - the image which was loaded in the background thread.public void select(boolean select)
select - true when this item should be selectedpublic void toggleSelect()
public void setPreferredFont(javax.microedition.lcdui.Font font)
font - the preferred fontpublic void adjustProperties(Item lastItem)
lastItem - the item to use the values from for adjustoingpublic void setPlainImage(javax.microedition.lcdui.Image image)
image - the image representing the "not selected" statepublic javax.microedition.lcdui.Image getPlainImage()
public void setSelectedImage(javax.microedition.lcdui.Image image)
image - the image representing the "selected" statepublic javax.microedition.lcdui.Image getSelectedImage()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||