1  import org.aswing.ListCell;
     2  import org.aswing.ListCellFactory;
     3  
     4  /**
     5   * GeneralListCellFactory let you can just specified a ListCell implemented class 
     6   * and other params to create a ListCellFactory
     7   * @author iiley
     8   */
     9  class org.aswing.GeneralListCellFactory implements ListCellFactory {
    10  	
    11  	private var listCellClass:Function;
    12  	private var shareCelles:Boolean;
    13  	private var cellHeight:Number;
    14  	private var sameHeight:Boolean;
    15  	
    16  	/**
    17  	 * @param listCellClass the ListCell implementation, for example com.xlands.ui.list.UserListCell
    18  	 * @param shareCelles (optional)is share cells for list items, default is true.
    19  	 * @param sameHeight (optional)is all cells with same height, default is true.
    20  	 * @param height (optional)the height for all cells if sameHeight, if not <code>sameHeight</code>, 
    21  	 * this param can be miss, default is 22.
    22  	 * @see #isShareCells()
    23  	 */
    24  	public function GeneralListCellFactory(listCellClass:Function, shareCelles:Boolean, sameHeight:Boolean, height:Number){
    25  		this.listCellClass = listCellClass;
    26  		
    27  		if(shareCelles == undefined){
    28  			shareCelles = true;
    29  		}
    30  		this.shareCelles = shareCelles;
    31  		if(sameHeight == undefined){
    32  			sameHeight = true;
    33  		}
    34  		this.sameHeight = sameHeight;
    35  		
    36  		if(height == undefined){
    37  			height = 22;
    38  		}
    39  		cellHeight = height;
    40  	}
    41  	
    42  	public function createNewCell() : ListCell {
    43  		return new listCellClass();
    44  	}
    45  	
    46  	/**
    47  	 * @see ListCellFactory#isAllCellHasSameHeight()
    48  	 */
    49  	public function isAllCellHasSameHeight() : Boolean {
    50  		return sameHeight;
    51  	}
    52  	
    53  	/**
    54  	 * @return is share cells for items.
    55  	 * @see ListCellFactory#isShareCells()
    56  	 */
    57  	public function isShareCells() : Boolean {
    58  		return shareCelles;
    59  	}
    60  	
    61  	/**
    62  	 * Sets the height for all cells
    63  	 */
    64  	public function setCellHeight(h:Number):Void{
    65  		cellHeight = h;
    66  	}
    67  	
    68  	/**
    69  	 * Returns the height for all cells
    70  	 * @see ListCellFactory#getCellHeight()
    71  	 */
    72  	public function getCellHeight() : Number {
    73  		return cellHeight;
    74  	}
    75  }