Skip to content

Instantly share code, notes, and snippets.

@rafalrusin rafalrusin/model.xml
Created Mar 22, 2011

Embed
What would you like to do?
UI Refresh based on Model items
<netflow.model.Model id="1">
<nodes id="2">
<netflow.model.MShape id="3">
<flow>10.0</flow>
<capacity>10.0</capacity>
<name>node-1</name>
<type>SOURCE</type>
<x>171.0</x>
<y>142.0</y>
</netflow.model.MShape>
<netflow.model.MLine id="4">
<flow>-10.0</flow>
<capacity>10.0</capacity>
<a id="5">
<flow>10.0</flow>
<capacity>10.0</capacity>
<name>node-2</name>
<type>SINK</type>
<x>394.0</x>
<y>157.0</y>
</a>
<b reference="3"/>
</netflow.model.MLine>
<netflow.model.MShape reference="5"/>
</nodes>
</netflow.model.Model>
public function render(i:MNode):UINode {
if (controller.renderedItems.containsKey(i)) {
return controller.renderedItems.get(i) as UINode;
} else {
var uiNode: UINode;
if (i instanceof MShape) {
uiNode = UIShape {
model: i
controller: this
}
} else if (i instanceof MLine) {
uiNode = UILine {
model: i
controller: this
}
}
controller.renderedItems.put(i, uiNode);
return uiNode;
}
}
public function update():Void {
for (i:MNode in controller.model.nodes) {
if (i instanceof MShape) {
var s:UIShape = render(i) as UIShape;
}
}
for (i:MNode in controller.model.nodes) {
if (i instanceof MLine) {
render(i);
}
}
content = for (i:Object in controller.model.nodes) {
render(i as MNode)
}
requestLayout();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.