dynamicchassisdemo.java
来自「全面实现ilog地功能,没有使用第三方lib.」· Java 代码 · 共 175 行
JAVA
175 行
/*
* This source code is part of TWaver 1.3.1
*
* SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* Copyright 2000-2005 SERVA Software, Inc. All rights reserved.
*/
package demo.network.chassis;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import demo.DemoPane;
import twaver.*;
import twaver.network.*;
import twaver.tree.TTree;
public class DynamicChassisDemo extends DemoPane {
private TDataBox box = new TDataBox();
private TNetwork network = new TNetwork(box);
private TTree tree = new TTree(box);
private JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(tree),
network);
public DynamicChassisDemo() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.add(split);
this.tree.setElementMakedVisibleOnSelected(true);
//change the default selection border color.
TUIManager.registerDefault(TWaverConst.PROPERTYNAME_ELEMENT_SELECT_COLOR, Color.red.darker());
//load cisco chassis from xml file.
box.parse("/demo/resource/dynamicchassis/cisco_12000.xml");
//simulate alarms on port 'fiber1' and 'fiber2'.
TaskScheduler.getInstance().register(new TaskAdapter() {
public int getInterval() {
return 1000;
}
public void run(long clock) {
box.getElementByTag("fiber1").getAlarmState().addNewAlarm(AlarmSeverity.CRITICAL);
box.getElementByTag("fiber2").getAlarmState().addNewAlarm(AlarmSeverity.MAJOR);
}
});
//simulate the card change on card 'card1'.
TaskScheduler.getInstance().register(new TaskAdapter() {
private Element card = box.getElementByTag("card1");
private boolean remove = true;
public int getInterval() {
return 1000;
}
public void run(long long0) {
if (remove) {
box.removeElement(card);
} else {
card.setParent(box.getElementByID("rackID"));
box.addElement(card);
}
remove = !remove;
}
});
//simulate the port status change event, change its color.
TaskScheduler.getInstance().register(new TaskAdapter() {
Random random = new Random();
public int getInterval() {
return 500;
}
public void run(long long0) {
box.getElementByTag("testport1").putClientProperty(
TWaverConst.PROPERTYNAME_ELEMENT_BODY_COLOR,
new Color(random.nextInt(255),
random.nextInt(255),
random.nextInt(255),
random.nextInt(255)));
box.getElementByTag("outlineTestPort").putClientProperty(
TWaverConst.PROPERTYNAME_ELEMENT_OUTLINE_COLOR,
new Color(random.nextInt(255),
random.nextInt(255),
random.nextInt(255)));
box.getElementByTag("outlineTestPort").putClientProperty(
TWaverConst.PROPERTYNAME_DRAW_ICON_SHAPE,
new Boolean(random.nextBoolean())
);
box.getElementByTag("outlineTestPort").putClientProperty(
TWaverConst.PROPERTYNAME_DRAW_IMAGE_SHAPE,
new Boolean(random.nextBoolean())
);
}
});
final Vector iconNames = new Vector();
iconNames.add("document");
iconNames.add("lock");
iconNames.add("temperature");
iconNames.add("break");
iconNames.add("gander");
iconNames.add("open");
iconNames.add("information");
iconNames.add("refresh");
//simulate event on port 'testport2', show it as attachment icon.
TaskScheduler.getInstance().register(new TaskAdapter() {
Element port = box.getElementByTag("testport2");
Random random = new Random();
public int getInterval() {
return 1000;
}
public void run(long long0) {
String iconName = (String) iconNames.get(random.nextInt(iconNames.size()));
port.putClientProperty("StateIcon:" + iconName, Boolean.valueOf(random.nextBoolean()));
}
});
//setup the popup menu factory.
network.setPopupMenuFactory(new PopupMenuFactory() {
public JPopupMenu getPopupMenu(DataBoxSelectionModel dataBoxSelectionModel, Point point) {
//for the demo, only one element selected we popup the menu.
if (dataBoxSelectionModel.size() != 1) {
return null;
}
//only the selected element is card or port instance, popup menu.
Element element = dataBoxSelectionModel.lastElement();
if (!(element instanceof Card) && !(element instanceof Port)) {
return null;
}
JPopupMenu menu = new JPopupMenu();
if (element instanceof Card) {
menu.add(new JMenuItem("Card Popup Menu"));
//add more menu item here.
}
if (element instanceof Port) {
menu.add(new JMenuItem("Port Flow"));
menu.add(new JMenuItem("Turn Off/On"));
menu.addSeparator();
menu.add(new JMenuItem("Alarm..."));
}
return menu;
}
});
}
public String getTitle() {
return "Dynamic Chassis Demo";
}
public String getHelp() {
return "This demo creates an equipment chassis by XML, "+
" and it will be changed in the runtime.";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?