Node学习篇
1. 使用API创建Node
Node node = new Node();
TDataBox box = new TDataBox();
Box.addElement(node);
//设置节点位置
node.setLocation(100,100);
node.setImage(“node.gif”);
l Node图标:
Node 默认图标是 ,如果要让其无图标,使用TWaverConst.BLANK_IMAGE,如果要画一个无图片的节点类,使用TUIManager.registerWithoutImage(Class elementClass);
l Node大小:
默认情况下,node的大小是它默认图片的大小。如果要更改大小则要覆盖它的getHeight()和getWidth()方法。
Node node = new Node(){ Public int getHeight(){ return 50; } Public int getWidth(){ Return 50; } };
l 设置Node名称:
node.setName(“This is a Node!”); //使用不同font来给node命名 node.putLabelFont(new Font(“Forte”,Font.ITALIC,20)); //更改标签颜色 node.putLabelColor(Color.cyan); //设置标签可见 node.putLableVisible(true); //加粗 node.putLableBorder(true);
2. 使用XML来创建节点
TDataBox box = new TDataBox();
box.parse(“node.xml”);
创建xml文件:
<?xml version="1.0" encoding="UTF-8"?> <Java version="1.4.2_01" class="Java.beans.XMLDecoder"> <object class="TWaver.Node"> <void method="putClientProperty"> <string>label.border</string> <boolean>true</boolean> </void> <void method="putClientProperty"> <string>label.color</string> <object class="Java.awt.Color"> <int>255</int> <int>0</int> <int>0</int> <int>255</int> </object> </void> <void method="putClientProperty"> <string>label.font</string> <object class="Java.awt.Font"> <string>Forte</string> <int>1</int> <int>30</int> </object> </void> <void property="location"> <object class="Java.awt.Point"> <int>310</int> <int>285</int> </object> </void> <void property="name"> <string>This is my name</string> </void> <void property="selected"> <boolean>true</boolean> </void> <void property="toolTipText"> <string>This is my tip!</string> </void> </object> </Java>
3. 使用ShapeNode元素
常用的变形节点元素种类:
l SHAPENODE_STRAIGHT_LINE:直角线变形节点
l SHAPENODE_ELLIPSE:椭圆变形节点
l SHAPENODE_ROUND:圆变形节点元素
l SHAPENODE_NONE:空节点元素
创建直角线的多边形节点:
TDataBox box =new TDataBox(); TNetwork network=new TNetwork(box); ShapeNode bus=new ShapeNode(); box.addElement(bus); bus.addPoint(new Point(40,200)); for(int i=1;i<=10;i++){ Node node=new Node(); node.setName("Server_"+i); node.setLocation(50*i,100+200*(i%2)); box.addElement(node); box.addElement(new Link(bus,node)); } bus.addPoint(new Point(540,200)); //设置直角线形状的变形节点 bus.setShapeNodeType(TWaverConst.SHAPENODE_ORTHOGONAL_LINE); //设置节点类型为接近点 bus.putShapeNodeJointPoint(TWaverConst.JOINT_POINT_NEAR);