1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4  
     5  import org.aswing.DefaultListCell;
     6  import org.aswing.ListCell;
     7  import org.aswing.ListCellFactory;
     8  
     9  /**
    10   * @author iiley
    11   */
    12  class org.aswing.DefaultListCellFactory implements ListCellFactory {
    13  	
    14  	private var shareCelles:Boolean;
    15  	private var cellHeight:Number;
    16  	
    17  	/**
    18  	 * @param shareCelles is share cells for list items.
    19  	 * @see #isShareCells()
    20  	 */
    21  	public function DefaultListCellFactory(shareCelles:Boolean){
    22  		if(shareCelles == undefined){
    23  			shareCelles = true;
    24  		}
    25  		this.shareCelles = shareCelles;
    26  		cellHeight = -1;
    27  	}
    28  	
    29  	public function createNewCell() : ListCell {
    30  		return new DefaultListCell();
    31  	}
    32  	
    33  	/**
    34  	 * Return true here.
    35  	 * @see ListCellFactory#isAllCellHasSameHeight()
    36  	 */
    37  	public function isAllCellHasSameHeight() : Boolean {
    38  		return true;
    39  	}
    40  	
    41  	/**
    42  	 * @return is share cells for items.
    43  	 * @see ListCellFactory#isShareCells()
    44  	 */
    45  	public function isShareCells() : Boolean {
    46  		return shareCelles;
    47  	}
    48  	
    49  	/**
    50  	 * Returns the height for all cells.
    51  	 * @see ListCellFactory#getCellHeight()
    52  	 */
    53  	public function getCellHeight() : Number {
    54  		if(cellHeight < 0){
    55  			var cell:ListCell = createNewCell();
    56  			cell.setValue("JjHhWpqQ1@|");
    57  			cellHeight = cell.getListCellComponent().getPreferredSize().height;
    58  		}
    59  		return cellHeight;
    60  	}
    61  
    62  }
    63