📄 imageitem.java
字号:
if (numCommands >= 1) { if (this.appearanceMode == Item.BUTTON) { return img.getHeight() + getLabelHeight(w) + (BUTTON_BORDER + BUTTON_PAD) * 2; } else if (this.appearanceMode == Item.HYPERLINK) { return img.getHeight() + getLabelHeight(w) + (HYPERLINK_IMG.getHeight() + HYPERLINK_PAD) * 2; } } return img.getHeight() + getLabelHeight(w); } /** * Paint this ImageItem * * @param g the Graphics context to paint to * @param width the width of this ImageItem * @param height the height of this ImageItem */ void callPaint(Graphics g, int width, int height) { int labelHeight = super.paintLabel(g, width); if (img == null) { return; } int x = 0; int y = labelHeight; int l = getLayout() & ImageItem.LAYOUT_CENTER; if (l == ImageItem.LAYOUT_CENTER) { x = width / 2; if ((numCommands >= 1) && (this.appearanceMode == Item.BUTTON)) { x += BUTTON_BORDER + BUTTON_PAD; y += BUTTON_BORDER + BUTTON_PAD; } else if ((numCommands >= 1) && (this.appearanceMode == Item.HYPERLINK)) { x += VERTICAL_HYPERLINK_IMG.getWidth() + HYPERLINK_PAD; y += HYPERLINK_IMG.getHeight() + HYPERLINK_PAD; } g.drawImage(img, x, y, Graphics.TOP | Graphics.HCENTER); } else if (l == ImageItem.LAYOUT_RIGHT) { x = width; if ((numCommands >= 1) && (this.appearanceMode == Item.BUTTON)) { x -= (BUTTON_BORDER + BUTTON_PAD); y += BUTTON_BORDER + BUTTON_PAD; } else if ((numCommands >= 1) && (this.appearanceMode == Item.HYPERLINK)) { x -= VERTICAL_HYPERLINK_IMG.getWidth() + HYPERLINK_PAD; y += HYPERLINK_IMG.getHeight() + HYPERLINK_PAD; } g.drawImage(img, x, y, Graphics.TOP | Graphics.RIGHT); } else { // use x = 0; if ((numCommands >= 1) && (this.appearanceMode == Item.BUTTON)) { x += BUTTON_BORDER + BUTTON_PAD; y += BUTTON_BORDER + BUTTON_PAD; } else if ((numCommands >= 1) && (this.appearanceMode == Item.HYPERLINK)) { x += VERTICAL_HYPERLINK_IMG.getWidth() + HYPERLINK_PAD; y += HYPERLINK_IMG.getHeight() + HYPERLINK_PAD; } g.drawImage(img, x, y, Graphics.TOP | Graphics.LEFT); } // draw the button border or hyperlink image if ((numCommands >= 1) && (this.appearanceMode == Item.BUTTON)) { int w = img.getWidth(); int h = img.getHeight(); // y = labelHeight + vertPad/2; y = labelHeight; if (l == ImageItem.LAYOUT_CENTER) { x = (width / 2) - (w / 2); } else if (l == ImageItem.LAYOUT_RIGHT) { x = width - w - 2 * (BUTTON_BORDER + BUTTON_PAD); } else { x = 0; } w += 2 * (BUTTON_BORDER + BUTTON_PAD); h += 2 * (BUTTON_BORDER + BUTTON_PAD); drawButtonBorder(g, x, y, w, h, hasFocus); } else if ((numCommands >= 1) && (this.appearanceMode == Item.HYPERLINK)) { // NOTE: We test to see if the width of the Image // in the ImageItem is // wider than the width of the hyperlink image, // if so, we re-draw // the image offset to the right as many times as necessary // to fill the width of the Image in the ImageItem. int imageItemWidth = img.getWidth(); int imageItemHeight = img.getHeight(); y = labelHeight; if (l == ImageItem.LAYOUT_CENTER) { drawTop_BottomBorder(g, width / 2 - imageItemWidth / 2 - HYPERLINK_PAD - VERTICAL_HYPERLINK_IMG.getWidth(), width / 2 + imageItemWidth / 2 + 2 * HYPERLINK_PAD, y, y + HYPERLINK_IMG.getHeight() + imageItemHeight + 2 * HYPERLINK_PAD); drawLeft_RightBorder(g, y, y + imageItemHeight + (2 * HYPERLINK_PAD), width / 2 - imageItemWidth / 2 - VERTICAL_HYPERLINK_IMG.getHeight(), width / 2 + imageItemWidth / 2 + 2 * HYPERLINK_PAD); } else if (l == ImageItem.LAYOUT_RIGHT) { drawTop_BottomBorder(g, width - imageItemWidth - 2 * HYPERLINK_PAD - VERTICAL_HYPERLINK_IMG.getWidth(), width - VERTICAL_HYPERLINK_IMG.getWidth(), y, y + HYPERLINK_IMG.getHeight() + imageItemHeight + 2 * HYPERLINK_PAD); drawLeft_RightBorder(g, y, y + imageItemHeight + 2 * HYPERLINK_PAD, width - imageItemWidth - HYPERLINK_PAD - VERTICAL_HYPERLINK_IMG.getHeight(), width - VERTICAL_HYPERLINK_IMG.getWidth()); } else { drawTop_BottomBorder(g, 0, imageItemWidth + 2 * HYPERLINK_PAD, y, y + HYPERLINK_IMG.getHeight() + imageItemHeight + 2 * HYPERLINK_PAD); drawLeft_RightBorder(g, y, y + imageItemHeight + 2 * HYPERLINK_PAD, 0, HYPERLINK_IMG.getHeight() + imageItemWidth + 2 * HYPERLINK_PAD); } }// end if HYPERLINK } /** * Called by the system to signal a key press * * @param keyCode the key code of the key that has been pressed * @see #getInteractionModes */ void callKeyPressed(int keyCode) { if (keyCode != Display.KEYCODE_SELECT) { return; } if (getCommandCount() == 0 || commandListener == null) { return; } ItemCommandListener cl = null; Command defaultCmd = null; synchronized (Display.LCDUILock) { cl = commandListener; defaultCmd = defaultCommand; } // synchronized // SYNC NOTE: The call to the listener must occur outside // of the lock if (cl != null) { try { // SYNC NOTE: We lock on calloutLock around any calls // into application code synchronized (Display.calloutLock) { if (defaultCmd != null) { cl.commandAction(defaultCmd, this); } else { // REMINDER : Needs HI decision // either call the first command // from the command list or // invoke the menu } } } catch (Throwable thr) { Display.handleThrowable(thr); } } } /** * Adds a context sensitive Command to the image item. * @param cmd the command to be removed */ void addCommandImpl(Command cmd) { synchronized (Display.LCDUILock) { super.addCommandImpl(cmd); if ((numCommands >= 1) && (appearanceMode == Item.PLAIN)) { // restore the value of the original appearanceMode // if it is a button // otherwise simple change the appearanceMode // to a hyperlink this.appearanceMode = originalAppearanceMode == Item.BUTTON ? Item.BUTTON : Item.HYPERLINK; invalidate(); } } // synchronized } /** * Removes the context sensitive command from item. * @param cmd the command to be removed */ void removeCommandImpl(Command cmd) { synchronized (Display.LCDUILock) { super.removeCommandImpl(cmd); if ((numCommands < 1) && (appearanceMode != Item.PLAIN)) { // store value of the original appearanceMode originalAppearanceMode = this.appearanceMode; // change the appearanceMode to plain this.appearanceMode = Item.PLAIN; // size or appearance changed invalidate(); } } // synchronized } /** * Determine if Form should not traverse to this ImageItem * * @return true if Form should not traverse to this ImageItem */ boolean shouldSkipTraverse() { if ((label == null || label.length() == 0) && (img == null)) { return true; } return false; } // private /** * Set the Image for this ImageItem * * @param img The image to use for this ImageItem */ private void setImageImpl(Image img) { if (img != null && img.isMutable()) { this.mutImg = img; this.img = Image.createImage(img); // use immutable copy of img } else { this.mutImg = null; this.img = img; } } /** * Set the alternate text for this ImageItem * * @param text The alternate text for this ImageItem */ private void setAltTextImpl(String text) { this.altText = text; } /** * Draw Top and Bottom Border for showing Hyperlink ImageItem * * @param g The Graphics context to paint to * @param start start x co-ordinate of ImageItem * @param end end x co-ordinate of ImageItem * @param y1 y co-ordinate of Top ImageItem * @param y2 y co-ordinate of Bottom ImageItem */ private void drawTop_BottomBorder(Graphics g, int start, int end, int y1, int y2) { for (int x = start; x < end; x += HYPERLINK_IMG.getWidth()) { // draw the top border g.drawImage(HYPERLINK_IMG, x, y1, Graphics.TOP | Graphics.LEFT); // draw the bottom border g.drawImage(HYPERLINK_IMG, x, y2, Graphics.TOP | Graphics.LEFT); } } /** * Draw Left and Right Border for showing Hyperlink ImageItem * * @param g The Graphics context to paint to * @param start start y co-ordinate of ImageItem * @param end end y co-ordinate of ImageItem * @param x1 x co-ordinate of Left ImageItem * @param x2 x co-ordinate of Right ImageItem */ private void drawLeft_RightBorder(Graphics g, int start, int end, int x1, int x2) { for (int y = start; y < end; y += VERTICAL_HYPERLINK_IMG.getHeight()) { // draw the left border g.drawImage(VERTICAL_HYPERLINK_IMG, x1, y, Graphics.TOP | Graphics.LEFT); // draw the right border g.drawImage(VERTICAL_HYPERLINK_IMG, x2, y, Graphics.TOP | Graphics.LEFT); } } /** * The snapshot of the Image of this ImageItem; * If the Image of this ImageItem was set to a mutable Image * this variable is updated with a new snapshot each time setImage() is * called. */ private Image img; /** * If the ImageItem was created with a mutable image or its Image * was set to a mutable image, that mutable image is stored in * the mutImg variable so that ImageItem.getImage() could return it. */ private Image mutImg; /** * The alternate text of this ImageItem */ private String altText; /** * Vertical padding used for this ImageItem so that it is padded to * occupy whole number of lines. */ private int vertPad; /** * The appearance hint */ private int appearanceMode; /** The original appearance hint before switching */ private int originalAppearanceMode; /** The hyperlink pad used between Hyperlink Border and ImageItem */ private final static int HYPERLINK_PAD = 3; /** The hyperlink Image to display with the Hyperlink */ private final static Image HYPERLINK_IMG; /** The Vertical hyperlink Image to display with the Hyperlink */ private final static Image VERTICAL_HYPERLINK_IMG; static { /* * Initialize the icons necessary for hyper links. */ VERTICAL_HYPERLINK_IMG = ImmutableImage.createIcon("link_vertical.png"); HYPERLINK_IMG = ImmutableImage.createIcon("link_horizontal.png"); com.sun.midp.lcdui.Text.HYPERLINK_IMG = HYPERLINK_IMG; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -