gauge.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 747 行 · 第 1/3 页
JAVA
747 行
* <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) { setValueImpl(value); } } /** * 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() { synchronized (Display.LCDUILock) { return gaugeLF.lGetValue(); } } /** * 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 /** * Sets the current value of this Gauge object. * * @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 */ void setValueImpl(int value) { if (!interactive && maxValue == INDEFINITE) { switch (value) { case CONTINUOUS_IDLE: case INCREMENTAL_IDLE: case INCREMENTAL_UPDATING: case CONTINUOUS_RUNNING: break; default: throw new IllegalArgumentException(); } } if ((this.value != value) || (this.maxValue == INDEFINITE && value == INCREMENTAL_UPDATING)) { int oldValue = this.value; this.value = value; checkValue(); gaugeLF.lSetValue(oldValue, this.value); } } /** * Return whether the Item takes user input focus. * * @return return <code>true</code> if contents is interactive or have * abstract commands. */ boolean acceptFocus() { return super.acceptFocus() || interactive; } // private implementation /** * Utility method to ensure the value of the Gauge is always * in a range of 0 to maxValue, or if maxValue is INDEFINITE * that value is CONTINUOUS_IDLE, INCREMENTAL_IDLE, * INCREMENTAL_UPDATING, or CONTINUOUS_RUNNING. In the case * where maxValue is INDEFINITE and value is not one of the * three defined here it will be set to CONTINUOUS_IDLE. (0) * * private instance variable value will be within parameter * after this call */ private void checkValue() { if (maxValue == INDEFINITE) { if (value < CONTINUOUS_IDLE || value > INCREMENTAL_UPDATING) { value = CONTINUOUS_IDLE; } } else { if (value < 0) { value = 0; } else if (value > maxValue) { value = maxValue; } } } /** * Set the max value of this Gauge. * * @param maxValue The maximum value to set for this Gauge * * @throws IllegalArgumentException if maxValue is not positive for * interactive gauges * @throws IllegalArgumentException if maxValue is neither positive nor * INDEFINITE for non-interactive gauges */ private void setMaxValueImpl(int maxValue) { if (maxValue <= 0) { if (!(interactive == false && maxValue == INDEFINITE)) { throw new IllegalArgumentException(); } } int oldMaxValue = this.maxValue; this.maxValue = maxValue; if (oldMaxValue == INDEFINITE) { // oldMaxValue if (maxValue > INDEFINITE) { value = 0; } } else if (maxValue == INDEFINITE) { value = CONTINUOUS_IDLE; } checkValue(); if (oldMaxValue != maxValue) { gaugeLF.lSetMaxValue(oldMaxValue, maxValue); } } /** * The look&feel associated with this item. * Set in the constructor. */ GaugeLF gaugeLF; // = null /** The current value of this gauge */ int value; // = 0 /** The maximum possible value of this gauge */ int maxValue; // = 0 /** Whether this gauge is interactive or not */ boolean interactive; // = false}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?