package
{
import flash.display.Sprite;
import org.aswing.ASColor;
import org.aswing.JScrollPane;
import org.aswing.JTable;
import org.aswing.VectorListModel;
import org.aswing.event.SelectionEvent;
import org.aswing.table.PropertyTableModel;
import org.aswing.table.sorter.TableSorter;
public class JTableExample extends Sprite
{
private var data:Array = [];
private var columns:Array = [];
private var table:JTable;
private var tableModel:PropertyTableModel;
private var modeList:VectorListModel;
private var sorter:TableSorter;
public function JTableExample()
{
super();
init();
}
private function init():void
{
this.stage.frameRate = 25;
data = [{name:"iiley", sex:1, age:26, score:99},
{name:"Comeny", sex:0, age:24, score:100},
{name:"Tom", sex:1, age:30, score:98},
{name:"Lita", sex:0, age:16, score:36}]
;
modeList = new VectorListModel(data);
columns = ["Name", "Sex", "age", "Score"] ;
tableModel = new PropertyTableModel(modeList,columns,["name","sex","age","score"],[null,sexTranslator,null,null,]);
sorter = new TableSorter(tableModel);
this.table = new JTable(sorter);
this.table.setRowHeight(22);
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.setForeground(new ASColor(0xffffff));
table.setSelectionForeground(new ASColor(0x123456));
this.table.setAutoResizeMode ( JTable.AUTO_RESIZE_OFF );
this.table.setSelectionMode ( JTable.SINGLE_SELECTION );
this.table.setBackground(new ASColor(0x000000));
this.table.addEventListener(SelectionEvent.ROW_SELECTION_CHANGED,__rowSelectHandler);
var panel:JScrollPane = new JScrollPane();
panel.setSizeWH(200, 100);
panel.append(this.table);
this.addChild(panel);
panel.validate();
}
private function __rowSelectHandler(e:SelectionEvent):void
{
var rowCount : int = this.table.getSelectedRow();
if(rowCount>0)
{
var row:Object = modeList.getElementAt(sorter.modelIndex(rowCount));
}
if(row!=null)
{
trace("Human"+" Name:"+row.name+",Sex:"+row.sex+",Age:"+row.age+",Score:"+row.score);
}
}
private function sexTranslator(info:*, key:String):String
{
if(info[key]=="1")
{
return "男";
}
else
{
return "女";
}
}
}
}