1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| import mx.core.UIComponent;
import mx.controls.TextArea;
import TextField.StyleSheet;
class HtmlCellRenderer extends UIComponent
{
static public var CssUrl:String; // Global: URL for CSS stylesheet
static public var style_sheet:StyleSheet = null;
var htmlComponent:TextField;
var owner; // The row that contains this cell
var listOwner : MovieClip; // the reference we receive to the list
var getCellIndex : Function; // the function we receive from the list
var getDataLabel : Function; // the function we receive from the list
var previousLabel:String = null; // for optimization
function HtmlCellRenderer()
{
}
function createChildren(Void) : Void
{
if (CssUrl != undefined && style_sheet == null)
{
style_sheet = new TextField.StyleSheet();
style_sheet.load(CssUrl);
}
if (htmlComponent == undefined)
{
createLabel("htmlComponent", 1);
}
htmlComponent.html = true;
htmlComponent.border = false;
htmlComponent.multiline = true;
htmlComponent.wordWrap = true;
htmlComponent.selectable = true;
htmlComponent.background = false;
htmlComponent.styleSheet = style_sheet;
size();
}
// note that setSize is implemented by UIComponent and calls size(), after setting
// __width and __height
function size(Void) : Void
{
htmlComponent.setSize(__width-2, __height-2);
}
function Interval (str:String)
{
setInterval(setValue, 1000, str);
}
////
function setValue(str:String, item:Object, sel:Boolean) : Void
{
// Ligne vide ou Header
if (item == undefined)
{
// Special case for headerRenderer
htmlComponent.htmlText = str;
previousLabel = null;
return;
}
var columnIndex = this["columnIndex"]; // private property (no access function)
var columnName = getDataLabel();
var htmlFunction : Function = listOwner.getColumnAt(columnIndex).htmlFunction;
if (htmlFunction != undefined)
{
var label = htmlFunction(item, columnName);
if (label != undefined)
{
// Important pour optimisation
// Empêche un flip-flop des images
if (label != previousLabel)
{
htmlComponent.htmlText = previousLabel = label;
}
}
else
{
htmlComponent.htmlText = "";
}
}
else
{
htmlComponent.htmlText = str;
}
}
function getPreferredHeight(Void) : Number
{
if (owner == undefined) return 18;
return owner.__height - 2;
}
} |
Partager