ImageItemLFImplpublic class ImageItemLFImpl extends ItemLFImpl implements ImageItemLFThis is the Look &s; Feel implementation for ImageItem. |
Fields Summary |
---|
private ImageItem | imgItemImageItem associated with this view | private int | appearanceModeThe appearance hint |
Constructors Summary |
---|
ImageItemLFImpl(ImageItem imageItem)Creates look&s;feel for an ImageItem
super(imageItem);
this.imgItem = imageItem;
ImageItemResources.load();
// when no commands are added actual appearance
// is PLAIN; actual appearance will be the same
// as appearance set in ImageItem if a command is added
// this ImageItem
appearanceMode = Item.PLAIN;
|
Methods Summary |
---|
boolean | equateNLB()Determine if this Item should have a newline before it
// LAYOUT_NEWLINE_BEFORE is set in the layout
// ImageItem had layout directives in MIDP1.0
// so if LAYOUT_NEWLINE_BEFORE is set we do not need
// to check LAYOUT_2 (as in StringItem)
if (super.equateNLB()) {
return true;
}
// LAYOUT_NEWLINE_BEFORE is not set but LAYOUT_2 is set
// which means that items could be positioned side by side
// unless LAYOUT_NEWLINE_BEFORE is set
if ((imgItem.layout & Item.LAYOUT_2) == Item.LAYOUT_2) {
return false;
}
// in MIDP1.0 any ImageItem with a non-null label would
// go on a new line
return imgItem.label != null && imgItem.label.length() > 0;
// IMPL NOTE: if there is no label in MIDP1.0
// ImageItem could go on the same line only with
// StringItems and ImageItems
| static int | getHorizontalPad(int appearance)Returns horizontal padding per ImageItem's appearance mode.
That is the distance between the left edge and the left part
of the text.
switch (appearance) {
case Item.PLAIN:
return 0;
case Item.HYPERLINK:
return ImageItemSkin.PAD_LINK_H;
default: // Item.BUTTON
return ImageItemSkin.PAD_BUTTON_H;
}
| static int | getVerticalPad(int appearance)Returns vertical padding per ImageItem's appearance mode.
That is the distance between the top edge and
the top part of the text.
switch (appearance) {
case Item.PLAIN:
return 0;
case Item.HYPERLINK:
return ImageItemSkin.PAD_LINK_V;
default: // Item.BUTTON
return ImageItemSkin.PAD_BUTTON_V;
}
| public void | lAddCommand(Command cmd, int i)Notifies L&F of a command addition in the corresponding ImageItem.
super.lAddCommand(cmd, i);
// restore the value of the original appearanceMode
if ((imgItem.numCommands >= 1) && (appearanceMode == Item.PLAIN)) {
appearanceMode = imgItem.appearanceMode == Item.BUTTON ?
Item.BUTTON : Item.HYPERLINK;
lRequestInvalidate(true, true);
}
| void | lGetContentSize(int[] size, int availableWidth)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.
Image img = imgItem.immutableImg;
if (img == null) {
size[WIDTH] = size[HEIGHT] = 0;
} else {
size[WIDTH] = img.getWidth() +
2 * getHorizontalPad(appearanceMode);
size[HEIGHT] = img.getHeight() +
2 * getVerticalPad(appearanceMode);
}
| void | lPaintContent(Graphics g, int width, int height)Paint this ImageItem
if (appearanceMode == Item.HYPERLINK) {
// we re-draw the HYPERLINK border image
// offset to the right (bottom) as many times as necessary
// to fill the width (height) of the Image in the ImageItem.
// with the H_HL_BORDER_PAD from the edge
CGraphicsUtil.drawTop_BottomBorder(g,
ImageItemSkin.IMAGE_LINK_H,
ImageItemSkin.IMAGE_LINK_H,
ImageItemSkin.PAD_LINK_H,
contentBounds[WIDTH] - ImageItemSkin.PAD_LINK_H,
ImageItemSkin.PAD_LINK_H,
height - ImageItemSkin.PAD_LINK_H -
ImageItemSkin.IMAGE_LINK_H.getHeight());
CGraphicsUtil.drawLeft_RightBorder(g,
ImageItemSkin.IMAGE_LINK_V,
ImageItemSkin.IMAGE_LINK_V,
ImageItemSkin.PAD_LINK_H +
ImageItemSkin.IMAGE_LINK_V.getHeight(),
contentBounds[HEIGHT] - ImageItemSkin.PAD_LINK_H -
ImageItemSkin.IMAGE_LINK_H.getHeight(),
ImageItemSkin.PAD_LINK_H,
width - ImageItemSkin.PAD_LINK_H -
ImageItemSkin.IMAGE_LINK_V.getWidth());
} else if (appearanceMode == Item.BUTTON) {
if (ImageItemSkin.IMAGE_BUTTON == null) {
CGraphicsUtil.draw2ColorBorder(g, 0, 0, width, height,
hasFocus,
ImageItemSkin.COLOR_BORDER_DK,
ImageItemSkin.COLOR_BORDER_LT,
ImageItemSkin.BUTTON_BORDER_W);
} else {
CGraphicsUtil.draw9pcsBackground(g, 0, 0,
width, height,
ImageItemSkin.IMAGE_BUTTON);
}
}
Image img = imgItem.immutableImg;
// Determine whether 'img' is not 'null' otherwise
// 'drawImage' method throws 'NullPointerException'
if (img != null) {
g.drawImage(img,
getHorizontalPad(appearanceMode),
getVerticalPad(appearanceMode),
Graphics.TOP | Graphics.LEFT);
}
| public void | lRemoveCommand(Command cmd, int i)Notifies L&F of a command removal in the corresponding ImageItem.
super.lRemoveCommand(cmd, i);
// default to Plain if there are not commands
if (imgItem.numCommands < 1) {
appearanceMode = Item.PLAIN;
lRequestInvalidate(true, true);
}
| public void | lSetAltText(java.lang.String altText)Notifies L&F of an alternative text change
in the corresponding ImageItem.
| public void | lSetImage(Image img)Notifies L&F of an image change in the corresponding ImageItem.
lRequestInvalidate(true, true);
| void | uCallKeyPressed(int keyCode)Called by the system to signal a key press
if (keyCode != Constants.KEYCODE_SELECT) {
return;
}
ItemCommandListener cl;
Command defaultCmd;
synchronized (Display.LCDUILock) {
if (imgItem.numCommands == 0 ||
imgItem.commandListener == null) {
return;
}
cl = imgItem.commandListener;
defaultCmd = imgItem.defaultCommand;
} // synchronized
// SYNC NOTE: The call to the listener must occur outside
// of the lock
if (cl != null) {
try {
// SYNC NOTE: We lock on uCalloutLock around any calls
// into application code
synchronized (Display.calloutLock) {
if (defaultCmd != null) {
cl.commandAction(defaultCmd, imgItem);
} 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);
}
}
|
|