📄 displayable.java
字号:
/** * Handle a repeated key press * * @param keyCode The key that was pressed */ void callKeyRepeated(int keyCode) { } /** * Handle a key release * * @param keyCode The key that was released */ void callKeyReleased(int keyCode) { } /** * Handle a key that was typed from the keyboard * * @param c The char that was typed */ void callKeyTyped(char c) {} /** * Handle a pointer press event * * @param x The x coordinate of the press * @param y The y coordinate of the press */ void callPointerPressed(int x, int y) { } /** * Handle a pointer drag event * * @param x The x coordinate of the drag * @param y The y coordinate of the drag */ void callPointerDragged(int x, int y) { } /** * Handle a pointer release event * * @param x The x coordinate of the release * @param y The y coordinate of the release */ void callPointerReleased(int x, int y) { } /** * Repaint this Displayable * * @param x The x coordinate of the region to repaint * @param y The y coordinate of the region to repaint * @param width The width of the region to repaint * @param height The height of the region to repaint * @param target an optional paint target to receive the paint request * when it returns via callPaint() */ final void callRepaint(int x, int y, int width, int height, Object target) { if (currentDisplay != null) { // Note: Display will not let anyone but the current // Displayable schedule repaints currentDisplay.repaintImpl(paintDelegate, x, y, width, height, target); } } /** * Repaints this Displayable. * This is the same as calling * callRepaint(0, 0, * viewport[X] + viewport[WIDTH], * viewport[Y] + viewport[HEIGHT], null) */ final void callRepaint() { callRepaint(0, 0, viewport[X] + viewport[WIDTH], viewport[Y] + viewport[HEIGHT], null); } /** * Repaint the viewport region of this Displayable */ final void repaintContents() { callRepaint(viewport[X], viewport[Y], viewport[WIDTH], viewport[HEIGHT], null); } /** * Set the vertical scroll position and proportion * * @param scrollPosition The vertical scroll position to set on a * scale of 0-100 * @param scrollProportion The vertical scroll proportion to set on * a scale of 0-100. For example, if the viewport * is 25 pixels high and the Displayable is 100 * pixels high, then the scroll proportion would * be 25, since only 25% of the Displayable can * be viewed at any one time. This proportion * value can be used by implementations which * render scrollbars to indicate scrollability * to the user. */ void setVerticalScroll(int scrollPosition, int scrollProportion) { synchronized (Display.LCDUILock) { this.vScrollPosition = scrollPosition; this.vScrollProportion = scrollProportion; if (currentDisplay != null) { currentDisplay.setVerticalScroll(scrollPosition, scrollProportion); } } } /** * Get the current vertical scroll position * * @return int The vertical scroll position on a scale of 0-100 */ int getVerticalScrollPosition() { // SYNC NOTE: return of atomic value return vScrollPosition; } /** * Get the current vertical scroll proportion * * @return ing The vertical scroll proportion on a scale of 0-100 */ int getVerticalScrollProportion() { // SYNC NOTE: return of atomic value return vScrollProportion; } /** * Notify this Displayable it is being shown on the given Display * * @param d the Display showing this Displayable */ void callShowNotify(Display d) { synchronized (Display.LCDUILock) { currentDisplay = d; // call grab full screen to let the native // layer know whether to be in // fullscreen or normal mode. grabFullScreen(fullScreenMode); if (sizeChangeOccurred) { callSizeChanged(viewport[WIDTH], viewport[HEIGHT]); } // display the ticker if we have a visible one. startTicker(); } } /** * Notify this Displayable it is being hidden on the given Display * * @param d the Display hiding this Displayable */ void callHideNotify(Display d) { synchronized (Display.LCDUILock) { currentDisplay = null; stopTicker(); } } /** * Get the set of Commands that have been added to this Displayable * * @return Command[] The array of Commands added to this Displayable */ Command[] getCommands() { return commands; } /** * Get the number of commands that have been added to this Displayable * * @return int The number of commands that have been added to this * Displayable */ int getCommandCount() { return numCommands; } /** * Gets item currently in focus. This is will be only applicable to * Form. The rest of the subclasses will return null. * @return Item The item currently in focus in this Displayable; * if there are no items in focus, null is returned */ Item getCurrentItem() { return null; } /** * Get the CommandListener for this Displayable * * @return CommandListener The CommandListener listening to Commands on * this Displayable */ CommandListener getCommandListener() { return listener; } /** * Add a Command to this Displayable * * @param cmd The Command to add to this Displayable */ void addCommandImpl(Command cmd) { 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; updateCommandSet(); } /** * Remove a Command from this Displayable * * @param cmd The Command to remove from this Displayable */ void removeCommandImpl(Command cmd) { for (int i = 0; i < numCommands; ++i) { if (commands[i] == cmd) { commands[i] = commands[--numCommands]; commands[numCommands] = null; updateCommandSet(); break; } } } /** * Updates command set if this Displayable is visible */ void updateCommandSet() { // SYNC NOTE: Display requires calls to updateCommandSet to // be synchronized synchronized (Display.LCDUILock) { if ((currentDisplay != null) && currentDisplay.isShown(this)) { currentDisplay.updateCommandSet(); } } } /** * Decide if the given Command has been added to this * Displayable's set of abstract commands. * * @param command The Command to check. This value should * never be null (no checks are made). * @return True if the Command has been previously added * via the addCommand() method */ boolean commandInSetImpl(Command command) { for (int i = 0; i < numCommands; i++) { if (commands[i] == command) { return true; } } return false; }// ************************************************************// private methods// ************************************************************ /** * Repaint the title area. */ private void repaintTitle() { if (currentDisplay != null) { currentDisplay.repaintImpl(paintDelegate, 0, (ticker != null) ? Ticker.PREFERRED_HEIGHT : 2, viewport[WIDTH], TITLE_HEIGHT, title); } } /** * Starts the "ticking" of the ticker. * */ private void startTicker() { if (ticker == null || fullScreenMode) { return; } stopTicker(); tickerPainter = new TickerPainter(); tickerTimer.schedule(tickerPainter, 0, Ticker.TICK_RATE); } /** * Stop the ticking of the ticker. * */ private void stopTicker() { if (tickerPainter == null) { return; } tickerPainter.cancel(); tickerPainter = null; } /** * Paints the ticker's text area. * */ private void repaintTickerText() { if (currentDisplay != null && currentDisplay.isShown(paintDelegate)) { currentDisplay.repaintImpl(paintDelegate, 0, Ticker.DECORATION_HEIGHT, viewport[WIDTH], Screen.CONTENT_HEIGHT, ticker); } } /** * This method is called from showNotify(Display ) * It checks if a size change has occurred since the last time * a size change occurred or since the object was constructed. * * If a size change has occurred, it calls callSizeChanged() * for package private handling of size change events, and returns true, * else returns false. * * @return true if a size change has occurred since the last size change * or since the construction of this Displayable. * false otherwise * */ private boolean sizeChangeImpl() { boolean flag = sizeChangeOccurred; sizeChangeOccurred = false; if (flag) { callSizeChanged(viewport[WIDTH], viewport[HEIGHT]); } return flag; } /** * Grabs the requested area of the display * * @param mode if true, grabs the entire display area for Canvas' * display * if false, occupies only part of the entire area * leaving space for the status and the command labels. */ native void grabFullScreen(boolean mode); // ************************************************************// Inner Class, TickerPainter// ************************************************************ /** * A special helper class to repaint the Ticker * if one has been set */ private class TickerPainter extends TimerTask { /** * Repaint the ticker area of this Screen */ public final void run() { synchronized (Display.LCDUILock) { repaintTickerText(); } } }} // Displayable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -