midpwindow.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 851 行 · 第 1/2 页
JAVA
851 行
itemCmdListener, scrCommands, scrCmdCount, scrCmdListener); } /** * Set this MIDPWindow's displayable to "fullscreen" mode. This * will expand the region occupied by the current displayable to * include the area previously occupied by the title and ticker * if present * * @param onOff true if the displayable should be in fullscreen mode */ public void setFullScreen(boolean onOff) { if (onOff) { setMode(FULL_SCR_MODE); } else { setMode(NORMAL_MODE); } } /** * Update the current layout */ public void updateLayout() { resize(); requestRepaint(); } /** * Changes layout mode. * * @param mode the mode to be set */ private void setMode(int mode) { screenMode = mode; updateLayout(); } /** * Determines if window is in full screen mode. * * @return true if in full screen mode */ public boolean isInFullScreenMode() { return screenMode == FULL_SCR_MODE; } /** * Called to paint a wash over the background of this window. * Used by SoftButtonLayer when the system menu pops up, and * internally when an Alert is shown. * * @param onOff A flag indicating if the wash should be on or off */ public void paintWash(boolean onOff) { if (alertLayer.visible) { addLayer(washLayer); if (onOff) { addLayer(alertWashLayer); } else { removeLayer(alertWashLayer); // IMPL_NOTES: interface has to be fixed alertLayer.setScrollInd( ScrollIndLayer.getInstance(ScrollIndSkin.MODE)); // IMPL_NOTES: need to be removed as soon as removeLayer algorithm // takes into account layers interaction tickerLayer.addDirtyRegion(); alertLayer.addDirtyRegion(); } } else { removeLayer(alertWashLayer); if (onOff) { addLayer(washLayer); } else { removeLayer(washLayer); // IMPL_NOTES: interface has to be fixed bodyLayer.setScrollInd(ScrollIndLayer.getInstance(ScrollIndSkin.MODE)); // IMPL_NOTES: need to be removed as soon as removeLayer algorithm // takes into account layers interaction tickerLayer.addDirtyRegion(); titleLayer.addDirtyRegion(); if (ptiLayer != null) { ptiLayer.addDirtyRegion(); } } } } /** * Returns the left soft button (one). * * @return the command that's tied to the left soft button */ public Command getSoftOne() { return buttonLayer.getSoftOne(); } /** * Returns the command array tied to the right soft button (two). * * @return the command array that's tied to the right soft button */ public Command[] getSoftTwo() { return buttonLayer.getSoftTwo(); } /** * Called by soft button layer when interactive state of it * has been changed * * @param interactive if soft buttons are currently interactive. */ public void onSoftButtonInteractive(boolean interactive) { if (FULL_SCR_MODE == screenMode) { // IMPL NOTES: in full screen mode we hide/show soft button layer // depending on its interactiveness, so we should update layout updateLayout(); } } /** * Returns true if the point lies in the bounds of commnad layer * @param x the "x" coordinate of the point * @param y the "y" coordinate of the point * @return true if the point lies in the bounds of commnad layer */ public boolean belongToCmdLayers(int x, int y) { return buttonLayer.belongToCmdLayers(x,y); } /** * Set the current vertical scroll position and proportion. * * @param scrollPosition vertical scroll position. * @param scrollProportion vertical scroll proportion. * @return true if set vertical scroll occues */ public boolean setVerticalScroll(int scrollPosition, int scrollProportion) { BodyLayer layer = null; if (alertLayer.isVisible()) { layer = alertLayer; } else if (bodyLayer.isVisible()) { layer = bodyLayer; } if (layer != null && layer.setVerticalScroll(scrollPosition, scrollProportion)) { setDirty(); sizeChangedOccured = true; return true; } return false; } /** * Get the current x anchor coordinate for the body layer (the body * layer renders the contents of the current displayable). * * @return the x anchor coordinate of the body layer */ public int getBodyAnchorX() { return bodyLayer.bounds[X]; } /** * Get the current y anchor coordinate for the body layer (the body * layer renders the contents of the current displayable). * * @return the y anchor coordinate of the body layer */ public int getBodyAnchorY() { return bodyLayer.bounds[Y]; } /** * Get the current width of the body layer (the body * layer renders the contents of the current displayable). * * @return the width of the body layer */ public int getBodyWidth() { return bodyLayer.bounds[W]; } /** * Get the current height of the body layer (the body * layer renders the contents of the current displayable). * * @return the height of the body layer */ public int getBodyHeight() { return bodyLayer.bounds[H]; } /** * Get the current width of the alert layer (the body * layer renders the contents of the current displayable). * * @return the width of the alert layer */ public int getAlertWidth() { return alertLayer.bounds[W]; } /** * Get the current height of the alert layer (the body * layer renders the contents of the current displayable). * * @return the height of the alert layer */ public int getAlertHeight() { return alertLayer.bounds[H]; } /** * Utility method to determine if the given point lies within * the bounds of body layer. The point should be in the coordinate * space of this layer's containing CWindow. * * @param x the "x" coordinate of the point * @param y the "y" coordinate of the point * @return true if the coordinate lies in the bounds of this layer */ public boolean bodyContainsPoint(int x, int y) { return bodyLayer.containsPoint(x, y); } /** * MIDPWindow overrides the parent paint method in order to * do special effects such as paint a "wash" over the background * when a dialog is up. Also in an effort to call * {@link javax.microedition.lcdui.Displayable#sizeChanged } * method before painting. This implementation determine whether size * has been changed and calls <code>sizeChanged()</code> if it's so. * Anyway it invokes the base class's {@link CWindow#paint} method. * * @param g The graphics object to use to paint this MIDP window. * @param refreshQ The chameleon graphics queue. */ public void callPaint(Graphics g, CGraphicsQ refreshQ) { if (sizeChangedOccured) { if (tunnel != null) { int w = getBodyWidth(); int h = getBodyHeight(); tunnel.callSizeChanged(w, h); sizeChangedOccured = false; } } super.paint(g, refreshQ); } /** * This method is an optimization which allows Display to bypass * the Chameleon paint engine logic and directly paint an animating * canvas. Display will call this method with the graphics context * and this method will either return false, indicating the Chameleon * paint engine should not be bypassed, or will return true and will * setup the graphics context for the canvas to be painted directly. * * @param g the graphics context to setup * @return true if Chameleon's paint logic can be bypassed and the * canvas can be rendered directly. */ public boolean setGraphicsForCanvas(Graphics g) { // IMPL_NOTE: Only Canvas painting specially doesn't change dirty // state of the owner window, however it is not enough to bypass // the Chameleon paint engine. Body layer holding the Canvas // should be not overlapped by a visible layer also. if (super.dirty) { // Schedule next overlapping check bodyChecked = false; return false; } if (!bodyChecked) { bodyOverlapped = !bodyLayer.opaque || isOverlapped(bodyLayer); bodyChecked = true; } if (!bodyOverlapped) { bodyLayer.setGraphicsForCanvas(g); return true; } return false; } /** * Internal method to resize window and its content layers * according to a size changes in the loaded skins. * This is important to re-calculate whenever things such as * titles, tickers, fullscreen mode, etc. change state. */ public void resize() { super.resize(tunnel.getDisplayWidth(), tunnel.getDisplayHeight()); int oldHeight = bodyLayer.bounds[H]; int oldWidth = bodyLayer.bounds[W]; switch (screenMode) { case FULL_SCR_MODE: // TODO: scroll arrows (bar? ) indicator has to be hidden? titleLayer.visible = false; tickerLayer.visible = false; buttonLayer.visible = buttonLayer.isInteractive(); break; case NORMAL_MODE: titleLayer.visible = (titleLayer.getTitle() != null); tickerLayer.visible = (tickerLayer.getText() != null); buttonLayer.visible = true; break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "MIDPWindow: screenMode=" + screenMode); return; } for (int i = 0; i < LAST_LAYER; i++) { CLayer l = mainLayers[i]; if (l != null && l.visible) { l.update(mainLayers); } } if (bodyLayer.bounds[W] != oldWidth || bodyLayer.bounds[H] != oldHeight) { setDirty(); sizeChangedOccured = true; } } /** * Internal method to clear all current popups. This occurs if a * change of displayable occurs, as all popups are treated as belonging * to the current displayable. */ protected void clearPopups() { synchronized (super.layers) { for (CLayerElement le = super.layers.getTop(); le != null; le = le.getLower()) { CLayer l = le.getLayer(); if (l instanceof PopupLayer) { removeLayer(l); } } } } /** * Gets the "top" most Popup layer added to this body layer. * If there are no popups, this method returns null. * * @return the top most popup layer, or null if there are none. */ public PopupLayer getTopMostPopup() { synchronized (super.layers) { for (CLayerElement le = super.layers.getTop(); le != null; le = le.getLower()) { CLayer l = le.getLayer(); if (l instanceof PopupLayer) { return (PopupLayer)l; } } } return null; } /** * create new layer by id and launch addLayer() * @param id - layer id */ private void createLayer(int id) { switch (id) { case PTI_LAYER: break; case TITLE_LAYER: titleLayer = new TitleLayer(); mainLayers[id] = titleLayer; addLayer(titleLayer); break; case TICKER_LAYER: tickerLayer = new TickerLayer(); mainLayers[id] = tickerLayer ; break; case BTN_LAYER: buttonLayer = new SoftButtonLayer(tunnel); mainLayers[id] = buttonLayer; addLayer(buttonLayer); break; case ALERT_LAYER: alertLayer = new AlertLayer(tunnel); mainLayers[id] = alertLayer; break; case WASH_LAYER: washLayer = new WashLayer(); mainLayers[id] = washLayer; break; case ALERT_WASH_LAYER: alertWashLayer = new WashLayer(); mainLayers[id] = alertWashLayer; break; case KEYBOARD_LAYER: break; case BODY_LAYER: bodyLayer = new BodyLayer(tunnel); mainLayers[id] = bodyLayer; addLayer(bodyLayer); break; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?