1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  import org.aswing.ASColor;
     6  import org.aswing.Component;
     7  import org.aswing.JLabel;
     8  import org.aswing.UIManager;
     9  
    10  import org.aswing.ListCell;
    11  
    12  /**
    13   * @author iiley
    14   */
    15  class org.aswing.DefaultListCell implements ListCell {
    16  	
    17  	private var jlabel:JLabel;
    18  	
    19  	private var itemBGC:ASColor;
    20  	private var itemSelectedBGC:ASColor;
    21  	private var itemFGC:ASColor;
    22  	private var itemSelectedFGC:ASColor;
    23  	
    24  	private var value:Object;
    25  	private var selected:Boolean;
    26  	
    27  	public function DefaultListCell(){
    28  		value = null;
    29  		selected = false;
    30  	}
    31  	
    32  	public function setValue(value : Object) : Void {
    33  		if(this.value != value){
    34  			this.value = value;
    35  			getJLabel().setText(value.toString());
    36  		}
    37  	}
    38  
    39  	public function getValue() : Object {
    40  		return value;
    41  	}
    42  
    43  	public function setSelected(b : Boolean) : Void {
    44  		if(selected != b){
    45  			selected = b;
    46  			if(b){
    47  				getJLabel().setBackground(itemSelectedBGC);
    48  				getJLabel().setForeground(itemSelectedFGC);
    49  			}else{
    50  				getJLabel().setBackground(itemBGC);
    51  				getJLabel().setForeground(itemFGC);				
    52  			}
    53  			getJLabel().repaint();
    54  		}
    55  	}
    56  
    57  	public function isSelected() : Boolean {
    58  		return selected;
    59  	}
    60  	
    61  	private function getJLabel():JLabel{
    62  		if(jlabel == null){
    63  			jlabel = new JLabel();
    64  			jlabel.setHorizontalAlignment(JLabel.LEFT);
    65  			itemBGC = UIManager.getColor("List.itemBackground");
    66  			itemSelectedBGC = UIManager.getColor("List.itemSelectedBackground");
    67  			itemFGC = UIManager.getColor("List.itemForeground");
    68  			itemSelectedFGC = UIManager.getColor("List.itemSelectedForeground");
    69  			jlabel.setBackground(itemBGC);
    70  			jlabel.setForeground(itemFGC);
    71  			jlabel.setOpaque(true);
    72  		}
    73  		return jlabel;
    74  	}
    75  
    76  	public function getListCellComponent() : Component {
    77  		return getJLabel();
    78  	}
    79  
    80  }
    81