?? virtuallist.java.svn-base
字號:
drawItemData(g, i, x1, y1, x2, y2, mode); } //#sijapp cond.if target is "MIDP2"# else { if ((y1 < mouseY) && (mouseY < y2) && (x1 < mouseX) && (mouseX < x2)) { switch (mode) { case DMS_CLICK: if (currItem != i) { currItem = i; if (vlCommands != null) vlCommands.vlCursorMoved(this); invalidate(); } break; case DMS_DBLCLICK: itemSelected(); break; } pointerPressedOnUtem(i, mouseX-x1, mouseY-y1, mode); return true; } } //#sijapp cond.end# y += itemHeight; if (y >= bottomY) break; } return false; } private void drawCursor(Graphics g, int topY, int clipY1, int clipY2, int size, int bottomY) { int i; int y; int grCursorY1 = -1; int grCursorY2 = -1; getCurXVals(curXVals); int curX1 = curXVals[0]; int curX2 = curXVals[1]; // Draw cursor y = topY; int itemHeight = 0; for (i = topItem; i < size; i++) { itemHeight = getItemHeight(i); if (isItemSelected(i)) { if (grCursorY1 == -1) grCursorY1 = y; grCursorY2 = y + itemHeight; } y += itemHeight; if (y >= bottomY) break; } if ((grCursorY1 != -1) && crdIntersect(grCursorY1-3, grCursorY2+2, clipY1, clipY2)) { grCursorY1--; drawRect(g, cursorColor, cursorColor, curX1, grCursorY1, curX2, grCursorY2, cursorAlpha); g.setColor(cursorFrameColor); boolean isCursorUpper = (topItem >= 1) ? isItemSelected(topItem - 1) : false; if (!isCursorUpper) g.fillRect(curX1-curFrameWidth+1, grCursorY1-curFrameWidth+1, curX2-curX1+2*curFrameWidth-2, curFrameWidth); g.fillRect(curX1-curFrameWidth, grCursorY1-curFrameWidth+2, curFrameWidth, grCursorY2-grCursorY1+2*curFrameWidth-3); g.fillRect(curX2, grCursorY1-curFrameWidth+2, curFrameWidth, grCursorY2-grCursorY1+2*curFrameWidth-3); g.fillRect(curX1-curFrameWidth+1, grCursorY2, curX2-curX1+2*curFrameWidth-2, curFrameWidth); g.setColor(mergeColors(cursorFrameColor, cursorColor, 50)); if (!isCursorUpper) { g.fillRect(curX1, grCursorY1+1, 1, 1); g.fillRect(curX1, grCursorY2-1, 1, 1); } g.fillRect(curX2-1, grCursorY1+1, 1, 1); g.fillRect(curX2-1, grCursorY2-1, 1, 1); } } static protected boolean crdContains(int crd, int crd1, int crd2) { return (crd1 <= crd) && (crd <= crd2); } static protected boolean crdIntersect(int a1, int a2, int b1, int b2) { if ((a1 == -1) || (a2 == -1) || (b1 == -1) || (b2 == -1)) return true; return crdContains(a1, b1, b2) || crdContains(a2, b1, b2) || crdContains(b1, a1, a2) || crdContains(b2, a1, a2); } void destroy() { } // change light of color static public int transformColorLight(int color, int light) { int r = (color & 0xFF) + light; int g = ((color & 0xFF00) >> 8) + light; int b = ((color & 0xFF0000) >> 16) + light; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; return r | (g << 8) | (b << 16); } static public int mergeColors(int color1, int color2, int value) { int r1 = (color1 & 0xFF); int g1 = ((color1 & 0xFF00) >> 8); int b1 = ((color1 & 0xFF0000) >> 16); int r2 = (color2 & 0xFF); int g2 = ((color2 & 0xFF00) >> 8); int b2 = ((color2 & 0xFF0000) >> 16); int r = value*(r2-r1)/100+r1; int g = value*(g2-g1)/100+g1; int b = value*(b2-b1)/100+b1; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; return (r) | (g << 8) | (b << 16); } static public int getInverseColor(int color) { int r = color & 0xFF; int g = (color >> 8) & 0xFF; int b = (color >> 16) & 0xFF; return ((r+g+b) > 300) ? 0 : 0xFFFFFF; } public void paintAllOnGraphics(Graphics graphics) { paintAllOnGraphics(graphics, DMS_DRAW, -1, -1); } public static void drawBgImage(Image backImage, int scrWidth, int scrHeight, Graphics graphics, boolean cave) { if (cave) { int imgWidth = backImage.getWidth(); int imgHeight = backImage.getHeight(); for (int xx = 0; xx < scrWidth; xx += imgWidth) for (int yy = 0; yy < scrHeight; yy += imgHeight) graphics.drawImage(backImage, xx, yy, Graphics.LEFT|Graphics.TOP); } else { graphics.drawImage(backImage, scrWidth/2, scrHeight/2, Graphics.HCENTER|Graphics.VCENTER); } } public void paintAllOnGraphics(Graphics graphics, int mode, int mouseX, int mouseY) { int y; int height = getHeightInternal(); int capHeight = getCapHeight(); int visCount = getVisCount(); int menuBarHeight; boolean clicked; //#sijapp cond.if target="RIM" | target="DEFAULT"# menuBarHeight = 0;//#sijapp cond.else# menuBarHeight = getMenuBarHeight();//#sijapp cond.end# switch (mode) { case DMS_DRAW: int clipY1 = graphics.getClipY(); int clipY2 = clipY1+graphics.getClipHeight(); y = capHeight; // Fill background //#sijapp cond.if target!="DEFAULT"# if (backImage == null || !caveBgImage) { //#sijapp cond.end# graphics.setColor(bkgrndColor); int realY1 = Math.max(y, clipY1); int realY2 = Math.min(y+getDrawHeight(), clipY2); graphics.fillRect(0, realY1, getWidthInternal()-scrollerWidth, realY2-realY1); //#sijapp cond.if target!="DEFAULT"# } if (backImage != null && mode == DMS_DRAW) drawBgImage(backImage, getWidth(), getHeight(), graphics, caveBgImage); //#sijapp cond.end# drawCaption(graphics, mode, mouseX, mouseY); if (mode == DMS_DRAW) drawCursor(graphics, y, clipY1, clipY2, getSize(), y+getDrawHeight()); drawItems(graphics, y, menuBarHeight, mode, mouseX, mouseY, clipY1, clipY2); drawScroller(graphics, y, visCount, menuBarHeight);//#sijapp cond.if target!="RIM" & target!="DEFAULT"# if (menuBarHeight != 0) { int barY = height-menuBarHeight; if (clipY2 >= barY) drawMenuBar(graphics, menuBarHeight, mode, mouseX, mouseY); } drawMenuItems(graphics, menuBarHeight, mode, mouseX, mouseY);//#sijapp cond.end# break; //#sijapp cond.if target is "MIDP2"# case DMS_CLICK: case DMS_DBLCLICK: y = capHeight; if (menuBarHeight != 0) { clicked = drawMenuBar(graphics, menuBarHeight, mode, mouseX, mouseY); if (clicked) return; } clicked = drawMenuItems(graphics, menuBarHeight, mode, mouseX, mouseY); if (clicked) return; clicked = drawItems(graphics, y, menuBarHeight, mode, mouseX, mouseY, -1, -1); if (clicked) return; break;//#sijapp cond.end# } } static private Image bDIimage = null; // protected void paint(Graphics g) protected void paint(Graphics g) { if (dontRepaint) return; if (virtualCanvas.isDoubleBuffered()) { paintAllOnGraphics(g, DMS_DRAW, -1, -1); } else { try { if (bDIimage == null) bDIimage = Image.createImage(getWidthInternal(), getHeightInternal()); paintAllOnGraphics(bDIimage.getGraphics(), DMS_DRAW, -1, -1); g.drawImage(bDIimage, 0, 0, Graphics.TOP | Graphics.LEFT); } catch (Exception e) { paintAllOnGraphics(g, DMS_DRAW, -1, -1); } } } // protected void drawItemData protected void drawItemData(Graphics g, int index, int x1, int y1, int x2, int y2, int paintMode) { paintedItem.clear(); get(index, paintedItem); int x = paintedItem.horizOffset+x1; // Draw first left image if (paintedItem.leftImage != null) { g.drawImage ( paintedItem.leftImage, x, (y1 + y2 - paintedItem.leftImage.getHeight()) / 2, Graphics.TOP | Graphics.LEFT ); x += (paintedItem.leftImage.getWidth()+1); } // Draw second left image if (paintedItem.secondLeftImage != null) { g.drawImage ( paintedItem.secondLeftImage, x, (y1 + y2 - paintedItem.secondLeftImage.getHeight()) / 2, Graphics.TOP | Graphics.LEFT ); x += (paintedItem.secondLeftImage.getWidth()+1); } // Draw text of item if (paintedItem.text != null) { Font font = getQuickFont(paintedItem.fontStyle); g.setFont(font); g.setColor(paintedItem.color); g.drawString(paintedItem.text, x+1, (y1 + y2 - font.getHeight()) / 2, Graphics.TOP | Graphics.LEFT); } // Draw right image if (paintedItem.rightImage != null) { g.drawImage ( paintedItem.rightImage, x2-paintedItem.rightImage.getWidth(), (y1 + y2 - paintedItem.rightImage.getHeight()) / 2, Graphics.TOP | Graphics.LEFT ); } } public void lock() { dontRepaint = true; } protected void afterUnlock() { } public void unlock() { dontRepaint = false; afterUnlock(); invalidate(); } protected boolean getLocked() { return dontRepaint; } private int forcedWidth = -1; private int forcedHeight = -1; public void setForcedSize(int width, int height) { forcedWidth = width; forcedHeight = height; } protected int getHeightInternal() { return (forcedHeight == -1) ? virtualCanvas.getHeight() : forcedHeight; } protected int getWidthInternal() { return (forcedWidth == -1) ? virtualCanvas.getWidth() : forcedWidth; } public int getWidth() { return virtualCanvas.getWidth(); } public int getHeight() { return virtualCanvas.getHeight(); } protected void onShow() {} protected void onHide() {} /////////////////////////////// // // // EXTENDED UI // // // /////////////////////////////// public static final int MENU_TYPE_LEFT_BAR = 1; public static final int MENU_TYPE_RIGHT_BAR = 2; public static final int MENU_TYPE_LEFT = 3; public static final int MENU_TYPE_RIGHT = 4; protected static final int DMS_DRAW = 1; protected static final int DMS_CLICK = 2; protected static final int DMS_DBLCLICK = 3; protected static final int DMS_CUSTOM = 4; protected Command findMenuByType(int type) {//#sijapp cond.if target="RIM" | target="DEFAULT"# for (int i = commands.size()-1; i >= 0; i--) { Command cmd = (Command)commands.elementAt(i); if (cmd.getCommandType() == type) return cmd; }//#sijapp cond.else# if ((leftMenu != null) && (leftMenu.getCommandType() == type)) return leftMenu; if ((rightMenu != null) && (rightMenu.getCommandType() == type)) return rightMenu; for (int i = leftMenuItems.size()-1; i >= 0; i--) { Command cmd = (Command)leftMenuItems.elementAt(i); if (cmd.getCommandType() == type) return cmd; } for (int i = rightMenuItems.size()-1; i >= 0; i--) { Command cmd = (Command)rightMenuItems.elementAt(i); if (cmd.getCommandType() == type) return cmd; }//#sijapp cond.end# return null; } public void addCommandEx(Command cmd, int type) {//#sijapp cond.if target="RIM" | target="DEFAULT"# commands.addElement(cmd); if (virtualCanvas.currentControl == this) virtualCanvas.addCommand(cmd);//#sijapp cond.else# if (mirrorMenu) { switch (type) { case MENU_TYPE_LEFT_BAR: type = MENU_TYPE_RIGHT_BAR; break; case MENU_TYPE_RIGHT_BAR: type = MENU_TYPE_LEFT_BAR; break; case MENU_TYPE_LEFT: type = MENU_TYPE_RIGHT; break; case MENU_TYPE_RIGHT: type = MENU_TYPE_LEFT; break; } } switch (type) { case MENU_TYPE_LEFT_BAR: leftMenu = cmd; invalidate(); break; case MENU_TYPE_RIGHT_BAR: rightMenu = cmd; invalidate(); break; case MENU_TYPE_LEFT: if (leftMenuItems.indexOf(cmd) == -1) { leftMenuItems.addElement(cmd); leftMenuItemsSorted = false; } break; case MENU_TYPE_RIGHT: if (rightMenuItems.indexOf(cmd) == -1) { rightMenuItems.addElement(cmd); rightMenuItemsSorted = false; } break; } //#sijapp cond.end# } public void removeCommandEx(Command cmd) {//#sijapp cond.if target="RIM" | target="DEFAULT"# commands.removeElement(cmd); if (virtualCanvas.currentControl == this) virtualCanvas.removeCommand(cmd);//#sijapp cond.else# if (cmd == leftMenu) { leftMenu = null; leftMenuItems.removeAllElements(); invalidate(); return;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -