package com.test; import java.awt.BorderLayout; import java.awt.Component; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import twaver.*; import twaver.network.TNetwork; import twaver.table.TElementTable; import twaver.table.TPropertySheet; import twaver.tree.TTree; public class HelloTWaver { /** * @param args */ public static void main(String[] args) { // 创建DataBox TDataBox box = new TDataBox(); // 增加两个节点和一条连线 Node node = new Node(); node.setName("Hello"); node.setLocation(10, 10); box.addElement(node); Node node2 = new Node(); node2.setName("TWaver"); node2.setLocation(200, 150); box.addElement(node2); Link link = new Link(node, node2); link.setName("Hello TWaver"); link.putLinkLabelRotatable(true); box.addElement(link); // 定义拓扑图组件 TNetwork network = new TNetwork(box); // 创建树组件 TTree tree = new TTree(box); // 创建属性页组件,并设置为可编辑 TPropertySheet sheet = new TPropertySheet(box); sheet.setEditable(true); // 创建表格组件,设置为可编辑 TElementTable table = new TElementTable(box); table.setElementClass(Element.class); table.setEditable(true); // 分别将属性页和表格组件放置在滚动面板中,这样可以保证表头的正确显示 JScrollPane tablePanel = new JScrollPane(table); JScrollPane sheetPanel = new JScrollPane(sheet); // 显示这些组件 showSplitPane("Hello TWaver", getSplitpane(tree, sheetPanel, 300, false), getSplitpane(network, tablePanel, 300, false), 100); } public static JFrame showSplitPane(String title, JComponent left, JComponent right, int leftLocation) { JSplitPane mainPane = getSplitpane(left, right, leftLocation, true); return showFrame(title, mainPane); } public static JSplitPane getSplitpane(JComponent firstPane, JComponent secondPane, int location, boolean isHorizontal) { JSplitPane mainPane = new JSplitPane(); if (isHorizontal) { mainPane.setRightComponent(secondPane); mainPane.setLeftComponent(firstPane); mainPane.setDividerLocation(location); } else { mainPane.setOrientation(JSplitPane.VERTICAL_SPLIT); mainPane.setBottomComponent(secondPane); mainPane.setTopComponent(firstPane); mainPane.setDividerLocation(location); } return mainPane; } public static JFrame showFrame(String title, Component component) { JFrame frame = new JFrame(); frame.setTitle(title); frame.getContentPane().add(component, BorderLayout.CENTER); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TWaverUtil.centerWindow(frame); frame.setVisible(true); return frame; } }
运行结果: