📄 form.java
字号:
if (this.isShown() ) {
repaint();
}
return this.container.size() - 1;
}
/**
* Adds an item consisting of one <code>String</code> to the
* <code>Form</code>. The effect of this method is identical to
* <p>
* <code>
* append(new StringItem(null, str))
* </code> </p>
*
* @param str the String to be added
* @param itemStyle the CSS style for this string
* @return the assigned index of the Item
* @throws NullPointerException if str is null
*/
public int append( String str, Style itemStyle )
{
return append( new StringItem(null, str, itemStyle), null );
}
/**
* Adds an item consisting of one <code>String</code> to the
* <code>Form</code>. The effect of
* this method is identical to
*
* <p> <code>
* append(new StringItem(null, str))
* </code> </p>
*
* @param str the String to be added
* @return the assigned index of the Item
* @throws NullPointerException if str is null
*/
public int append( String str)
{
return append( new StringItem(null, str), null );
}
/**
* Adds an item consisting of one <code>Image</code> to the
* <code>Form</code>. The effect of
* this method is identical to
*
* <p> <code>
* append(new ImageItem(null, img, ImageItem.LAYOUT_DEFAULT, null))
* </code> </p>
*
* @param img the image to be added
* @param itemStyle the CSS style for this string
* @return the assigned index of the Item
* @throws NullPointerException if img is null
*/
public int append( Image img, Style itemStyle )
{
return append(new ImageItem(null, img, Item.LAYOUT_DEFAULT, null, itemStyle), null );
}
/**
* Adds an item consisting of one <code>Image</code> to the <code>Form</code>.
* The effect of this method is identical to
* <p> <code>
* append(new ImageItem(null, img, ImageItem.LAYOUT_DEFAULT, null))
* </code> </p>
*
* @param img - the image to be added
* @return the assigned index of the Item
* @throws NullPointerException - if img is null
*/
public int append( Image img)
{
return append(new ImageItem(null, img, Item.LAYOUT_DEFAULT, null), null);
}
/**
* Inserts an item into the <code>Form</code> just prior to
* the item specified.
* The size of the <code>Form</code> grows by one. The
* <code>itemNum</code> parameter must be
* within the range <code>[0..size()]</code>, inclusive.
* The index of the last item is <code>size()-1</code>, and
* so there is actually no item whose index is
* <code>size()</code>. If this value
* is used for <code>itemNum</code>, the new item is inserted
* immediately after
* the last item. In this case, the effect is identical to
* <A HREF="../../../javax/microedition/lcdui/Form.html#append(javax.microedition.lcdui.Item)"><CODE>append(Item)</CODE></A>.
*
* <p> The semantics are otherwise identical to
* <A HREF="../../../javax/microedition/lcdui/Form.html#append(javax.microedition.lcdui.Item)"><CODE>append(Item)</CODE></A>. </p>
*
* @param itemNum the index where insertion is to occur
* @param item the item to be inserted
* @throws IndexOutOfBoundsException if itemNum is invalid
* @throws IllegalStateException if the item is already owned by a container
* @throws NullPointerException if item is null
*/
public void insert(int itemNum, Item item)
{
if (itemNum == this.container.size()) {
this.container.add(item);
} else {
this.container.add( itemNum, item );
}
}
/**
* Deletes the <code>Item</code> referenced by
* <code>itemNum</code>. The size of the <code>Form</code>
* shrinks by one. It is legal to delete all items from a
* <code>Form</code>.
* The <code>itemNum</code> parameter must be
* within the range <code>[0..size()-1]</code>, inclusive.
*
* @param itemNum the index of the item to be deleted
* @throws IndexOutOfBoundsException if itemNum is invalid
*/
public void delete(int itemNum)
{
this.container.remove(itemNum);
if (this.isShown() ) {
repaint();
}
}
/**
* Deletes all the items from this <code>Form</code>, leaving
* it with zero items.
* This method does nothing if the <code>Form</code> is already empty.
*
* @since MIDP 2.0
*/
public void deleteAll()
{
this.container.clear();
if (this.isShown() ) {
repaint();
}
}
/**
* Sets the item referenced by <code>itemNum</code> to the
* specified item,
* replacing the previous item. The previous item is removed
* from this <code>Form</code>.
* The <code>itemNum</code> parameter must be
* within the range <code>[0..size()-1]</code>, inclusive.
*
* <p>The end result is equal to
* <code>insert(n, item); delete(n+1);</code><br>
* although the implementation may optimize the repainting
* and usage of the array that stores the items. <P>
*
* @param itemNum the index of the item to be replaced
* @param item the new item to be placed in the Form
* @throws IndexOutOfBoundsException if itemNum is invalid
* @throws IllegalStateException if the item is already owned by a container
* @throws NullPointerException if item is null
*/
public void set(int itemNum, Item item)
{
this.container.set( itemNum, item );
}
/**
* Gets the item at given position. The contents of the
* <code>Form</code> are left
* unchanged.
* The <code>itemNum</code> parameter must be
* within the range <code>[0..size()-1]</code>, inclusive.
*
* @param itemNum the index of item
* @return the item at the given position
* @throws IndexOutOfBoundsException - if itemNum is invalid
*/
public Item get(int itemNum)
{
return this.container.get( itemNum );
}
/**
* Sets the <code>ItemStateListener</code> for the
* <code>Form</code>, replacing any previous
* <code>ItemStateListener</code>. If
* <code>iListener</code> is <code>null</code>, simply
* removes the previous <code>ItemStateListener</code>.
*
* @param iListener the new listener, or null to remove it
*/
public void setItemStateListener( ItemStateListener iListener)
{
this.itemStateListener = iListener;
}
/**
* Gets the number of items in the <code>Form</code>.
*
* @return the number of items
*/
public int size()
{
return this.container.size();
}
//#ifdef polish.useDynamicStyles
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Screen#getCssSelector()
//# */
//# protected String createCssSelector() {
//# return "form";
//# }
//#endif
/**
* Adds the given item to the queue for state notifications.
* The ItemStateListener will be called at the next possibility.
*
* @param item the item which contents have been edited.
*/
protected void addToStateNotifyQueue( Item item ) {
if (this.itemStateListener != null) {
if (this.stateNotifyQueue == null) {
this.stateNotifyQueue = new ArrayList();
}
synchronized (this.stateNotifyQueue) {
this.stateNotifyQueue.add( item );
}
//#debug
//# System.out.println("added item " + item + " to stateNotifyQueue with listener " + this.itemStateListener + ", size of queue=" + this.stateNotifyQueue.size() + " to form " + this );
}
}
/**
* Notifies the ItemStateListener about the changes which occurred to the items.
*/
protected void notifyStateListener() {
if (this.stateNotifyQueue != null && this.itemStateListener != null) {
Item lastItem = null;
while (this.stateNotifyQueue.size() > 0) {
Item item;
synchronized (this.stateNotifyQueue) {
item = (Item) this.stateNotifyQueue.remove(0);
}
if (item != lastItem) {
//#debug
//# System.out.println("notifying ItemStateListener for item " + item + " and form " + this );
this.itemStateListener.itemStateChanged(item);
lastItem = item;
}
}
//#debug
//# System.out.println("done notifying ItemStateListener.");
}
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Screen#animate()
*/
public boolean animate() {
boolean animated = false;
if ( (this.itemStateListener != null)
&& (this.stateNotifyQueue != null)
&& (this.stateNotifyQueue.size() > 0 ) ) {
notifyStateListener();
animated = true;
}
return animated | super.animate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -