gauge.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 747 行 · 第 1/3 页
JAVA
747 行
/** * Creates a new <code>Gauge</code> object with the given * label, in interactive or non-interactive mode, with the given * maximum and initial values. In interactive mode (where * <code>interactive</code> is <code>true</code>) the maximum * value must be greater than zero, otherwise an exception is * thrown. In non-interactive mode (where * <code>interactive</code> is <code>false</code>) the maximum * value must be greater than zero or equal to the special value * <code>INDEFINITE</code>, otherwise an exception is thrown. * * <p>If the maximum value is greater than zero, the gauge has * definite range. In this case the initial value must be within * the range zero to <code>maxValue</code>, inclusive. If the * initial value is less than zero, the value is set to zero. If * the initial value is greater than <code>maxValue</code>, it is * set to <code>maxValue</code>.</p> * * <p>If <code>interactive</code> is <code>false</code> and the * maximum value is <code>INDEFINITE</code>, this creates a * non-interactive gauge with indefinite range. The initial value * must be one of <code>CONTINUOUS_IDLE</code>, * <code>INCREMENTAL_IDLE</code>, <code>CONTINUOUS_RUNNING</code>, * or <code>INCREMENTAL_UPDATING</code>.</p> * * @see #INDEFINITE * @see #CONTINUOUS_IDLE * @see #INCREMENTAL_IDLE * @see #CONTINUOUS_RUNNING * @see #INCREMENTAL_UPDATING * * @param label the <code>Gauge's</code> label * @param interactive tells whether the user can change the value * @param maxValue the maximum value, or <code>INDEFINITE</code> * @param initialValue the initial value in the range * <code>[0..maxValue]</code>, or one of <code>CONTINUOUS_IDLE</code>, * <code>INCREMENTAL_IDLE</code>, <code>CONTINUOUS_RUNNING</code>, * or <code>INCREMENTAL_UPDATING</code> if <code>maxValue</code> is * <code>INDEFINITE</code>. * * @throws IllegalArgumentException if <code>maxValue</code> * is not positive for interactive gauges * @throws IllegalArgumentException if <code>maxValue</code> is * neither positive nor * <code>INDEFINITE</code> for non-interactive gauges * @throws IllegalArgumentException if initialValue is not one of * <code>CONTINUOUS_IDLE</code>, <code>INCREMENTAL_IDLE</code>, * <code>CONTINUOUS_RUNNING</code>, or <code>INCREMENTAL_UPDATING</code> * for a non-interactive gauge with indefinite range */ public Gauge(String label, boolean interactive, int maxValue, int initialValue) { super(label); if (maxValue == INDEFINITE && (initialValue < CONTINUOUS_IDLE || initialValue > INCREMENTAL_UPDATING)) { throw new IllegalArgumentException(); } synchronized (Display.LCDUILock) { this.interactive = interactive; itemLF = gaugeLF = LFFactory.getFactory().getGaugeLF(this); /** * IllegalArgumentException may be thrown by * setMaxValueImpl and setValue */ setMaxValueImpl(maxValue); setValueImpl(initialValue); } } /** * Sets the label of the <code>Item</code>. If <code>label</code> * is <code>null</code>, specifies that this item has no label. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param label the label string * @throws IllegalStateException if this <code>Item</code> is contained * within an <code>Alert</code> * @see #getLabel */ public void setLabel(String label) { if (this.owner instanceof Alert) { throw new IllegalStateException("Gauge contained within an Alert"); } super.setLabel(label); } /** * Sets the layout directives for this item. * * <p>It is illegal to call this method if this <code>Item</code> * is contained within an <code>Alert</code>.</p> * * @param layout a combination of layout directive values for this item * @throws IllegalArgumentException if the value of layout is not a valid * combination of layout directives * @throws IllegalStateException if this <code>Item</code> is * contained within an <code>Alert</code> * @see #getLayout */ public void setLayout(int layout) { if (this.owner instanceof Alert) { 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> */ 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> */ 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 */ 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> */ 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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?