⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
//				//#endif
//			}		
//		//#endif
//		this.listType = listType;
//		
//		this.choiceGroup = new ChoiceGroup( null, this.listType, stringElements, imageElements, style, true  );
//		this.choiceGroup.autoFocusEnabled = true;
//		this.choiceGroup.screen = this;
//		this.choiceGroup.isFocused = true;
//		this.container = this.choiceGroup;
	}
		
	/**
	 * Creates a new <code>List</code>, specifying its title, the type
	 * the type of the
	 * <code>List</code>, and an array of <code>ChoiceItem</code>s
	 * to be used as its initial contents.
	 * 
	 * <p>The <code>items</code>s array must be non-null and
	 * every <code>ChoiceItem</code> must have its text be a non-null
	 * <code>String</code>.
	 * The length of the <code>items</code> array
	 * determines the number of elements in the <code>ChoiceGroup</code>.</p>
	 * 
	 * @param title the screen's title (see Displayable)
	 * @param listType one of IMPLICIT, EXCLUSIVE, or MULTIPLE
	 * @param items set of <code>ChoiceItem</code>s specifying the ChoiceGroup elements
	 * @throws NullPointerException if <code>items</code> is null 
	 *         or if getText() for one of the <code>ChoiceItem</code> in the array 
	 *         retuns a null <code>String</code>.
	 * @throws IllegalArgumentException if listType is not one of IMPLICIT, EXCLUSIVE, or MULTIPLE
	 * @see Choice#EXCLUSIVE
	 * @see Choice#MULTIPLE
	 * @see Choice#IMPLICIT
	 */
	public List( String title, int listType, ChoiceItem[] items)
	{
		this( title, listType, items, null ); 
	}
		
	/**
	 * Creates a new <code>List</code>, specifying its title, the type
	 * the type of the
	 * <code>List</code>, and an array of <code>ChoiceItem</code>s
	 * to be used as its initial contents.
	 * 
	 * <p>The <code>items</code>s array must be non-null and
	 * every <code>ChoiceItem</code> must have its text be a non-null
	 * <code>String</code>.
	 * The length of the <code>items</code> array
	 * determines the number of elements in the <code>ChoiceGroup</code>.</p>
	 * 
	 * @param title the screen's title (see Displayable)
	 * @param listType one of IMPLICIT, EXCLUSIVE, or MULTIPLE
	 * @param items set of <code>ChoiceItem</code>s specifying the ChoiceGroup elements
	 * @param style the style of this list
	 * @throws NullPointerException if <code>items</code> is null 
	 *         or if getText() for one of the <code>ChoiceItem</code> in the array 
	 *         retuns a null <code>String</code>.
	 * @throws IllegalArgumentException if listType is not one of IMPLICIT, EXCLUSIVE, or MULTIPLE
	 * @see Choice#EXCLUSIVE
	 * @see Choice#MULTIPLE
	 * @see Choice#IMPLICIT
	 */
	public List( String title, int listType, ChoiceItem[] items, Style style)
	{
		super( title, style, false );
		//#ifndef polish.skipArgumentCheck
			if (listType != Choice.EXCLUSIVE && listType != Choice.MULTIPLE && listType != Choice.IMPLICIT ) {
				//#ifdef polish.debugVerbose
					//# throw new IllegalArgumentException("invalid list-type: " + listType );
				//#else
					throw new IllegalArgumentException();
				//#endif
			}		
		//#endif
		this.listType = listType;
		
		//#ifdef polish.i18n.useDynamicTranslations
			//# String selectLabel = "Select";
			//# if ( selectLabel != SELECT_COMMAND.getLabel()) {
				//# SELECT_COMMAND = new Command( selectLabel, Command.ITEM, 3 );
				//# this.selectCommand = SELECT_COMMAND;
			//# }
		//#endif

		this.choiceGroup = new ChoiceGroup( null, this.listType, items, style, true  );
		this.choiceGroup.autoFocusEnabled = true;
		this.choiceGroup.screen = this;
		this.choiceGroup.isFocused = true;
		this.container = this.choiceGroup;
	}
		
	/**
	 * Gets the number of elements in the <code>List</code>.
	 * 
	 * @return the number of elements in the List
	 * @see Choice#size() in interface Choice
	 */
	public int size()
	{
		return this.container.size();
	}

	/**
	 * Gets the <code>String</code> part of the element referenced by
	 * <code>elementNum</code>.
	 * 
	 * @param elementNum - the index of the element to be queried
	 * @return the string part of the element
	 * @throws IndexOutOfBoundsException - if elementNum is invalid
	 * @see Choice#getString(int) in interface Choice
	 * @see #getImage(int)
	 */
	public String getString(int elementNum)
	{
		return this.choiceGroup.getString( elementNum );
	}

	/**
	 * Gets the <code>Image</code> part of the element referenced by
	 * <code>elementNum</code>.
	 * 
	 * @param elementNum the number of the element to be queried
	 * @return the image part of the element, or null if there is no image
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @see Choice#getImage(int) in interface Choice
	 * @see #getString(int)
	 */
	public Image getImage( int elementNum )
	{
		return this.choiceGroup.getImage( elementNum );
	}

	/**
	 * Gets the <code>ChoiceItem</code> of the element referenced by
	 * <code>elementNum</code>.
	 *
	 * @param elementNum the number of the element to be queried
	 * @return the ChoiceItem of the element
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 */
	public ChoiceItem getItem( int elementNum )
	{
		return (ChoiceItem)this.choiceGroup.get( elementNum );
	}

	/**
	 * Appends an element to the <code>List</code>.
	 * 
	 * @param stringPart the string part of the element to be added
	 * @param imagePart the image part of the element to be added, or null if there is no image part
	 * @return the assigned index of the element
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#append(String, Image) in interface Choice
	 */
	public int append( String stringPart, Image imagePart)
	{
		return append( stringPart, imagePart, null );
	}
	/**
	 * Appends an element to the <code>List</code>.
	 * 
	 * @param stringPart the string part of the element to be added
	 * @param imagePart the image part of the element to be added, or null if there is no image part
	 * @param elementStyle the style for the new list element.
	 * @return the assigned index of the element
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#append(String, Image) in interface Choice
	 */
	public int append( String stringPart, Image imagePart, Style elementStyle )
	{
		return append( new ChoiceItem( stringPart, imagePart, this.listType, elementStyle ));
	}
	
	/**
	 * Appends a <code>ChoiceItem</code> to the <code>List</code>.
	 *
	 * @param item ChoiceItem to be added
	 * @return the assigned index of the element
	 */
	public int append( ChoiceItem item )
	{
		//#ifdef polish.css.show-text-in-title
			//# if (this.showTextInTitle){
				//# String stringPart = item.getText();
				//# if (item.getImage() != null && stringPart != null) {
					//# item.setText( null );
					//# this.titles.add( stringPart );
					//# if (this.titles.size() == 1) {
						//# // now set the title of the first item:
						//# setTitle( stringPart );
					//# }
				//# } else {
					//# this.titles.add( "" );
				//# }
			//# }
		//#endif
		int number = this.choiceGroup.append( item );
		//#if polish.List.suppressCommands != true
			if (number == 0) {
				// the first item has been inserted:
				if (this.listType == IMPLICIT && this.selectCommand != null ) {
					//#if polish.List.suppressSelectCommand != true
						addCommand( this.selectCommand );
					//#endif
				} else {
					//#if polish.List.suppressMarkCommands != true
						setItemCommands(this.choiceGroup);
					//#endif
				}
			}
		//#endif
		return number;
	}
	
	/**
	 * Inserts an element into the <code>List</code> just prior to the element specified.
	 * 
	 * @param elementNum the index of the element where insertion is to occur
	 * @param stringPart the string part of the element to be inserted
	 * @param imagePart the image part of the element to be inserted, or null if there is no image part
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#insert(int, String, Image) in interface Choice
	 */
	public void insert(int elementNum, String stringPart, Image imagePart)
	{
		this.choiceGroup.insert( elementNum, stringPart, imagePart, null );
	}
	
	/**
	 * Inserts an element into the <code>List</code> just prior to the element specified.
	 * 
	 * @param elementNum the index of the element where insertion is to occur
	 * @param stringPart the string part of the element to be inserted
	 * @param imagePart the image part of the element to be inserted, or null if there is no image part
	 * @param elementStyle the style for the new list element.
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#insert(int, String, Image) in interface Choice
	 */
	public void insert(int elementNum, String stringPart, Image imagePart, Style elementStyle )
	{
		this.choiceGroup.insert( elementNum, stringPart, imagePart, elementStyle );
	}

	/**
	 * Inserts an element into the <code>List</code> just prior to the element specified.
	 * 
	 * @param elementNum the index of the element where insertion is to occur
	 * @param item ChoiceItem of the element to be inserted
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 */
	public void insert(int elementNum, ChoiceItem item)
	{
		this.choiceGroup.insert( elementNum, item );
	}
	
	/**
	 * Sets the <code>String</code> and <code>Image</code> parts of the
	 * element referenced by <code>elementNum</code>,
	 * replacing the previous contents of the element.
	 * 
	 * @param elementNum the index of the element to be set
	 * @param stringPart the string part of the new element
	 * @param imagePart the image part of the element, or null if there is no image part
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#set(int, String, Image) in interface Choice
	 */
	public void set(int elementNum, String stringPart, Image imagePart)
	{
		this.choiceGroup.set( elementNum, stringPart, imagePart, null );
	}

	/**
	 * Sets the <code>String</code> and <code>Image</code> parts of the
	 * element referenced by <code>elementNum</code>,
	 * replacing the previous contents of the element.
	 * 
	 * @param elementNum the index of the element to be set
	 * @param stringPart the string part of the new element
	 * @param imagePart the image part of the element, or null if there is no image part
	 * @param elementStyle the style for the new list element.
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @throws NullPointerException if stringPart is null
	 * @see Choice#set(int, String, Image) in interface Choice
	 */
	public void set(int elementNum, String stringPart, Image imagePart, Style elementStyle )
	{
		this.choiceGroup.set( elementNum, stringPart, imagePart, elementStyle );
	}

	/**
	 * Sets the <code>ChoiceItem</code> of the
	 * element referenced by <code>elementNum</code>,
	 * replacing the previous one.
	 * 
	 * @param elementNum the index of the element to be set
	 * @param item ChoiceItem of the new element
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 */
	public void set(int elementNum, ChoiceItem item)
	{
		this.choiceGroup.set( elementNum, item );
	}

	/**
	 * Deletes the element referenced by <code>elementNum</code>.
	 * 
	 * @param elementNum the index of the element to be deleted
	 * @throws IndexOutOfBoundsException if elementNum is invalid
	 * @see Choice#delete(int) in interface Choice
	 */
	public void delete(int elementNum)
	{
		//#ifdef polish.css.show-text-in-title
			//# if (this.showTextInTitle){
				//# this.titles.remove(elementNum);
			//# }
		//#endif
		this.choiceGroup.delete(elementNum);
		if (this.choiceGroup.size() == 0 ) {
			if (this.listType == IMPLICIT && this.selectCommand != null ) {
				super.removeCommand( this.selectCommand );
			} else {
				removeItemCommands(this.choiceGroup);
			}
		}
	}

	/**
	 * Deletes all elements from this List.
	 * 
	 * @see Choice#deleteAll() in interface Choice
	 */
	public void deleteAll()
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -