📄 menuelementcomboshift.java
字号:
package no.auc.one.portableplayer.userinterface;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Font;
/**
* MenuElement which displays it's children at it's name tag,
* instead of normal browsing.
*/
public class MenuElementComboShift extends MenuElementContainer {
private int currentChildIndex = 0;
public MenuElementComboShift(String name) {
super(name + ':');
}
public MenuElementComboShift(String name, MenuEventListener listener) {
super(name + ':', listener);
}
public MenuElementComboShift(
String name,
MenuEventListener listener,
MenuElement[] children)
{
super(name + ':', listener, children);
}
// XXX To be deprecated!
public int getCurrentIndex() {
return currentChildIndex;
}
// XXX To be deprecated!
public MenuElement getCurrentChild() {
return (MenuElement)children.elementAt(currentChildIndex);
}
public void paint(Graphics g) {
// Draw "name:" at the left and "childname" at the right
g.drawString(
name,
g.getClipX(),
g.getClipY(),
Graphics.TOP | Graphics.LEFT);
if (children != null && children.size() > 0) {
Font f = g.getFont();
g.setClip(
g.getClipX() +
((100 > f.stringWidth(name)) ? 100 : f.stringWidth(name)),
g.getClipY(),
g.getClipWidth(),
g.getClipHeight());
String itemNameSuffix = "<->";
int maxItemNameLength = g.getClipX() - f.stringWidth(itemNameSuffix);
String itemName = ((MenuElement)children.elementAt(
currentChildIndex)).toString();
if (f.stringWidth(itemName) > maxItemNameLength) {
while(f.stringWidth(itemName) > maxItemNameLength + f.stringWidth("..")) {
itemName = itemName.substring(0, itemName.length() - 1);
}
itemName += "..";
}
itemName += itemNameSuffix;
g.drawString(
itemName,
g.getClipWidth(),
g.getClipY(),
Graphics.TOP | Graphics.RIGHT);
}
}
public void invokeAction() {
if (children.size() > 0) {
System.out.println("Invoke action of current child");
((MenuElement)children.elementAt(
currentChildIndex)).invokeAction();
}
}
public boolean prepareNavigateLeft() {
if (currentChildIndex > 0) {
currentChildIndex--;
} else {
currentChildIndex = (children.size() - 1);
}
return false;
}
public boolean prepareNavigateRight() {
if (currentChildIndex < (children.size() - 1)) {
currentChildIndex++;
} else {
currentChildIndex = 0;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -