今天写了一个CellRenderer,实现自定义Flash的DataGrid组件中字体的外观,使其支持hmtl格式。文件如下:
文件名:HtmlCellRenderer.as
/****************************************************************************
类名:HtmlCellRenderer
作者:Bob Kang 2007/01/23
****************************************************************************/
class HtmlCellRenderer extends mx.core.UIComponent
{
private var HtmlLabel;
private var owner;
private var listOwner;
private static var PREFERRED_HEIGHT_OFFSET = 4;
private static var PREFERRED_WIDTH = 100;
private var startDepth:Number = 1;
public function HtmlCellRenderer()
{
}
var c = HtmlLabel = this.createLabel("HtmlLabel", startDepth);
c.styleName = listOwner;
c.selectable = false;
c.tabEnabled = false;
c.background = false;
c.border = false;
c.html=true;
size();
}
public function size():Void
{
var c = HtmlLabel;
c.setSize(__width, __height);
}
public function getPreferredHeight():Number
{
return owner.__height + PREFERRED_HEIGHT_OFFSET;
}
public function setValue(suggestedValue:String, item:Object, selected:Boolean):Void
{
if (item==undefined){
HtmlLabel._visible = false;
}
HtmlLabel.htmlText = suggestedValue;
}
}
用法:myDataGrid.getColumnAt(i).cellRenderer = "HtmlCellRenderer";
效果如图所示: