日期:2014-05-20 浏览次数:20699 次
package com; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import twaver.*; import twaver.network.*; import twaver.network.ui.*; import twaver.table.*; import twaver.tree.*; public class Tutorial extends JFrame { private TDataBox box = new TDataBox("Simple DataBox"); private TNetwork network; private TTree tree; private JPanel networkPane = new JPanel( new BorderLayout() ); private JPanel treePane = new JPanel( new BorderLayout() ); private JSplitPane split = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,treePane,networkPane ); public Tutorial() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); getContentPane().add(split,BorderLayout.CENTER); split.setDividerLocation(200); doSample(); } public static void main(String[] args) { Tutorial frame = new Tutorial(); frame.setSize(800, 600); frame.setTitle("test TWaver Tutorial"); TWaverUtil.centerWindow(frame); frame.setVisible(true); } private void doSample(){ try{ step1(); step2(); step3(); step4(); step5(); step6(); step7(); step8(); step9(); } catch(Exception ex){ ex.printStackTrace(); } } private void step1() { network = new TNetwork(box); networkPane.add(network, BorderLayout.CENTER); Node nodeA =new Node("A"); nodeA.putRenderAlpha(0.5f); nodeA.setName("I am node A"); nodeA.setLocation(100, 150); box.addElement(nodeA); Node nodeB = new Node("B"); //nodeB.setName("I am node B"); nodeB.setDisplayName("<html>In case you thought that TWaver label had to be"+ "<p>boring,one line descriptions,the"+ "<p><font color=blue size=+2>TWaver Team</font>"+ "<p>is happy to shatter your illusions.<p>"+ "In TWaver,they can use HTML to"+ "<ul><li>Have Lists<li><b>Bold</b>"+ "text<li><em>emphasized</em>"+ "text<li>text with<font color=red>Color</font>"+ "<li>text in different<font size=+3>sizes</font>"+ "<li>and<font face=AvantGarde>Fonts</font></ul>"+ "Oh,and they can be multi-line,too.</html>"); nodeB.getAlarmState().addNewAlarm(AlarmSeverity.CRITICAL); nodeB.setLocation(300, 450); box.addElement(nodeB); Link link = new Link("link",nodeA,nodeB); link.setName("telephone line"); box.addElement(link); } private void step2() { Dummy dummyNode = new Dummy("node dummy"); dummyNode.setName("all nodes"); dummyNode.addChild(box.getElementByID("A")); dummyNode.addChild(box.getElementByID("B")); box.addElement(dummyNode); Dummy dummyLink = new Dummy("link dummy"); dummyLink.setName("all link"); dummyLink.addChild(box.getElementByID("link")); box.addElement(dummyLink); tree = new TTree(box); JScrollPane scroll = new JScrollPane(tree); treePane.add(scroll, BorderLayout.CENTER); } private void step3() { Node node=(Node)box.getElementByID("A"); Chassis chassis=new Chassis("CHA"); node.addChild(chassis); box.addElement(chassis); Rack rack = new Rack("Rack A"); rack.setName("Rack"); rack.setLocation(50,50); rack.setImage("/com/rack.png"); chassis.addChild(rack); box.addElement(rack); String imgPort1 = "/com/port1.png"; String imgPort2 = "/com/port2.png"; for(int module=0; module<4; module++){ Dummy dummy = new Dummy("PortDummy"+module); dummy.setName("module"+module); rack.addChild(dummy); box.addElement(dummy); for(int index=0; index<4; index++) { Port port = new Port(module+":"+index); port.setName(module+":"+index); int x,y; if(module%2==0) { x=210+index*24; } else{ x=319+index*24; } if(module<2) { y=16; port.setImage(imgPort1); } else{ y=37; port.setImage(imgPort2); } x += rack.getLocation().x; y += rack.getLocation().y; port.setLocation(new Point(x,y)); dummy.addChild(port); box.addElement(port); } } } private void step4() { } private void step5() { } private void step6() { } private void step7() { } private void step8() { } private void step9() { } }