?? virtuallist.java.svn-base
字號:
} else if (cmd == rightMenu) { rightMenu = null; rightMenuItems.removeAllElements(); invalidate(); return; } leftMenuItems.removeElement(cmd); rightMenuItems.removeElement(cmd);//#sijapp cond.end# } public void removeAllCommands() {//#sijapp cond.if target="RIM" | target="DEFAULT"# if (virtualCanvas.currentControl == this) for (int i = commands.size()-1; i >= 0; i--) virtualCanvas.removeCommand((Command)commands.elementAt(i)); commands.removeAllElements();//#sijapp cond.else# leftMenu = null; rightMenu = null; leftMenuItems.removeAllElements(); rightMenuItems.removeAllElements();//#sijapp cond.end# }//#sijapp cond.if target="RIM" | target="DEFAULT"# private Vector commands = new Vector();//#sijapp cond.else# private static final int UI_STATE_NORMAL = 0; private static final int UI_STATE_LEFT_MENU_VISIBLE = 1; private static final int UI_STATE_RIGHT_MENU_VISIBLE = 2; private int uiState; private Command leftMenu; private Command rightMenu; private Vector leftMenuItems = new Vector(); private Vector rightMenuItems = new Vector(); private boolean leftMenuItemsSorted = true; private boolean rightMenuItemsSorted = true; void resetUiState() { uiState = UI_STATE_NORMAL; } static private int visibleItemsMenuCount; static private int topMenuItem; private Vector leftMenuPressed() { Vector items = null; if (leftMenu != null) { if (leftMenuItems.size() == 0) { if ( executeCommand(leftMenu) ) return null; } else { if (uiState == UI_STATE_LEFT_MENU_VISIBLE) uiState = UI_STATE_NORMAL; else { if (!leftMenuItemsSorted) { sortMenuItems(leftMenuItems); leftMenuItemsSorted = true; } uiState = UI_STATE_LEFT_MENU_VISIBLE; items = leftMenuItems; } } } return items; } private Vector rightMenuPressed() { Vector items = null; if (rightMenu != null) { if (rightMenuItems.size() == 0) { if (executeCommand(rightMenu)) return null; } else { if (uiState == UI_STATE_RIGHT_MENU_VISIBLE) uiState = UI_STATE_NORMAL; else { if (!rightMenuItemsSorted) { sortMenuItems(rightMenuItems); rightMenuItemsSorted = true; } uiState = UI_STATE_RIGHT_MENU_VISIBLE; items = rightMenuItems; } } } return items; } private void initPopupMenuItems(Vector items) { if (items == null) return; curMenuItemIndex = items.size()-1; int menuItemsCount = items.size(); int menuHeight = getMenuHeight(menuItemsCount); int drawHeight = getDrawHeight(); if (menuHeight > drawHeight) { visibleItemsMenuCount = drawHeight/capAndMenuFont.getHeight(); topMenuItem = menuItemsCount-visibleItemsMenuCount; } else { visibleItemsMenuCount = menuItemsCount; topMenuItem = 0; } } private static void moveSelectedMenuItem(int offset, int size, boolean moveOnlyView) { if (!moveOnlyView) { curMenuItemIndex += offset; if (curMenuItemIndex >= size) curMenuItemIndex = 0; if (curMenuItemIndex < 0) curMenuItemIndex = size-1; if (curMenuItemIndex >= topMenuItem+visibleItemsMenuCount) topMenuItem = curMenuItemIndex-visibleItemsMenuCount+1; if (curMenuItemIndex < topMenuItem) topMenuItem = curMenuItemIndex; } else { topMenuItem += offset; if (topMenuItem < 0) topMenuItem = 0; if (topMenuItem >= size-visibleItemsMenuCount) topMenuItem = size-visibleItemsMenuCount; } } public static void drawFramedString (Graphics g, String text, int left, int top, int style, int textColor, int frameColor){ g.setColor(frameColor); g.drawString(text, left-1, top, style); g.drawString(text, left+1, top, style); g.drawString(text, left, top-1, style); g.drawString(text, left, top+1, style); g.setColor(textColor); g.drawString(text, left, top, style); } private boolean drawMenuBar(Graphics g, int height, int style, int curX, int curY) { int y1 = getHeightInternal()-height; int y2 = getHeightInternal(); int width = getWidthInternal(); int layer = height/4; if (style == DMS_DBLCLICK) return false; if (style == DMS_DRAW) { if (fullScreen) { g.setColor(bkgrndColor); g.fillRect(0, y1, width, y2-y1); return false; } else { //drawRect(g, capBkCOlor, transformColorLight(capBkCOlor, -80), 0, y1, width, y2, 255); int[] backPic = getMenuBarBackground(width, height, transformColorLight(capBkCOlor, -32), transformColorLight(capBkCOlor, -102)); g.drawRGB(backPic, 0, width, 0, y1, width, height, false); } } g.setFont(capAndMenuFont); int textY = (y1+y2-capAndMenuFont.getHeight())/2+2; boolean menuItemsVisible = false; if (leftMenu != null) { //#sijapp cond.if target is "MIDP2"# if ((style == DMS_CLICK) && ptInRect(curX, curY, 0, y1, getWidthInternal()/2, y2)) { Vector items = leftMenuPressed(); initPopupMenuItems(items); invalidate(); return true; } //#sijapp cond.end# if (uiState == UI_STATE_LEFT_MENU_VISIBLE) { menuItemsVisible = true; drawRect(g, transformColorLight(capBkCOlor, -64), transformColorLight(capBkCOlor, -32), 0, y1, width/2, y2, 255); } String text = leftMenu.getLabel(); g.setColor(capTxtColor); g.drawString(text, layer, textY, Graphics.TOP|Graphics.LEFT); } if (rightMenu != null) { //#sijapp cond.if target is "MIDP2"# if ((style == DMS_CLICK) && ptInRect(curX, curY, getWidthInternal()/2, y1, getWidthInternal(), y2)) { Vector items = rightMenuPressed(); initPopupMenuItems(items); invalidate(); return true; } //#sijapp cond.end# String text = rightMenu.getLabel(); if (uiState == UI_STATE_RIGHT_MENU_VISIBLE) { menuItemsVisible = true; drawRect(g, transformColorLight(capBkCOlor, -64), transformColorLight(capBkCOlor, -32), width/2, y1, width, y2, 255); } g.setColor(capTxtColor); g.drawString ( text, width-layer-capAndMenuFont.stringWidth(text), textY, Graphics.TOP|Graphics.LEFT ); } if (!menuItemsVisible && (bottomText != null)) { drawFramedString ( g, bottomText, (width-capAndMenuFont.stringWidth(bottomText))/2, textY, Graphics.TOP|Graphics.LEFT, capTxtColor, getInverseColor(capTxtColor) ); } g.setColor(transformColorLight(capBkCOlor, -128)); g.drawLine(0, y1, width, y1); return false; } private boolean exMenuExists() { return (leftMenu != null) || (rightMenu != null); } protected final int getMenuBarHeight() { if (fullScreen) return curFrameWidth; return exMenuExists() ? capAndMenuFont.getHeight()+3 : curFrameWidth; } private boolean drawMenuItems(Graphics g, int menuBarHeight, int style, int curX, int curY) { switch (uiState) { case UI_STATE_LEFT_MENU_VISIBLE: return drawMenuItems(g, leftMenuItems, getHeightInternal()-menuBarHeight, Graphics.LEFT, style, curX, curY); case UI_STATE_RIGHT_MENU_VISIBLE: return drawMenuItems(g, rightMenuItems, getHeightInternal()-menuBarHeight, Graphics.RIGHT, style, curX, curY); } return false; } private static int getMenuHeight(int count) { int fontHeight = capAndMenuFont.getHeight(); return fontHeight+fontHeight*count; } private static boolean ptInRect(int ptX, int ptY, int x1, int y1, int x2, int y2) { return (x1 <= ptX) && (ptX < x2) && (y1 <= ptY) && (ptY < y2); } private boolean paint3points(Graphics g, int x1, int y1, int x2, int y2, int mode, int curX, int curY, int moveOffset, int menuItemsCount) { switch (mode) { case DMS_DRAW: g.setColor(textColor); int size = 2; int y = (y1+y2-size)/2; int x = 0; for (int i = -1; i <= 1; i++) { x = (x1+x2)/2-i*(2*size+1); g.fillRect(x, y, size, size); } break; //#sijapp cond.if target is "MIDP2"# case DMS_CLICK: case DMS_DBLCLICK: if (ptInRect(curX, curY, x1, y1, x2, y2)) { moveSelectedMenuItem(moveOffset, menuItemsCount, true); invalidate(); return true; } break; //#sijapp cond.end# } return false; } private boolean drawMenuItems(Graphics g, Vector items, int bottom, int horizAlign, int mode, int curX, int curY) { int fontHeight = capAndMenuFont.getHeight(); int layer = fontHeight/3; int vert_layer = fontHeight/2; int itemsCount = items.size(); // calculate width and height int width = 0; int height = getMenuHeight(visibleItemsMenuCount); for (int i = 0; i < itemsCount; i++) { Command cmd = (Command)items.elementAt(i); int txtWidth = capAndMenuFont.stringWidth(cmd.getLabel()); if (txtWidth > width) width = txtWidth; } width += layer*2; if (width > getWidth()-4) width = getWidth()-4; int y = bottom-height; int x = 0; switch (horizAlign) { case Graphics.LEFT: x = 2; break; case Graphics.RIGHT: x = getWidthInternal()-width-2; break; } // Draw background if (mode == DMS_DRAW) { drawRect(g, transformColorLight(bkgrndColor, 24), transformColorLight(bkgrndColor, -24), x, y, x+width, y+height, menuAlpha); } // Draw up button if (topMenuItem != 0) { boolean ok = paint3points(g, x, y, x+width, y+vert_layer, mode, curX, curY, -1, itemsCount); if (ok) return true; } if (topMenuItem+visibleItemsMenuCount != itemsCount) { boolean ok = paint3points(g, x, y+height-vert_layer, x+width, y+height, mode, curX, curY, +1, itemsCount); if (ok) return true; } // Draw items g.setFont(capAndMenuFont); int itemY = y+vert_layer; for (int i = topMenuItem, j = 0; j < visibleItemsMenuCount; i++, j++) { if (i == curMenuItemIndex) { if (mode == DMS_DRAW) { g.setColor(getInverseColor(bkgrndColor)); g.fillRect(x, itemY-1, width+1, fontHeight+2); } } itemY += fontHeight; } itemY = y+vert_layer; for (int i = topMenuItem, j = 0; j < visibleItemsMenuCount; i++, j++) { Command cmd = (Command)items.elementAt(i); switch (mode) { case DMS_DRAW: g.setColor((i == curMenuItemIndex) ? bkgrndColor : textColor); g.drawString(cmd.getLabel(), x+layer, itemY, Graphics.LEFT|Graphics.TOP); break; //#sijapp cond.if target is "MIDP2"# case DMS_CLICK: if (ptInRect(curX, curY, x, itemY, x+width, itemY+fontHeight)) { uiState = UI_STATE_NORMAL; invalidate(); executeCommand(cmd); return true; } break; //#sijapp cond.end# } itemY += fontHeight; } // Draw rectangle if (mode == DMS_DRAW) { g.setColor(textColor); g.drawRect(x, y, width, height); } return false; } static private void sortMenuItems(Vector items) { int size = items.size()-1; boolean swaped; do { swaped = false; for (int i = 0; i < size; i++) { Command cmd1 = (Command)items.elementAt(i); Command cmd2 = (Command)items.elementAt(i+1); if (cmd1.getPriority() < cmd2.getPriority()) { items.setElementAt(cmd2, i); items.setElementAt(cmd1, i+1); swaped = true; } } } while (swaped); } //#sijapp cond.end# //#sijapp cond.if target="MOTOROLA" | target="MIDP2"# private static boolean manualBackLight = false; private static int backLightTimeOut = 5; private static boolean backLightIsOn = false; public static void setBackLightData(boolean manualBackLight, int backLightTimeOut) { VirtualList.manualBackLight = manualBackLight; VirtualList.backLightTimeOut = backLightTimeOut; } private static void setBackLightOn() { if (!manualBackLight) return; virtualCanvas.getDisplay().flashBacklight(1000*backLightTimeOut); //System.out.println("VirtualList.setBackLightOn()"); } //#sijapp cond.end # public static int getCanvasWidth() { return virtualCanvas.getWidth(); } public static int getCanvasHeight() { return virtualCanvas.getHeight(); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -