StringItemLFImplpublic class StringItemLFImpl extends ItemLFImpl implements StringItemLFThis is the look &s; feel implementation for StringItem. |
Fields Summary |
---|
private StringItem | strItemStringItem associated with this view | private boolean | skipTraverseAn internal flag. True if Form should not traverse
to this StringItem | private int | appearanceModeThe actual appearance used for this StringItem.
It can be different than the hint set in strItem.
Actual appearance is always PLAIN if there are no
commands added. And is never PLAIN if there is at least
one command added |
Constructors Summary |
---|
StringItemLFImpl(StringItem strItem)Creates a look&s;feel for a StringItem
super(strItem);
this.strItem = strItem;
StringItemResources.load();
checkTraverse();
// when no commands are added actual appearance
// is PLAIN; actual appearance will be the same
// as appearance set in StringItem if a command is added
// this StringItem
this.appearanceMode = Item.PLAIN;
|
Methods Summary |
---|
private void | checkTraverse()Check that given the label, text, and commands, Form
should traverse this StringItem. Updates the internal
'skipTraverse' variable.
String label = strItem.label;
String str = strItem.str;
if (str == null && label == null) {
skipTraverse = true;
} else if (str == null && label.trim().equals("")) {
skipTraverse = true;
} else if (label == null && str.trim().equals("")) {
skipTraverse = true;
} else {
skipTraverse = false;
}
| boolean | equateNLA()Determine if this Item should have a newline after it
String label = item.label;
String str = strItem.str;
// If content ends with a \n,
// there is a newline after this StringItem no matter what
if (str != null && str.length() > 0) {
if (str.charAt(str.length() - 1) == '\n") {
return true;
}
} else if (label != null && label.length() > 0) {
// If there is no content and our label ends with a \n,
// there is a newline after this StringItem
if (label.charAt(label.length() - 1) == '\n") {
return true;
}
} else {
// empty StringItem
return false;
}
if ((strItem.layout & Item.LAYOUT_2) == Item.LAYOUT_2) {
return ((item.layout & Item.LAYOUT_NEWLINE_AFTER)
== Item.LAYOUT_NEWLINE_AFTER);
}
return false;
| boolean | equateNLB()Determine if this Item should have a newline before it
String label = strItem.label;
String str = strItem.str;
// If label starts with a\n,
// put this StringItem on a newline no matter what
if (label != null && label.length() > 0) {
if (label.charAt(0) == '\n") {
return true;
}
} else if (str != null && str.length() > 0) {
// If there is no label and our content starts with a \n,
// this StringItem starts on a newline
if (str.charAt(0) == '\n") {
return true;
}
} else {
// empty StringItem
return false;
}
if ((strItem.layout & Item.LAYOUT_2) == Item.LAYOUT_2) {
return ((strItem.layout & Item.LAYOUT_NEWLINE_BEFORE)
== Item.LAYOUT_NEWLINE_BEFORE);
}
// in MIDP1.0 new any StringItem with a non-null label would
// go on a new line
return label != null && label.length() > 0;
// IMPL NOTE: if there is no label in MIDP1.0
// StringItem could go on the same line only with
// StringItems and ImageItems
| public Font | getDefaultFont()Gets default font to render text in StringItem if it was not
set by the application.
return getTextFont(appearanceMode);
| static int | getForeground(int appearance)Returns the foreground color to render text in StringItem.
switch (appearance) {
case Item.PLAIN:
return ScreenSkin.COLOR_FG;
case Item.HYPERLINK:
return StringItemSkin.COLOR_FG_LINK;
default: // BUTTON
return StringItemSkin.COLOR_FG_BUTTON;
}
| static int | getForegroundHilight(int appearance)Returns the foreground color to render text in StringItem.
switch (appearance) {
case Item.HYPERLINK:
return StringItemSkin.COLOR_FG_LINK_FOCUS;
case Item.PLAIN:
default: // BUTTON
return ScreenSkin.COLOR_FG;
}
| static Font | getTextFont(int appearance)Returns the font to render text in StringItem.
switch (appearance) {
case Item.PLAIN:
return StringItemSkin.FONT;
case Item.HYPERLINK:
return StringItemSkin.FONT_LINK;
default: // BUTTON
return StringItemSkin.FONT_BUTTON;
}
| public void | lAddCommand(Command cmd, int i)Notifies L&s;F of a command addition in the corresponding StringItem.
super.lAddCommand(cmd, i);
// restore the value of the original appearanceMode
if ((strItem.numCommands >= 1) && (appearanceMode == Item.PLAIN)) {
appearanceMode = strItem.appearanceMode == Item.BUTTON ?
Item.BUTTON : Item.HYPERLINK;
lRequestInvalidate(true, true);
}
// checkTraverse(); right now traversability is not command dependent
// lRequestInvalidate(true, true);
| void | lCallPaint(Graphics g, int width, int height)Paint this StringItem
// In BUTTON mode internal layout and painting is done through
// ItemLFImpl
if (appearanceMode == Item.BUTTON || appearanceMode == Item.HYPERLINK) {
super.lCallPaint(g, width, height);
return;
}
// **************** Hyperlink and Plain *********************
lGetLabelSize(labelBounds, width);
int xOffset = 0;
int yOffset = 0;
if (labelBounds[HEIGHT] > 0) {
Font lFont = ScreenSkin.FONT_LABEL;
xOffset = Text.paint(g, strItem.label, lFont,
ScreenSkin.COLOR_FG, 0,
width, labelBounds[HEIGHT],
0, Text.NORMAL, null);
if (xOffset > 0) {
xOffset += getHorizontalPad();
}
yOffset = labelBounds[HEIGHT] - lFont.getHeight();
g.translate(0, yOffset);
}
Text.paint(g, strItem.str, strItem.font,
getForeground(appearanceMode),
getForegroundHilight(appearanceMode),
width, height - yOffset, xOffset, Text.NORMAL, null);
g.translate(0, -yOffset);
| void | lGetContentSize(int[] size, int w)Sets the content size in the passed in array.
Content is calculated based on the availableWidth.
size[WIDTH] and size[HEIGHT] should be set by this method.
if (appearanceMode == Item.HYPERLINK) {
Text.getSizeForWidth(size, w,
strItem.str, strItem.font, 0);
} else {
Text.getSizeForWidth(size, w - (2 * StringItemSkin.PAD_BUTTON_H),
strItem.str, strItem.font, 0);
size[WIDTH] = size[WIDTH] + (2 * StringItemSkin.PAD_BUTTON_H);
}
size[HEIGHT] = strItem.font.getHeight() +
(2 * StringItemSkin.PAD_BUTTON_V);
| public int | lGetPreferredHeight(int w)Get the preferred height of this Item
// In BUTTON and HIPERLINK mode internal layout and sizing is done in
// ItemLFImpl
if (appearanceMode == Item.BUTTON || appearanceMode == Item.HYPERLINK) {
return super.lGetPreferredHeight(w);
}
// In PLAIN and HYPERLINK modes label and content string are
// almost concatenated together and wrapped together
// (almost because there is a horizontal padding between them)
int size[] = contentBounds;
Text.getTwoStringsSize(size, strItem.label, strItem.str,
ScreenSkin.FONT_LABEL,
strItem.font,
w == -1 ? lGetAvailableWidth() : w,
getHorizontalPad());
return size[HEIGHT];
| public int | lGetPreferredWidth(int h)Get the preferred width of this Item
// IMPL NOTE: we ignore the 'h' value and just return
// a basic width based on our contents.
// In BUTTON mode internal layout and sizing is done in
// ItemLFImpl
if (appearanceMode == Item.BUTTON) {
return super.lGetPreferredWidth(h);
}
// In PLAIN and HYPERLINK modes label and content string are
// almost concatenated together and wrapped together
// (if both are not empty there is a horizontal padding between them)
int size[] = contentBounds;
Text.getTwoStringsSize(size, strItem.label, strItem.str,
ScreenSkin.FONT_LABEL,
strItem.font, lGetAvailableWidth(),
getHorizontalPad());
return size[WIDTH];
| void | lPaintContent(Graphics g, int width, int height)Paints the content area of this StringItem.
Graphics is translated to contents origin.
// ********************* BUTTON and HYPERLINK Appearance ******************
// Graphics is translated to content's top left corner
switch (appearanceMode) {
case Item.HYPERLINK: {
int mode = Text.HYPERLINK;
if (hasFocus) {
mode |= Text.INVERT;
}
Text.paint(g, strItem.str, strItem.font,
getForeground(appearanceMode),
getForegroundHilight(appearanceMode),
contentBounds[WIDTH], contentBounds[HEIGHT], contentBounds[X], mode, null);
}
break;
case Item.BUTTON: {
if (StringItemSkin.IMAGE_BUTTON == null) {
CGraphicsUtil.draw2ColorBorder(g, 0, 0,
contentBounds[WIDTH],
contentBounds[HEIGHT],
hasFocus,
StringItemSkin.COLOR_BORDER_DK,
StringItemSkin.COLOR_BORDER_LT,
StringItemSkin.BUTTON_BORDER_W);
} else {
CGraphicsUtil.draw9pcsBackground(g, 0, 1,
contentBounds[WIDTH],
contentBounds[HEIGHT],
StringItemSkin.IMAGE_BUTTON);
}
g.translate(StringItemSkin.PAD_BUTTON_H,
StringItemSkin.PAD_BUTTON_V);
Text.paint(g, strItem.str, strItem.font,
getForeground(appearanceMode),
getForegroundHilight(appearanceMode),
contentBounds[WIDTH] - (2 * StringItemSkin.PAD_BUTTON_H),
contentBounds[HEIGHT] - (2 * StringItemSkin.PAD_BUTTON_V),
0, Text.TRUNCATE, null);
g.translate(-StringItemSkin.PAD_BUTTON_H,
-StringItemSkin.PAD_BUTTON_V);
}
}
| public void | lRemoveCommand(Command cmd, int i)Notifies L&s;F of a command removal in the corresponding StringItem.
super.lRemoveCommand(cmd, i);
// default to PLAIN appearance if there are no commands left
if (strItem.numCommands < 1) {
appearanceMode = Item.PLAIN;
lRequestInvalidate(true, true);
}
// checkTraverse(); right now traversability is not command dependent
// lRequestInvalidate(true, true);
| public void | lSetFont(Font font)Notifies L&s;F of a font change in the corresponding StringItem.
lRequestInvalidate(true, true);
| public void | lSetText(java.lang.String str)Notifies L&s;F of a string change in the corresponding StringItem.
checkTraverse();
lRequestInvalidate(true, true);
| void | uCallKeyPressed(int keyCode)called by the system to signal a key press
ItemCommandListener cl;
Command defaultCmd;
if (keyCode != Constants.KEYCODE_SELECT) {
return;
}
synchronized (Display.LCDUILock) {
// StringItem takes focus only
// if there are one or more Item Commands
// attached to it
if (!(strItem.numCommands > 0) || strItem.commandListener == null) {
return;
}
cl = strItem.commandListener;
defaultCmd = strItem.defaultCommand;
} // synchronized
// SYNC NOTE: The call to the listener must occur outside
// of the lock. 'strItem' does not change. So we can use it without
// LCDUILock.
synchronized (Display.calloutLock) {
try {
if (defaultCmd != null) {
cl.commandAction(defaultCmd, strItem);
} else {
// IMPL NOTE: Needs HI decision
// either call the first command
// from the command list or
// invoke the menu
}
} catch (Throwable thr) {
Display.handleThrowable(thr);
}
} // synchronized(calloutLock)
|
|