gaugelfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,445 行 · 第 1/4 页
JAVA
1,445 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import java.util.TimerTask;import java.util.Timer;import javax.microedition.lcdui.game.Sprite;import com.sun.midp.chameleon.skins.ScreenSkin;import com.sun.midp.chameleon.skins.GaugeSkin;import com.sun.midp.chameleon.skins.ProgressBarSkin;import com.sun.midp.chameleon.skins.BusyCursorSkin;import com.sun.midp.chameleon.skins.UpdateBarSkin;import com.sun.midp.chameleon.skins.resources.GaugeResources;import com.sun.midp.chameleon.skins.resources.ProgressBarResources;import com.sun.midp.chameleon.skins.resources.UpdateBarResources;import com.sun.midp.chameleon.skins.resources.BusyCursorResources;import com.sun.midp.chameleon.*;import com.sun.midp.lcdui.Text;import com.sun.midp.configurator.Constants;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;/*** This is the look & feel implementation for Gauge.*/class GaugeLFImpl extends ItemLFImpl implements GaugeLF { /** * Creates GaugeLF for the passed in Gauge. * @param gauge the Gauge object associated with this look&feel. */ GaugeLFImpl(Gauge gauge) { super(gauge); this.gauge = gauge; lSetMaxValue(0, gauge.maxValue); lSetValue(0, gauge.value); // IMPL NOTE: Make this smarter so that only the // resources we need load. Also, replicate this // code in the set* methods so that a gauge which // changes on the fly has the proper resources if (gauge.interactive) { GaugeResources.load(); } else { ProgressBarResources.load(); UpdateBarResources.load(); BusyCursorResources.load(); } percentLoc = new int[2]; drawsTraversalIndicator = false; } // ***************************************************** // Public methods // ***************************************************** /** * Notifies L&F of a value change in the corresponding Gauge. * @param oldValue - the old value set in the Gauge * @param newValue - the new value set in the Gauge */ public void lSetValue(int oldValue, int newValue) { synchronized (Display.LCDUILock) { if (gauge.maxValue == Gauge.INDEFINITE) { /** * -- if there are more than one Gauge, we shouldn't * stop other continuous gauges until we change Displayable. * IMPL NOTE: see if this is the only Gauge on the form -au */ if (newValue == Gauge.CONTINUOUS_RUNNING) { // If this gauge is already visible and its new value // is changed to CONTINUOUS_RUNNING, then start update // task here. // Otherwise, delay update task creation until it becomes // visible (I.e. lCallShow is called). if (visible) { startGaugeUpdateTask(); } } else if (oldValue == Gauge.CONTINUOUS_RUNNING) { cancelGaugeUpdateTask(); } if (oldValue != newValue) lRequestInvalidate(true, true); else lRequestPaint(); } else if (oldValue != newValue) { lRequestPaint(); } } // end sync } /** * Gets the current value. * @return the current value */ public int lGetValue() { return gauge.value; } /** * Notifies L&F of a maximum value change in the corresponding Gauge * @param oldMaxValue - the old maximum value set in the Gauge * @param newMaxValue - the new maximum value set in the Gauge */ public void lSetMaxValue(int oldMaxValue, int newMaxValue) { // changing the max value will change the scale of the gauge if (oldMaxValue != newMaxValue) { lRequestInvalidate(true, true); } } // ***************************************************** // Package private methods // ***************************************************** /** * Determine if this Gauge should not be traversed to * * @return true if this Gauge should not be traversed to */ boolean shouldSkipTraverse() { // Only traverse to gauges which are interactive, or have // item-specific commands added to them return (gauge.interactive) ? false : super.shouldSkipTraverse(); } /** * Sets the content size in the passed in array. * Content is calculated based on the availableWidth. * size[WIDTH] and size[HEIGHT] should be set by this method. * @param size The array that holds Item content size and location * in Item internal bounds coordinate system. * @param availableWidth The width available for this Item */ void lGetContentSize(int size[], int availableWidth) { if (gauge.interactive) { size[WIDTH] = GaugeSkin.WIDTH; size[HEIGHT] = GaugeSkin.HEIGHT; } else if (gauge.maxValue != Gauge.INDEFINITE) { size[WIDTH] = ProgressBarSkin.WIDTH; size[HEIGHT] = ProgressBarSkin.HEIGHT; } else if ((gauge.value == Gauge.CONTINUOUS_RUNNING) || (gauge.value == Gauge.CONTINUOUS_IDLE)) { size[WIDTH] = BusyCursorSkin.WIDTH; size[HEIGHT] = BusyCursorSkin.HEIGHT; } else { size[WIDTH] = UpdateBarSkin.WIDTH; size[HEIGHT] = UpdateBarSkin.HEIGHT; } } /** * Determine if this Item should have a newline after it * * @return true if it should have a newline after */ boolean equateNLA() { if (super.equateNLA()) { return true; } return ((gauge.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Determine if this Item should have a newline before it * * @return true if it should have a newline before */ boolean equateNLB() { if (super.equateNLB()) { return true; } return ((gauge.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Handle traversal within this Gauge * * @param dir the direction of traversal * @param viewportWidth the width of the viewport * @param viewportHeight the height of the viewport * @param visRect the in/out rectangle for the internal traversal location * @return True if traversal occurred within this Gauge */ boolean uCallTraverse(int dir, int viewportWidth, int viewportHeight, int[] visRect) { super.uCallTraverse(dir, viewportWidth, viewportHeight, visRect); // If its a non-interactive gauge, there is no internal traversal // No need to lock either, we just access the boolean once. // (In fact, traverse should never be called on a non-interactive // gauge because shouldSkipTraverse() returns true in that case) if (!gauge.interactive) { return false; } // If it was an invalidate or something, just keep the focus // button where it is and reflect there is internal traversal if (dir == CustomItem.NONE) { intTraverse = true; } else { // The standard horizontal gauge's orientation is RIGHT, all // others accommodate vertical gauges and possible gauges for // right-to-left languages (which would be a LEFT orientation) switch (GaugeSkin.ORIENTATION) { // Gauge increases left to right, horizontally // (this is the default in chameleon) case Graphics.RIGHT: switch (dir) { case Canvas.LEFT: if (initialTraverse) { intTraverse = true; focusBtn = I_INC_BTN; } else { intTraverse = (focusBtn != I_DEC_BTN); focusBtn = I_DEC_BTN; } break; case Canvas.RIGHT: if (initialTraverse) { intTraverse = true; focusBtn = I_DEC_BTN; } else { intTraverse = (focusBtn != I_INC_BTN); focusBtn = I_INC_BTN; } break; case Canvas.UP: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_INC_BTN; } break; case Canvas.DOWN: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_DEC_BTN; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallTraverse, dir=" +dir); break; } break; // Gauge increases right to left, horizontally // (think of right-to-left languages) case Graphics.LEFT: switch (dir) { case Canvas.LEFT: if (initialTraverse) { intTraverse = true; focusBtn = I_DEC_BTN; } else { intTraverse = (focusBtn != I_INC_BTN); focusBtn = I_INC_BTN; } break; case Canvas.RIGHT: if (initialTraverse) { intTraverse = true; focusBtn = I_INC_BTN; } else { intTraverse = (focusBtn != I_DEC_BTN); focusBtn = I_DEC_BTN; } break; case Canvas.UP: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_DEC_BTN; } break; case Canvas.DOWN: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_INC_BTN; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallTraverse, dir=" +dir); break; } break; // Gauge increases bottom to top, vertically case Graphics.TOP: switch (dir) { case Canvas.LEFT: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_INC_BTN; } break; case Canvas.RIGHT: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_DEC_BTN; } break; case Canvas.UP: if (initialTraverse) { intTraverse = true; focusBtn = I_DEC_BTN; } else { intTraverse = (focusBtn != I_INC_BTN); focusBtn = I_INC_BTN; } break; case Canvas.DOWN: if (initialTraverse) { intTraverse = true; focusBtn = I_INC_BTN; } else { intTraverse = (focusBtn != I_DEC_BTN); focusBtn = I_DEC_BTN; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?