欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

TWaver基于Swing的应用初例

程序员文章站 2022-04-20 09:00:42
...
package com;

import java.awt.BorderLayout;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import twaver.AlarmSeverity;
import twaver.DataBoxSelectionModel;
import twaver.Element;
import twaver.Link;
import twaver.Node;
import twaver.PopupMenuFactory;

import twaver.TDataBox;
import twaver.network.TNetwork;
import twaver.network.background.ImageBackground;
import twaver.table.TPropertySheet;

public class Exapem extends JFrame{

    //创建数据箱、地图组件和属性表组件
	TDataBox box = new TDataBox();
	TNetwork network=new TNetwork(box);	
	TPropertySheet sheet=new TPropertySheet(box);
	
	JSplitPane split=new JSplitPane();
	public Exapem(){
		//初始化布局管理
		this.getContentPane().add(split, BorderLayout.CENTER);
		split.setLeftComponent(network);
		split.setDividerLocation(350);//设置分隔页面
		split.setRightComponent(new JScrollPane(sheet));
		this.setSize(800,800);
		loadData();
	}
	private void loadData() {
		//创建网元节点
		Node node1=new Node();
		node1.setName("one");
		node1.setLocation(100,100);
		box.addElement(node1);
		Node node2=new Node();
		node2.setName("two");
		node2.setLocation(200,200);
		box.addElement(node2);
		//添加一个Critical新发告警
        Node node3=new Node();     
        node3.setName("新告警");
        node3.getAlarmState().addNewAlarm(AlarmSeverity.CRITICAL);
        box.addElement(node3);
		network.setNetworkBackground(new ImageBackground("/image/map.jpg"));
		//加入链接
        Link link=new Link(node1,node2);
        link.setName("我是链路");
        box.addElement(link);              
        //加入右键菜单
        network.setPopupMenuFactory(new PopupMenuFactory(){
            public JPopupMenu getPopupMenu(DataBoxSelectionModel selectionModel, Point p) {
                JPopupMenu menu = new JPopupMenu();
                
                if (selectionModel.size() == 1) {
                	//获得当前点击选中的网元节点
                    Element element = (Element) selectionModel.lastElement();
                    if (element instanceof Link) {
                        menu.add(new JMenuItem("断开连接"));
                    } else {
                        menu.add(new JMenuItem("配置网元"));
                    }
                    menu.addSeparator();
                    menu.add(new JMenuItem("查看告警"));      
            	  
                    return menu;
                }
                return null;
            }

        });
        
	}

	public static void main(String[] args){
		Exapem ss=new Exapem();
		ss.show();
	}
}

 

相关标签: Swing 配置管理