📄 item.java
字号:
* * @param g the Graphics object to be used for rendering the item * @param w current width of the item in pixels * @param h current height of the item in pixels */ abstract void callPaint(Graphics g, int w, int h); /** * Called by subclasses to repaint this entire Item's bounds */ void repaint() { if (bounds != null) { repaint(0, 0, bounds[WIDTH], bounds[HEIGHT]); } } /** * Called by subclasses to repaint a portion of this Item's bounds * * @param x the x coordinate of the origin of the dirty region * @param y the y coordinate of the origin of the dirty region * @param w the width of the dirty region * @param h the height of the dirty region */ void repaint(int x, int y, int w, int h) { if (owner != null) { if (x < 0) { x = 0; } else if (x > bounds[WIDTH]) { return; } if (y < 0) { y = 0; } else if (y > bounds[HEIGHT]) { return; } if (w < 0) { w = 0; } else if (w > bounds[WIDTH]) { w = bounds[WIDTH]; } if (h < 0) { h = 0; } else if (h > bounds[HEIGHT]) { h = bounds[HEIGHT]; } owner.repaintItem(this, x, y, w, h); } } /** * Called by subclasses to paint this Item's label * * @param g the graphics to draw to * @param width the allowable width for the label * @return the vertical offset of the label, if it was painted, 0 * if it was not */ int paintLabel(Graphics g, int width) { int labelHeight = getLabelHeight(width); if (LABEL_BOLD_ON_TRAVERSE) { Text.paint(label, hasFocus ? LABEL_FONT: Screen.CONTENT_FONT, g, width, labelHeight, 0, Text.NORMAL, null); } else { Text.paint(label, LABEL_FONT, g, width, labelHeight, 0, Text.NORMAL, null); } return labelHeight; } /** * Called by the system to indicate the size available to this Item * has changed * * @param w the new width of the item's content area * @param h the new height of the item's content area */ void callSizeChanged(int w, int h) { } /** * Called by subclass code to indicate to the system that it has * either modified its size requirements or performed an internal * traversal */ void invalidate() { synchronized (Display.LCDUILock) { if (owner != null) { owner.invalidate(this); } } } /** * Called by the system * * <p>The default implementation of the traverse() method always returns * false.</p> * * @param dir the direction of traversal * @param viewportWidth the width of the container's viewport * @param viewportHeight the height of the container's viewport * @param visRect_inout passes the visible rectangle into the method, and * returns the updated traversal rectangle from the method * @return true if internal traversal had occurred, false if traversal * should proceed out * * @see #getInteractionModes * @see #traverseOut * @see #TRAVERSE_HORIZONTAL * @see #TRAVERSE_VERTICAL */ boolean callTraverse(int dir, int viewportWidth, int viewportHeight, int[] visRect_inout) { hasFocus = true; return false; } /** * Called by the system to indicate traversal has left this Item * * @see #getInteractionModes * @see #traverse * @see #TRAVERSE_HORIZONTAL * @see #TRAVERSE_VERTICAL */ void callTraverseOut() { hasFocus = false; } /** * 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) { } /** * Called by the system to signal a key typed * * @param c The character entered from the QWERTY keyboard */ void callKeyTyped(char c) { } /** * Called by the system to signal a key release * * @param keyCode the key code of the key that has been released * @see #getInteractionModes */ void callKeyReleased(int keyCode) { } /** * Called by the system to signal a key repeat * * @param keyCode the key code of the key that has been repeated * @see #getInteractionModes */ void callKeyRepeated(int keyCode) { } /** * Called by the system to signal a pointer press * * @param x the x coordinate of the pointer down * @param y the y coordinate of the pointer down * * @see #getInteractionModes */ void callPointerPressed(int x, int y) { } /** * Called by the system to signal a pointer release * * @param x the x coordinate of the pointer up * @param y the x coordinate of the pointer up * * @see #getInteractionModes */ void callPointerReleased(int x, int y) {} /** * Called by the system to signal a pointer drag * * @param x the x coordinate of the pointer drag * @param y the x coordinate of the pointer drag * * @see #getInteractionModes */ void callPointerDragged(int x, int y) { } /** * Called by the system to notify this Item it is being shown * * <p>The default implementation of this method updates * the 'visible' state */ void callShowNotify() { this.visible = true; } /** * Called by the system to notify this Item it is being hidden * * <p>The default implementation of this method updates * the 'visible' state */ void callHideNotify() { this.visible = false; } /** * Draw a Button Border around this Item when in Button Mode * * @param g The Graphics context to paint to * @param x x co-ordinate of the Button Border * @param y y co-ordinate of the Button Border * @param w width of the Button Border * @param h height of the Button Border * @param hasFocus A flag indicating this Item has focus or not */ void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean hasFocus) { g.setColor(hasFocus ? DARK_GRAY_COLOR : LIGHT_GRAY_COLOR); g.fillRect(x, y, w, BUTTON_BORDER); g.fillRect(x, y, BUTTON_BORDER, h); g.setColor(hasFocus ? LIGHT_GRAY_COLOR : DARK_GRAY_COLOR); g.fillTriangle(x, y + h, x + BUTTON_BORDER, y + h - BUTTON_BORDER, x + BUTTON_BORDER, y + h); g.fillRect(x + BUTTON_BORDER, y + h - BUTTON_BORDER, w - BUTTON_BORDER, BUTTON_BORDER); g.fillTriangle(x + w, y, x + w - BUTTON_BORDER, y + BUTTON_BORDER, x + w, y + BUTTON_BORDER); g.fillRect(x + w - BUTTON_BORDER, y + BUTTON_BORDER, BUTTON_BORDER, h - BUTTON_BORDER); g.setColor(Display.FG_COLOR); } /** * Adds a context sensitive Command to the item. * @param cmd the command to be removed */ void addCommandImpl(Command cmd) { // LCDUI Lock must be acquired // prior to calling this method. if (cmd == null) { throw new NullPointerException(); } for (int i = 0; i < numCommands; ++i) { if (commands[i] == cmd) { return; } } if ((commands == null) || (numCommands == commands.length)) { Command[] newCommands = new Command[numCommands + 4]; if (commands != null) { System.arraycopy(commands, 0, newCommands, 0, numCommands); } commands = newCommands; } commands[numCommands] = cmd; ++numCommands; if (owner != null) { owner.updateCommandSet(); } } /** * Removes the context sensitive command from item. * @param cmd the command to be removed */ void removeCommandImpl(Command cmd) { // LCDUI Lock must be acquired // prior to calling this method. for (int i = 0; i < numCommands; ++i) { if (commands[i] == cmd) { commands[i] = commands[--numCommands]; commands[numCommands] = null; if (cmd == defaultCommand) { defaultCommand = null; } if (owner != null) { owner.updateCommandSet(); } break; } } } /** * Gets the set of Commands that have been added to this Item * * @return Command[] The array of Commands added to this Item */ Command[] getCommands() { return commands; } /** * Gets the number of commands that have been added to this Item * * @return int The number of commands that have been added to this * Item */ int getCommandCount() { return numCommands; } /** * Gets ItemCommandListener for this Item * @return ItemCommandListener The ItemCommandListener for this Item */ ItemCommandListener getItemCommandListener() { return commandListener; } /** * Get the owner of this Item * * @return Screen The owner of this Item */ final Screen getOwner() { return owner; } /** * Set the Screen owner of this Item * * @param owner The Screen containing this Item */ void setOwner(Screen owner) { synchronized (Display.LCDUILock) { if (this.owner != null && owner != null) { throw new IllegalStateException(); } this.owner = owner; } } /** * Set the layout type of this Item * * @param layout The layout type. */ void setLayoutImpl(int layout) { if ((layout & ~VALID_LAYOUT) != 0) { throw new IllegalArgumentException(); } this.layout = layout; } /** * Get the effective layout type of this Item * * @return layout The translated layout type. */ int callGetLayout() { int l = this.layout; if (l == LAYOUT_DEFAULT) { return LAYOUT_TOP | LAYOUT_LEFT; } else { return l; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -