Twaver Gui Demo

2024-02-04 20:08
文章标签 gui demo twaver

本文主要是介绍Twaver Gui Demo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

电信级拓扑及设备面板开发工具,功能强大。对于网元的抽象也做得很好,可以快速构建拓扑视图。

一个Develop Guide中的Example,

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.WindowConstants;import twaver.AlarmSeverity;
import twaver.AlarmState;
import twaver.Chassis;
import twaver.DataBoxSelectionEvent;
import twaver.DataBoxSelectionListener;
import twaver.Dummy;
import twaver.Element;
import twaver.Link;
import twaver.Node;
import twaver.PopupMenuGenerator;
import twaver.Port;
import twaver.Rack;
import twaver.SummingAlarmPropagator;
import twaver.TDataBox;
import twaver.TUIManager;
import twaver.TView;
import twaver.TWaverUtil;
import twaver.network.TNetwork;
import twaver.network.ui.ElementUI;
import twaver.network.ui.IconAttachment;
import twaver.tree.TTree;public class Tutorial extends JFrame {private TDataBox box = new TDataBox("Simple Data Box");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(100);doSample();}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.setName("I'm node A!");nodeA.setLocation(50, 50);box.addElement(nodeA);Node nodeB = new Node("B");nodeB.setName("I'm node B!");nodeB.setLocation(200, 200);box.addElement(nodeB);Link link = new Link("link", nodeA, nodeB);link.setName("Telephone Line");box.addElement(link);}private void step2() {//在树上面将设备分类,并加载Dummy nodeDummy = new Dummy("node dummy");nodeDummy.setName("All Nodes");nodeDummy.addChild(box.getElementByID("A"));nodeDummy.addChild(box.getElementByID("B"));box.addElement(nodeDummy);Dummy linkDummy = new Dummy("link dummy");linkDummy.setName("All Links");linkDummy.addChild(box.getElementByID("link"));box.addElement(linkDummy);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("Chassis A");node.addChild(chassis);box.addElement(chassis);// 1.在chassis上添加机架Rack rack = new Rack("Rack A");rack.setName("Rack");rack.setLocation(50, 50);rack.setImage("/demo/resource/tutorial/rack.png");chassis.addChild(rack);box.addElement(rack);// 2.在机架上添加端口String imgPort1 = "/demo/resource/tutorial/port1.png";String imgPort2 = "/demo/resource/tutorial/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);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() {//给视图添加弹出菜单,// Create a popup menu generatorPopupMenuGenerator popupMenuGenerator = new PopupMenuGenerator() {/*** Add the identifier of each of the selected objects to the menu.* In this example, the items added to the menu do nothing. In a* real application, you would probably associate an implementation* of the Swing Action interface with each menu item.*/public JPopupMenu generate(TView tview, MouseEvent mouseEvent) {// Create an empty pop-up menu.JPopupMenu popMenu = new JPopupMenu();JMenuItem item;// If the selectedObjects collection is empty, no objects are// selected.if (tview.getDataBox().getSelectionModel().isEmpty()) {popMenu.add("Nothing selected");} else {// Access the selected objects from the selection model.Iterator it = tview.getDataBox().getSelectionModel().selection();while (it.hasNext()) {Element element = (Element) it.next();popMenu.add(element.getName());}}// If menu is empty, return null.if (popMenu.getComponentCount() == 0) {return null;} else {return popMenu;}}};// Set the pop-up menu generator for network componentsnetwork.setPopupMenuGenerator(popupMenuGenerator);}private void step5() {//拓扑视图鼠标响应事件,有个可能不可接受的问题是为什么点出子视图后总是会回到主视图?network.getCanvas().addMouseListener(new MouseAdapter() {public void mouseClicked(MouseEvent e) {if (e.getClickCount() == 2) {// get the element the mouse clicked.Element element = network.getElementPhysicalAt(e.getPoint());String message;if (element == null) {message = "You clicked nothing.";} else {message = "You clicked '" + element.getName() + "'";}JOptionPane.showMessageDialog(network, message);}}});}private void step6() {//树中的结点与拓扑中的网元动作关联// create a selection listener.DataBoxSelectionListener listener = new DataBoxSelectionListener() {public void selectionChanged(DataBoxSelectionEvent e) {// get the last selected element and make it visible.Element element = e.getBoxSelectionModel().lastElement();if (element != null) {//并且如果这个选中的数据不在可见区域内,会自动滚动画布以保证数据处于可见视野内。network.ensureVisible(element);}}};box.getSelectionModel().addDataBoxSelectionListener(listener);}private void step7() {//给端口添加告警状态。支持子网元告警在主网元上自动显示,且显示最高等级,属于自动告警收缩。// create and set a summing propagator to the data source,// here will make the box propagate alarms to its parent.box.setAlarmPropagator(new SummingAlarmPropagator());// get a port in the equipment rack.Port nodeA = (Port) box.getElementByID("0:0");AlarmState alarmState = nodeA.getAlarmState();// add an acknowledged alarm with critical severity.alarmState.addAcknowledgedAlarm(AlarmSeverity.CRITICAL);// add and new alarm with major severity.alarmState.addNewAlarm(AlarmSeverity.MAJOR);// get another port.Port nodeB = (Port) box.getElementByID("3:3");alarmState = nodeB.getAlarmState();// add 10 new alarms with critical minor.alarmState.increaseNewAlarm(AlarmSeverity.MINOR, 10);}//装饰图标private void step8() {String iconName = "document";TUIManager.registerAttachment(iconName, MyIconAttachment.class);// put a "document" icon on element B.Element element = box.getElementByID("A");element.addAttachment(iconName);}//链路效果private void step9() {// get the link element.Link element = (Link) box.getElementByID("link");// make the link animating flowingelement.putLinkFlowing(true);// set the link flowing colorelement.putLinkFlowingColor(Color.black);// set the link outline colorelement.putLinkOutlineColor(Color.black);// set the link body color.element.putLinkColor(Color.white);// set the link lable fontelement.putLabelFont(new Font("Impact", 1, 20));// set the link lable colorelement.putLabelColor(Color.MAGENTA);}public static class MyIconAttachment extends IconAttachment {public MyIconAttachment(String name, ElementUI ui) {super(name, ui, TWaverUtil.getImageIcon("myIcon.png"));}}/*** @param args*/public static void main(String[] args) {Tutorial frame = new Tutorial();frame.setSize(640, 480);frame.setTitle("TWaver Tutorial");TWaverUtil.centerWindow(frame);frame.setVisible(true);}}


这篇关于Twaver Gui Demo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/678665

相关文章

Springboot处理跨域的实现方式(附Demo)

《Springboot处理跨域的实现方式(附Demo)》:本文主要介绍Springboot处理跨域的实现方式(附Demo),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录Springboot处理跨域的方式1. 基本知识2. @CrossOrigin3. 全局跨域设置4.

Python GUI框架中的PyQt详解

《PythonGUI框架中的PyQt详解》PyQt是Python语言中最强大且广泛应用的GUI框架之一,基于Qt库的Python绑定实现,本文将深入解析PyQt的核心模块,并通过代码示例展示其应用场... 目录一、PyQt核心模块概览二、核心模块详解与示例1. QtCore - 核心基础模块2. QtWid

Java 创建图形用户界面(GUI)入门指南(Swing库 JFrame 类)概述

概述 基本概念 Java Swing 的架构 Java Swing 是一个为 Java 设计的 GUI 工具包,是 JAVA 基础类的一部分,基于 Java AWT 构建,提供了一系列轻量级、可定制的图形用户界面(GUI)组件。 与 AWT 相比,Swing 提供了许多比 AWT 更好的屏幕显示元素,更加灵活和可定制,具有更好的跨平台性能。 组件和容器 Java Swing 提供了许多

Golang GUI入门——andlabs ui

官方不提供gui标准库,只好寻求第三方库。 https://github.com/google/gxui 这个gui库是谷歌内部人员提供的,并不是谷歌官方出品,现在停止维护,只好作罢。 第三方gui库 找了好多,也比较了好多,最终决定使用的是还是 https://github.com/andlabs/ui 相信golang gui还会发展的更好,期待更优秀的gui库 由于andlabs

linux 内核提权总结(demo+exp分析) -- 任意读写(四)

hijack_modprobe_path篇 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm     原理同hijack_prctl, 当用户执行错误格式的elf文件时内核调用call_usermod

linux 内核提权总结(demo+exp分析) -- 任意读写(三)

hijack_prctl篇 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm   prctl函数: 用户态函数,可用于定制进程参数,非常适合和内核进行交互 用户态执行prctl函数后触发prctl系统

linux 内核提权总结(demo+exp分析) -- 任意读写(二)

hijack_vdso篇 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm     vdso: 内核实现的一个动态库,存在于内核,然后映射到用户态空间,可由用户态直接调用 内核中的vdso如果被修改

linux 内核提权总结(demo+exp分析) -- 任意读写(一)

cred篇 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm   每个线程在内核中都对应一个线程结构块thread_infothread_info中存在task_struct类型结构体 struct t

linux 内核提权总结(demo+exp分析) -- ROP(二)

ret2usr CR4篇 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm   smep: smep是内核的一种保护措施, 使得内核不可执行用户态代码 内核通过CR4寄存器的第20位来控制smep,

linux 内核提权总结(demo+exp分析) -- ROP(一)

基础ROP篇(linux 5.0.21) 本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:jmpcall 专栏地址:https://zhuanlan.kanxue.com/user-815036.htm   内核提权与用户态攻击的区别 攻击流程 用户态攻击: 执行 system("/bin/sh") 获得shel