Attachment定制的一个例子,还未具体调试,先把代码贴出来,后面再整理。
1.定制Node:
import twaver.Node;
public class ChartNode extends Node
{
public function ChartNode(id:Object = null)
{
super(id);
}
override public function get elementUIClass():Class
{
return ChartNodeUI;
}
}
2.定制NodeUI:
import twaver.Node;
import twaver.network.Network;
import twaver.network.ui.NodeUI;
public class ChartNodeUI extends NodeUI
{
private var barAttachment:BarAttachment;
public function ChartNodeUI(network:Network, node:Node)
{
super(network, node);
}
override public function checkAttachments():void
{
super.checkAttachments();
checkChartAttachemnt();
}
protected function checkChartAttachemnt():void
{
if(this.node.getClient("bar"))
{
if(null == this.barAttachment)
{
this.barAttachment = new BarChartAttachment();
this.addAttachment(barAttachment);
}
}
else
{
if(null != this.barAttachment)
{
this.removeAttachment(this.barAttachment);
this.barAttachment = null;
}
}
}
}
3.定制Attachment:
import twaver.Node;
import twaver.network.ui.BasicAttachment;
import twaver.network.ui.ElementUI;
public class BarAttachment extends BasicAttachment
{
private chart:BarChart = new AttachmentBarChart();
public function BarAttachment(elementUI:ElementUI, showInAttachmentCanvas:Boolean = false)
{
super(elementUI, showInAttachmentCanvas);
this.content = chart;
}
override public function updateProperties():void
{
super.updateProperties();
var node:Node = new Node(this.element);
chart.dataProvider = [{name:"Y", value:int(node.location.y)},
{name:"X", value:int(node.location.x)}];
}
override public function get position():String
{
return Consts.POSITION_TOPLEFT;
}
override public function get direction():String
{
return Consts.ATTACHMENT_DIRECTION_LEFT;
}
}
4.测试:
private function init():void
{
this.initBox();
}
private function initBox():void
{
var node:ChartNode = new ChartNode();
node.name = "Chart Node";
node.setClient("bar", true);
node.setLocation(100, 100);
network.elementBox.add(node);
}