📄 menu.java
字号:
// clear tab body
g.setColor(FILL_COLOR);
g.fillRect(0, menuPadding + tabHeight + 2, width, height - menuPadding - tabHeight - 2);
// if it is necessary to display a vertical scrollbar
g.translate(0, menuPadding + tabHeight + menuPadding + 2);
short scrollStep, minStep/*, currScroll*/;
if (maxTabs < MAX_TABS) {
clientHeight -= 5;
minStep = 10;
scrollStep = (short) ((clientWidth) / (MAX_TABS - maxTabs + 1));
g.setColor(SCROLLBAR_BGCOLOR);
g.fillRect(menuPadding, clientHeight, clientWidth, 2);
if (scrollStep < minStep) {
scrollStep = (short) ((clientWidth - minStep) / (MAX_TABS - maxTabs));
g.setColor(SCROLLBAR_COLOR);
g.fillRect(menuPadding + firstTab * scrollStep, clientHeight, minStep, 2);
} else {
g.setColor(SCROLLBAR_COLOR);
g.fillRect(menuPadding + firstTab * scrollStep, clientHeight, scrollStep, 2);
}
}
// if it is necessary to display a horizontal scrollbar
short itemCount = (short) tabs[currTab].item.size();
short maxDsplItems = getMaxItems();
if (maxDsplItems < itemCount) {
scrollStep = (short) ((clientHeight) / (itemCount - maxDsplItems + 1));
minStep = 10;
clientWidth -= 3;
g.setColor(SCROLLBAR_BGCOLOR);
g.fillRect(2 * menuPadding + clientWidth, 0, 2, clientHeight);
if (scrollStep < minStep) {
scrollStep = (short) ((clientHeight - minStep) / (itemCount - maxDsplItems));
g.setColor(SCROLLBAR_COLOR);
g.fillRect(2 * menuPadding + clientWidth, firstItem * scrollStep, 2, minStep);
} else {
g.setColor(SCROLLBAR_COLOR);
g.fillRect(2 * menuPadding + clientWidth, firstItem * scrollStep, 2, scrollStep);
}
}
// draw menu items
int x = 0;
int y = 0;
for (short j = 0; j < maxDsplItems; j++) {
short itemID = (short) ((firstItem + j) % itemCount);
MenuItem mi = (MenuItem) (tabs[currTab].item.elementAt(itemID));
// if item is not selected
if (itemID != currItem) {
g.setColor(FONT_COLOR);
} else {
g.setColor(OUTLINE_COLOR);
// try to draw a one-line rectangle if value of the item is null
if (mi.value == null) {
g.fillRoundRect(menuPadding, y, clientWidth, fontHeight, 4, 4);
} // else draw a two-line rectangle
else {
g.fillRoundRect(menuPadding, y, clientWidth, 2 * fontHeight, 4, 4);
}
g.setColor(FILL_COLOR);
}
// item now fits to the display
if (mi.img != null) {
x += menuPadding + 1;
g.drawImage(mi.img, x, y + (fontHeight - mi.img.getHeight()) / 2, Graphics.TOP | Graphics.LEFT);
x += mi.img.getWidth() + 2;
}
// draw name and value
if (mi.name != null) {
g.setFont(getFirstLineFont());
byte offset = (byte) (x + 3);
// scrollbar
if (maxDsplItems < itemCount) {
offset += 3;
}
// actionkey numbers
if (poundPressed) {
offset += g.getFont().charWidth('m');
}
if (g.getFont().stringWidth(mi.name) < clientWidth - offset) {
g.drawString(mi.name, x + 2, y + fontHeight, Graphics.BOTTOM | Graphics.LEFT);
} // name does not fit to the screen
else {
if (itemID == currItem) {
//init TickerTask
if (timer == null) {
timer = new Timer();
timer.schedule(new TickerTask(), 250, 100);
}
if (!sStarted) {
sStarted = true;
tickerText1 = mi.name;
//lets fill the tickerText1 with half of display of spaces
short space = (short) (width / (2 * g.getFont().charWidth(' ')));
for (short i = 0; i < space; i++) {
tickerText1 += ' ';
}
String nameSubstr = Functions.cutString(mi.name, sindex, clientWidth - offset - g.getFont().stringWidth(".."), g).trim() + "..";
g.drawString(nameSubstr, x + 2, y + fontHeight, Graphics.BOTTOM | Graphics.LEFT);
} else {
Functions.Ticker(tickerText1, sindex, x + 2, y + fontHeight, clientWidth - 3, g, Graphics.BOTTOM | Graphics.LEFT);
sindex = (short) ((sindex + 1) % tickerText1.length());
}
} else {// item is not selected so don't move
String nameSubstr = Functions.cutString(mi.name, 0, clientWidth - offset - g.getFont().stringWidth(".."), g).trim() + "..";
g.drawString(nameSubstr, x + 2, y + fontHeight, Graphics.BOTTOM | Graphics.LEFT);
}
}
// draw actionkey number if a pound key is pressed
if (mi.actionKey != -1 && poundPressed) {
if (Settings.fontSize == Settings.FONT_NORMAL) {
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
}
else {
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
}
g.drawString(String.valueOf(itemID + 1), clientWidth, y + (fontHeight + g.getFont().getHeight()) / 2, Graphics.BOTTOM | Graphics.RIGHT);
}
// draw value on the second line
y += fontHeight;
if (poundPressed) {
offset -= g.getFont().charWidth('m');
}
if (mi.value != null) {
g.setFont(getSecondLineFont());
if (g.getFont().stringWidth(mi.value) < clientWidth - offset) {
g.drawString(mi.value, 2, y + fontHeight - 2, Graphics.BOTTOM | Graphics.LEFT);
} // value does not fit to the screen, so move
else {
if (itemID == currItem) {
// init TickerTask
if (timer == null) {
timer = new Timer();
timer.schedule(new TickerTask(), 250, 100);
}
if (!aStarted) {
aStarted = true;
tickerText2 = mi.value;
//lets fill the tickerText1 with half of display of spaces
short space = (short) (width / (2 * g.getFont().charWidth(' ')));
for (short i = 0; i < space; i++) {
tickerText2 += ' ';
}
String valueSubstr = Functions.cutString(mi.value, aindex, clientWidth - offset - g.getFont().stringWidth(".."), g).trim() + "..";
g.drawString(valueSubstr, 2, y + fontHeight - 2, Graphics.BOTTOM | Graphics.LEFT);
} else { //doing the effect, moving to the left
Functions.Ticker(tickerText2, aindex, 2, y + fontHeight - 2, clientWidth - 3, g, Graphics.BOTTOM | Graphics.LEFT);
aindex = (short) ((aindex + 1) % tickerText2.length());
}
} else {
String valueSubstr = Functions.cutString(mi.value, 0, clientWidth - offset - g.getFont().stringWidth(".."), g).trim() + "..";
g.drawString(valueSubstr, 2, y + fontHeight, Graphics.BOTTOM | Graphics.LEFT);
}
}
y += fontHeight;
}
}
x = 0;
} /* while */
// transform axis back to [0, 0] position
g.translate(0, -menuPadding - tabHeight - menuPadding - 2);
}
//#ifdef MUJMAIL_TOUCH_SCR
protected void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
if (DEBUG) { System.out.println("Pointer pressed: " + x + "; " + y); }
pointerEventTransformer.pointerPressed(x, y);
}
//#endif
/**
* Reacts on keys pressed.
* @param keyCode - a code of key pressed.
*/
protected synchronized void keyPressed(int keyCode) {
// process a NUM pad keys that are mostly used as shortcuts
// boolean has = hasRepeatEvents();
switch (keyCode) {
case KEY_STAR:
if (actionKeyTask != null) {
actionKeyTask.cancel();
actionKeyTask = null;
}
if (starPressed) {
starPressed = false;
} else {
starPressed = true;
if (timer == null) {
timer = new Timer();
}
actionKeyTask = new ActionKeyTask();
timer.schedule(actionKeyTask, 3000);
}
poundPressed = false;
repaint();
break;
case KEY_POUND:
if (actionKeyTask != null) {
actionKeyTask.cancel();
actionKeyTask = null;
}
if (poundPressed) {
poundPressed = false;
} else {
poundPressed = true;
if (timer == null) {
timer = new Timer();
}
actionKeyTask = new ActionKeyTask();
timer.schedule(actionKeyTask, 3000);
}
starPressed = false;
repaint();
break;
case KEY_NUM1:
case KEY_NUM2:
case KEY_NUM3:
case KEY_NUM4:
case KEY_NUM5:
case KEY_NUM6:
case KEY_NUM7:
case KEY_NUM8:
case KEY_NUM9:
// interval between pressing the STAR button and the following button is limited to 3 second
if (starPressed) {
if (keyCode - 49 < MAX_TABS) {
starPressed = false;
poundPressed = false;
setSelectedTab((byte) (keyCode - 49));
}
return;
}
if (poundPressed) {
if (keyCode - 49 < tabs[currTab].item.size()) {
starPressed = false;
poundPressed = false;
setSelectedItem((short) (keyCode - 49));
commandAction(null, this);
}
return;
}
starPressed = false;
poundPressed = false;
repaint();
break;
}
int gameAction = getGameAction(keyCode);
if (gameAction == UP || gameAction == DOWN || gameAction == RIGHT || gameAction == LEFT) {
starPressed = false;
poundPressed = false;
}
switch (getGameAction(keyCode)) {
case UP:
upPressedAction();
break;
case DOWN:
downPressedAction();
break;
case RIGHT:
rightPressedAction();
break;
case LEFT:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -