📄 gauge.java
字号:
throw new IllegalStateException("Gauge contained within an Alert"); } super.setLayout(layout); } /** * Adds a context sensitive <code>Command</code> to the item. * The semantic type of * <code>Command</code> should be <code>ITEM</code>. The implementation * will present the command * only when the the item is active, for example, highlighted. * <p> * If the added command is already in the item (tested by comparing the * object references), the method has no effect. If the item is * actually visible on the display, and this call affects the set of * visible commands, the implementation should update the display as soon * as it is feasible to do so. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param cmd the command to be added * @throws IllegalStateException if this <code>Item</code> is contained * within an <code>Alert</code> * @throws NullPointerException if cmd is <code>null</code> * @since MIDP 2.0 */ public void addCommand(Command cmd) { if (this.owner instanceof Alert) { throw new IllegalStateException("Gauge contained within an Alert"); } super.addCommand(cmd); } /** * Sets a listener for <code>Commands</code> to this Item, * replacing any previous * <code>ItemCommandListener</code>. A <code>null</code> reference * is allowed and has the effect of * removing any existing listener. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param l the new listener, or <code>null</code>. * @throws IllegalStateException if this <code>Item</code> is contained * within an <code>Alert</code> * @since MIDP 2.0 */ public void setItemCommandListener(ItemCommandListener l) { if (this.owner instanceof Alert) { throw new IllegalStateException("Gauge contained within an Alert"); } super.setItemCommandListener(l); } /** * Sets the preferred width and height for this <code>Item</code>. * Values for width and height less than <code>-1</code> are illegal. * If the width is between zero and the minimum width, inclusive, * the minimum width is used instead. * If the height is between zero and the minimum height, inclusive, * the minimum height is used instead. * * <p>Supplying a width or height value greater than the minimum width or * height <em>locks</em> that dimension to the supplied * value. The implementation may silently enforce a maximum dimension for * an <code>Item</code> based on factors such as the screen size. * Supplying a value of * <code>-1</code> for the width or height unlocks that dimension. * See <a href="#sizes">Item Sizes</a> for a complete discussion.</p> * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param width the value to which the width should be locked, or * <code>-1</code> to unlock * @param height the value to which the height should be locked, or * <code>-1</code> to unlock * @throws IllegalArgumentException if width or height is less than * <code>-1</code> * @throws IllegalStateException if this <code>Item</code> is contained * within an <code>Alert</code> * @see #getPreferredHeight * @see #getPreferredWidth * @since MIDP 2.0 */ public void setPreferredSize(int width, int height) { if (this.owner instanceof Alert) { throw new IllegalStateException("Gauge contained within an Alert"); } super.setPreferredSize(width, height); } /** * Sets default <code>Command</code> for this <code>Item</code>. * If the <code>Item</code> previously had a * default <code>Command</code>, that <code>Command</code> * is no longer the default, but it * remains present on the <code>Item</code>. * * <p>If not <code>null</code>, the <code>Command</code> object * passed becomes the default <code>Command</code> * for this <code>Item</code>. If the <code>Command</code> object * passed is not currently present * on this <code>Item</code>, it is added as if {@link #addCommand} * had been called * before it is made the default <code>Command</code>.</p> * * <p>If <code>null</code> is passed, the <code>Item</code> is set to * have no default <code>Command</code>. * The previous default <code>Command</code>, if any, remains present * on the <code>Item</code>. * </p> * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param cmd the command to be used as this <code>Item's</code> default * <code>Command</code>, or <code>null</code> if there is to * be no default command * * @throws IllegalStateException if this <code>Item</code> is contained * within an <code>Alert</code> * @since MIDP 2.0 */ public void setDefaultCommand(Command cmd) { if (this.owner instanceof Alert) { throw new IllegalStateException("Gauge contained within an Alert"); } super.setDefaultCommand(cmd); } /** * Sets the current value of this <code>Gauge</code> object. * * <p>If the gauge is interactive, or if it is non-interactive with * definite range, the following rules apply. If the value is less than * zero, zero is used. If the current value is greater than the maximum * value, the current value is set to be equal to the maximum value. </p> * * <p> If this <code>Gauge</code> object is a non-interactive * gauge with indefinite * range, then value must be one of <code>CONTINUOUS_IDLE</code>, * <code>INCREMENTAL_IDLE</code>, <code>CONTINUOUS_RUNNING</code>, or * <code>INCREMENTAL_UPDATING</code>. * Other values will cause an exception to be thrown.</p> * * @see #CONTINUOUS_IDLE * @see #INCREMENTAL_IDLE * @see #CONTINUOUS_RUNNING * @see #INCREMENTAL_UPDATING * * @param value the new value * @throws IllegalArgumentException if value is not one of * <code>CONTINUOUS_IDLE</code>, <code>INCREMENTAL_IDLE</code>, * <code>CONTINUOUS_RUNNING</code>, or <code>INCREMENTAL_UPDATING</code> * for non-interactive gauges with indefinite range * @see #getValue */ public void setValue(int value) { synchronized (Display.LCDUILock) { if (!interactive && maxValue == INDEFINITE) { if (value != CONTINUOUS_RUNNING && this.value == CONTINUOUS_RUNNING) { cancelGaugeUpdateTask(); } switch (value) { case CONTINUOUS_IDLE: spriteInUse = CONTINUOUS_SPRITE; spriteInUse.setFrameSequence(IDLE_SEQUENCE); break; case INCREMENTAL_IDLE: spriteInUse = INCREMENTAL_SPRITE; spriteInUse.setFrameSequence(IDLE_SEQUENCE); break; case INCREMENTAL_UPDATING: if (spriteInUse != INCREMENTAL_SPRITE || spriteInUse.getFrameSequenceLength() == 1) { spriteInUse = INCREMENTAL_SPRITE; spriteInUse.setFrameSequence(ACTIVE_SEQUENCE); } else { spriteInUse.nextFrame(); } break; case CONTINUOUS_RUNNING: if (spriteInUse != CONTINUOUS_SPRITE || spriteInUse.getFrameSequenceLength() == 1) { spriteInUse = CONTINUOUS_SPRITE; spriteInUse.setFrameSequence(ACTIVE_SEQUENCE); } if (updateHelper == null) { startGaugeUpdateTask(spriteInUse); } break; default: throw new IllegalArgumentException(); } } this.value = value; checkValue(); repaint(); } } /** * Gets the current value of this <code>Gauge</code> object. * * <p> If this <code>Gauge</code> object is a non-interactive * gauge with indefinite * range, the value returned will be one of <code>CONTINUOUS_IDLE</code>, * <code>INCREMENTAL_IDLE</code>, <code>CONTINUOUS_RUNNING</code>, or * <code>INCREMENTAL_UPDATING</code>. Otherwise, it will be an integer * between zero and the gauge's maximum value, inclusive.</p> * * @see #CONTINUOUS_IDLE * @see #INCREMENTAL_IDLE * @see #CONTINUOUS_RUNNING * @see #INCREMENTAL_UPDATING * * @return current value of the <code>Gauge</code> * @see #setValue */ public int getValue() { // SYNC NOTE: return of atomic value, no locking necessary return value; } /** * Sets the maximum value of this <code>Gauge</code> object. * * <p>For interactive gauges, the new maximum value must be greater than * zero, otherwise an exception is thrown. For non-interactive gauges, * the new maximum value must be greater than zero or equal to the special * value <code>INDEFINITE</code>, otherwise an exception is thrown. </p> * * <p>If the new maximum value is greater than zero, this provides the * gauge with a definite range. If the gauge previously had a definite * range, and if the current value is greater than new maximum value, the * current value is set to be equal to the new maximum value. If the * gauge previously had a definite range, and if the current value is less * than or equal to the new maximum value, the current value is left * unchanged. </p> * * <p>If the new maximum value is greater than zero, and if the gauge had * previously had indefinite range, this new maximum value provides it * with a definite range. Its graphical representation must change * accordingly, the previous state of <code>CONTINUOUS_IDLE</code>, * <code>INCREMENTAL_IDLE</code>, <code>CONTINUOUS_RUNNING</code>, or * <code>INCREMENTAL_UPDATING</code> is ignored, and the current value * is set to zero. </p> * * <p>If this gauge is non-interactive and the new maximum value is * <code>INDEFINITE</code>, this gives the gauge indefinite range. * If the gauge * previously had a definite range, its graphical representation must * change accordingly, the previous value is ignored, and the current * state is set to <code>CONTINUOUS_IDLE</code>. If the gauge previously * had an indefinite range, setting the maximum value to * <code>INDEFINITE</code> will have no effect. </p> * * @see #INDEFINITE * * @param maxValue the new maximum value * * @throws IllegalArgumentException if <code>maxValue</code> is invalid * @see #getMaxValue */ public void setMaxValue(int maxValue) { synchronized (Display.LCDUILock) { setMaxValueImpl(maxValue); } } /** * Gets the maximum value of this <code>Gauge</code> object. * * <p>If this gauge is interactive, the maximum value will be a positive * integer. If this gauge is non-interactive, the maximum value will be a * positive integer (indicating that the gauge has definite range) * or the special value <code>INDEFINITE</code> (indicating that * the gauge has * indefinite range).</p> * * @see #INDEFINITE * * @return the maximum value of the <code>Gauge</code>, or * <code>INDEFINITE</code> * @see #setMaxValue */ public int getMaxValue() { // SYNC NOTE: return of atomic value, no locking necessary return maxValue; } /** * Tells whether the user is allowed to change the value of the * <code>Gauge</code>. * * @return a boolean indicating whether the <code>Gauge</code> is * interactive */ public boolean isInteractive() { // SYNC NOTE: return of atomic value, no locking necessary return interactive; } // package private implementation /** * 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 ((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 ((layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Return the minimum width for this guage * * @return the minimum width */ int callMinimumWidth() { return DEFAULT_WIDTH; } /** * Return the preferred width for this gauge for the given height * * @param h the height to compute the width for * @return the preferred width for the given height */ int callPreferredWidth(int h) { return DEFAULT_WIDTH; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -