In this section you will learn how to programmatically assign a rule to an element
(VisualNode or VisualEdge).
Below we add a new rule named “nrule2” to rule definition file
rule.xml. This rule specifies a resizeable node.
Example 6.5. A rule for resizeable nodes
...
<list name="Rule">
<attribute name="Name" type="String" value="nrule2"/>
<attribute name="Type" type="String" value="NodeRule"/>
<list name="Properties">
<attribute name="Deletable" type="Boolean" value="false"/>
<attribute name="Moveable" type="Boolean" value="true"/>
<attribute name="Selectable" type="Boolean" value="true"/>
<attribute name="Resizable" type="Boolean" value="true"/>
...
</list>
</list>
...
In this example, we do not want all our visual nodes to be resizeable, just the root
one. This requires us to retrieve that root node (variable nodeA
is holding this root node in the graph model), get the corresponding
VisualNode object and then apply our new rule
“nrule2” to it. The following code snippet reflects these steps.
Example 6.6. Assigning a rule to a node
// retrieve the first node of the graph
VisualNode vNodeA=
graphView.getVisualNodeByID(nodeA.getID());
// apply the previously defined rule
vNodeA.setRule("NormalNodeRule");
Adding these lines of code will result in a resizeable root node. When you get around
to reading the javadocs, you will notice that rules can be set for any
VisualGraphObject instance!
© 2004, 2005 Tensegrity Software GmbH