?? virtuallist.java.svn-base
字號:
this.textColor = text; this.cursorFrameColor = crsFrame; this.cursorAlpha = cursorAlpha; this.menuAlpha = menuAlpha; if (isActive()) virtualCanvas.repaint(); } public int getFontSize() { return fontSize; } public int getTextColor() { return textColor; } public int getBkgrndColor() { return bkgrndColor; } //! Returns number of visibled lines of text which fits in screen public int getVisCount() { int size = getSize(); int y = 0; int counter = 0, i; int height = getDrawHeight(); int topItem = this.topItem; if (size == 0) return 0; if (topItem < 0) topItem = 0; if (topItem >= size) topItem = size - 1; for (i = topItem; i < (size - 1); i++) { y += getItemHeight(i); if (y > height) return counter; counter++; } y = height; counter = 0; for (i = size - 1; i >= 0; i--) { y -= getItemHeight(i); if (y < 0) break; counter++; } return counter; } //TODO: brief text public void setMode(int value) { if (cursorMode == value) return; cursorMode = value; invalidate(); } public int getCursorMode() { return cursorMode; } public boolean isActive() { return (virtualCanvas.currentControl == this) && virtualCanvas.isShown(); } private void doActivate(Display display, Alert alert) { if (isActive()) return; if (virtualCanvas.currentControl != null) {//#sijapp cond.if target="RIM" | target="DEFAULT"# for (int i = virtualCanvas.currentControl.commands.size()-1; i >= 0; i--) virtualCanvas.removeCommand((Command)virtualCanvas.currentControl.commands.elementAt(i));//#sijapp cond.end# if (virtualCanvas.isShown()) virtualCanvas.currentControl.onHide(); } //#sijapp cond.if target="RIM" | target="DEFAULT"# for (int i = commands.size()-1; i >= 0; i--) virtualCanvas.addCommand((Command)commands.elementAt(i));//#sijapp cond.else# resetUiState();//#sijapp cond.end# virtualCanvas.currentControl = this; virtualCanvas.cancelKeyRepeatTask(); virtualCanvas.setCommandListener(commandListener); if (alert != null) display.setCurrent(alert, virtualCanvas); else display.setCurrent(virtualCanvas); repaint(); onShow();//#sijapp cond.if target="MOTOROLA" | target="MIDP2"# setBackLightOn();//#sijapp cond.end# } public void activate(Display display) { doActivate(display, null); } public void activate(Display display, Alert alert) { doActivate(display, alert); } protected void showNotify() { virtualCanvas.setCommandListener(commandListener); forcedHeight = forcedWidth = -1;//#sijapp cond.if target!="RIM" & target!="DEFAULT"# uiState = UI_STATE_NORMAL;//#sijapp cond.end# onShow(); } //! Returns height of each item in list public int getItemHeight(int itemIndex) { int imgHeight = 0; paintedItem.clear(); get(itemIndex, paintedItem); if (paintedItem.leftImage != null) imgHeight = Math.max(imgHeight, paintedItem.leftImage.getHeight()+1); else if (paintedItem.secondLeftImage != null) imgHeight = Math.max(imgHeight, paintedItem.secondLeftImage.getHeight()+1); else if (paintedItem.rightImage != null) imgHeight = Math.max(imgHeight, paintedItem.secondLeftImage.getHeight()+1); else imgHeight = 0; return (fontHeight > imgHeight) ? fontHeight : imgHeight; } // protected void invalidate() protected void invalidate() { if (dontRepaint) return; if (isActive()) virtualCanvas.repaint(); } protected void invalidate(int x1, int y1, int x2, int y2) { if (dontRepaint) return; if (isActive()) virtualCanvas.repaint(x1, y1, x2-x1, y2-y1); } // protected void checkCurrItem() protected void checkCurrItem() { int size = getSize(); if (cyclingCursor) { if (currItem < 0) currItem = size - 1; else if (currItem >= size) currItem = 0; } else { if (currItem < 0) currItem = 0; else if (currItem >= size) currItem = size-1; } } // protected void checkTopItem() - internal // check for position of top element of list and change it, if nesessary protected void checkTopItem() { int size = getSize(); int visCount = getVisCount(); if (size == 0) { topItem = 0; return; } if (currItem >= (topItem + visCount - 1)) topItem = currItem - visCount + 1; if (currItem < topItem) topItem = currItem; if ((size - topItem) <= visCount) topItem = (size > visCount) ? (size - visCount) : 0; if (topItem < 0) topItem = 0; } // Check does item with index visible protected boolean visibleItem(int index) { return (index >= topItem) && (index <= (topItem + getVisCount())); } // private void storelastItemIndexes() protected void storelastItemIndexes() { lastCurrItem = currItem; lastTopItem = topItem; } // private void repaintIfLastIndexesChanged() protected void repaintIfLastIndexesChanged() { if ((lastCurrItem != currItem) || (lastTopItem != topItem)) invalidate(); if ((lastCurrItem != currItem) && (vlCommands != null)) vlCommands.vlCursorMoved(this); } // protected void moveCursor(int step) protected void moveCursor(int step, boolean moveTop) { storelastItemIndexes(); if (moveTop && (cursorMode == CURSOR_MODE_DISABLED)) topItem += step; if (cyclingCursor) { int last = getSize()-1; int newPos = currItem+step; if (currItem != 0 && newPos < 0) newPos = 0; if (currItem != last && newPos > last) newPos = last; currItem = newPos; } else currItem += step; checkCurrItem(); checkTopItem(); repaintIfLastIndexesChanged(); } protected boolean itemSelected() { return executeCommand(findMenuByType(Command.OK)); } // private keyReaction(int keyCode) private void keyReaction(int keyCode, int type) {//#sijapp cond.if target!="RIM" & target!="DEFAULT"# boolean menuItemsVisible = false; int lastMenuIndex = curMenuItemIndex; Vector menuItemsData = null, clickedMenuItems = null; switch (uiState) { case UI_STATE_LEFT_MENU_VISIBLE: menuItemsVisible = true; menuItemsData = leftMenuItems; break; case UI_STATE_RIGHT_MENU_VISIBLE: menuItemsVisible = true; menuItemsData = rightMenuItems; break; } int lastUIState = uiState;//#sijapp cond.end# switch (getExtendedGameAction(keyCode)) {//#sijapp cond.if target!="RIM" & target!="DEFAULT"# case KEY_CODE_LEFT_MENU: if (type == KEY_PRESSED) clickedMenuItems = leftMenuPressed(); break; case KEY_CODE_RIGHT_MENU: if (type == KEY_PRESSED) clickedMenuItems = rightMenuPressed(); break;//#sijapp cond.end# case KEY_CODE_BACK_BUTTON: if (type == KEY_PRESSED) {//#sijapp cond.if target!="RIM" & target!="DEFAULT"# switch (uiState) { case UI_STATE_RIGHT_MENU_VISIBLE: case UI_STATE_LEFT_MENU_VISIBLE: uiState = UI_STATE_NORMAL; invalidate(); break; default: Command backMenu = findMenuByType(Command.BACK); if (backMenu != null && executeCommand(backMenu)) return; break; }//#sijapp cond.end# Command backMenu = findMenuByType(Command.BACK); if (backMenu != null && executeCommand(backMenu)) return; } break; case Canvas.DOWN://#sijapp cond.if target!="RIM" & target!="DEFAULT"# if (menuItemsVisible) moveSelectedMenuItem(1, menuItemsData.size(), false); else moveCursor(1, false);//#sijapp cond.else# moveCursor(1, false);//#sijapp cond.end# break; case Canvas.UP://#sijapp cond.if target!="RIM" & target!="DEFAULT"# if (menuItemsVisible) moveSelectedMenuItem(-1, menuItemsData.size(), false); else moveCursor(-1, false);//#sijapp cond.else# moveCursor(-1, false);//#sijapp cond.end# break; case Canvas.FIRE: if (type == KEY_PRESSED) {//#sijapp cond.if target!="RIM" & target!="DEFAULT"# if ((keyCode == KEY_CODE_LEFT_MENU) || (keyCode == KEY_CODE_RIGHT_MENU)) return; if (menuItemsVisible) { uiState = UI_STATE_NORMAL; executeCommand((Command)menuItemsData.elementAt(curMenuItemIndex)); invalidate(); } else { boolean executed = itemSelected(); if (!executed && (vlCommands != null)) vlCommands.vlItemClicked(this); }//#sijapp cond.else# boolean executed = itemSelected(); if (!executed && (vlCommands != null)) vlCommands.vlItemClicked(this);//#sijapp cond.end# } break; } //#sijapp cond.if target!="RIM" & target!="DEFAULT"# initPopupMenuItems(clickedMenuItems); if ((menuItemsVisible && (lastMenuIndex != curMenuItemIndex)) || (lastUIState != uiState)) { invalidate(); return; }//#sijapp cond.end# if (type == KEY_PRESSED) { switch (keyCode) { case Canvas.KEY_NUM1: storelastItemIndexes(); currItem = topItem = 0; repaintIfLastIndexesChanged(); break; case Canvas.KEY_NUM7: storelastItemIndexes(); int endIndex = getSize() - 1; currItem = endIndex; checkTopItem(); repaintIfLastIndexesChanged(); break; case Canvas.KEY_NUM3: moveCursor(-getVisCount(), false); break; case Canvas.KEY_NUM9: moveCursor(getVisCount(), false); break;//#sijapp cond.if target="MOTOROLA"# case Canvas.KEY_STAR: getDisplay().flashBacklight(backLightIsOn ? 1 : Integer.MAX_VALUE); backLightIsOn = !backLightIsOn; break;//#sijapp cond.end# } } } protected Display getDisplay() { return virtualCanvas.getDisplay(); } protected Canvas getCanvas() { return virtualCanvas; } public void doKeyreaction(int keyCode, int type) { switch (type) { case KEY_PRESSED://#sijapp cond.if target="MOTOROLA" | target="MIDP2"# setBackLightOn();//#sijapp cond.end# keyReaction(keyCode, type); break; case KEY_REPEATED: keyReaction(keyCode, type); break; } if (vlCommands != null) vlCommands.vlKeyPress(this, keyCode, type); } // Return game action or extended codes // Thanks for Aspro for source examples private int getExtendedGameAction(int keyCode) { try { int gameAct = virtualCanvas.getGameAction(keyCode); switch (gameAct) { case Canvas.UP: case Canvas.DOWN: case Canvas.LEFT: case Canvas.RIGHT: return gameAct; } } catch (Exception e) {} String strCode = null; try { strCode = virtualCanvas.getKeyName(keyCode).toLowerCase(); } catch (IllegalArgumentException e) {} if (strCode != null) { if ("soft1".equals(strCode) || "soft 1".equals(strCode) || "soft_1".equals(strCode) || "softkey 1".equals(strCode) || "sk2(left)".equals(strCode) || strCode.startsWith("left soft")) return KEY_CODE_LEFT_MENU; if ("soft2".equals(strCode) || "soft 2".equals(strCode) || "soft_2".equals(strCode) || "softkey 4".equals(strCode) || "sk1(right)".equals(strCode) || strCode.startsWith("right soft")) return KEY_CODE_RIGHT_MENU; if ("on/off".equals(strCode) || "back".equals(strCode)) return KEY_CODE_BACK_BUTTON; //#sijapp cond.if target="RIM"# if ("trackball".equals(strCode) || "enter".equals(strCode)) return Canvas.FIRE;//#sijapp cond.end# } switch (keyCode) {//#sijapp cond.if target is "MIDP2"# case -6://#sijapp cond.end# case -21: case 21: case 105: case -202: case 113: case 57345: return KEY_CODE_LEFT_MENU; //#sijapp cond.if target is "MIDP2"# case -7://#sijapp cond.end# case -22: case 22: case 106: case -203: case 112: case 57346: return KEY_CODE_RIGHT_MENU;//#sijapp cond.if target isnot "SIEMENS2"# case -11: return KEY_CODE_BACK_BUTTON;//#sijapp cond.end# } try { int gameAct = virtualCanvas.getGameAction(keyCode); if (gameAct > 0) return gameAct; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -