apichassisdemo.java

来自「全面实现ilog地功能,没有使用第三方lib.」· Java 代码 · 共 161 行

JAVA
161
字号
/*
 * 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.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import twaver.AlarmSeverity;
import twaver.Card;
import twaver.Port;
import twaver.Rack;
import twaver.TDataBox;
import twaver.network.TNetwork;
import twaver.tree.TTree;
import demo.DemoPane;

public class APIChassisDemo extends DemoPane {
    TDataBox box = new TDataBox();
    TTree tree = new TTree(box);
    TNetwork network = new TNetwork(box);

    public APIChassisDemo() {
        JSplitPane split = new JSplitPane();
        split.setLeftComponent(new JScrollPane(tree));
        split.setRightComponent(network);
        split.setContinuousLayout(true);
        split.setDividerLocation(200);
        this.add(split, BorderLayout.CENTER);
        tree.setElementMakedVisibleOnSelected(true);

        Rack rack = new Rack("rack");
        rack.setName("ROUTER CHASSIS");
        rack.setLocation(20, 20);
        rack.setImage("/demo/resource/chassis/chassis.png");
        rack.putClientProperty("label.font", new Font("Dialog", Font.BOLD, 20));
        box.addElement(rack);

        addShelf1(rack);
        addShelf2(rack);
    }

    private void addShelf2(Rack rack) {
        Rack shelf2 = new Rack("shelf2");
        shelf2.setLocation(rack.getLocation().x + 15,
                           rack.getLocation().y + 330);
        shelf2.setSize(rack.getSize().width - 30, 120);
        shelf2.setParent(rack);
        box.addElement(shelf2);

        Font font = new Font("Impact", Font.PLAIN, 12);
        for (int i = 0; i < 10; i++) {
            Card card = new Card("card" + i);
            card.setName("card" + i);
            card.setLocation(shelf2.getLocation().x + 3 + i * 30,
                             shelf2.getLocation().y + 3);
            card.setSize(28, shelf2.getSize().height - 6);
            card.setParent(shelf2);

            card.putClientProperty("label.font", font);
            card.putClientProperty("label.color", Color.darkGray);
            if (i == 1) {
                card.getAlarmState().addNewAlarm(AlarmSeverity.CRITICAL);
            }
            if (i == 5) {
                card.getAlarmState().setNewAlarmCount(AlarmSeverity.MINOR, 2);
            }
            if (i == 0 || i == 9) {
                card.putClientProperty("card.bolt.top", Boolean.TRUE);
                card.putClientProperty("card.bolt.bottom", Boolean.TRUE);
            }
            box.addElement(card);
        }
    }

    private void addShelf1(Rack rack) {
        Rack shelf1 = new Rack("shelf1");
        shelf1.setLocation(rack.getLocation().x + 15,
                           rack.getLocation().y + 145);
        shelf1.setSize(rack.getSize().width - 35, 120);
        shelf1.setParent(rack);
        box.addElement(shelf1);

        Card card = new Card("top card");
        card.setLocation(shelf1.getLocation().x + 3,
                         shelf1.getLocation().y + 3);
        card.setSize(shelf1.getSize().width - 6, 30);
        card.setParent(shelf1);
        box.addElement(card);
        for (int i = 0; i < 12; i++) {
            Port port = new Port("top card port" + i);
            port.setImage("/demo/resource/chassis/port_rj45f.png");
            port.setLocation(card.getLocation().x + 10 +
                             i * 20 +
                             i / 4 * 15,
                             card.getLocation().y + 5);
            card.addChild(port);
            box.addElement(port);
        }

        for (int i = 0; i < 3; i++) {
            card = new Card("horizontal card" + i);
            card.setSize(shelf1.getSize().width / 2 - 6, 28);
            card.setLocation(shelf1.getLocation().x + 3,
                             shelf1.getLocation().y + 5 + (i + 1) * card.getSize().getHeight());

            card.setParent(shelf1);
            card.putClientProperty("card.bolt.left", Boolean.TRUE);
            card.putClientProperty("card.bolt.right", Boolean.TRUE);
            box.addElement(card);

            Port port = new Port("horizontal card port" + i);
            port.setImage("/demo/resource/chassis/port_cent36f.png");
            port.setLocation(card.getLocation().x + 30, card.getLocation().y + 5);
            card.addChild(port);
            if (i == 0) {
                port.getAlarmState().addNewAlarm(AlarmSeverity.MAJOR);
                port.putClientProperty("StateIcon:temperature", Boolean.TRUE);
                port.putClientProperty("StateIcon:lock", Boolean.TRUE);
            }
            box.addElement(port);
        }
        for (int i = 0; i < 5; i++) {
            card = new Card("vertical card" + i);
            card.setSize(30, 84);
            card.setLocation(shelf1.getLocation().x - 3
                             + shelf1.getSize().width / 2 +
                             i * card.getSize().width,
                             shelf1.getLocation().y + 33);

            card.setParent(shelf1);
            box.addElement(card);

            Port port = new Port("vertical card port" + i);
            port.setImage("/demo/resource/chassis/port3.png");
            port.setLocation(card.getLocation().x + 10, card.getLocation().y + 10);
            card.addChild(port);
            if (i == 4) {
                port.getAlarmState().addNewAlarm(AlarmSeverity.WARNING);
            }
            box.addElement(port);
        }
    }

    public String getHelp() {
        return "This demo creates equipment chassis by API.";
    }

    public String getTitle() {
        return "Chassis Demo (API)";
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?