⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systemstatus.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * ==================================================================== * The Vovida Software License, Version 1.0 *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. *  * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. *  */package vocal.systemStatus;import vocal.comm.VPPTransactionWrapper;import vocal.comm.VPPException;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import java.awt.event.*;import java.util.StringTokenizer;import java.util.Vector;import java.util.Enumeration;import java.util.Calendar;import java.util.TimeZone;import java.net.URL;import java.net.MalformedURLException;import java.io.*;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreeSelectionModel;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.DefaultTreeModel;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.plaf.metal.MetalIconFactory;import javax.swing.tree.TreePath;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.ParserConfigurationException;import org.xml.sax.AttributeList;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.InputSource;import org.xml.sax.Attributes;/** * This class displays the System status as a GUI. It receives the information * about the systems from SNMP network manager. * This class extends JFrame to implement the frame container for our JTree */public class SystemStatus extends JFrame{  /**   * A reference to the Applet that started this up.   */  private SNMPApplet theApplet;  /**   * Flag which indicates whether to keep querying the server for new status info.   */  private boolean run = true;  /**   * Name of the System Status host   */  private String hostname = "";  /**   * Port the System Status host is listening on   */  private int port = 0;  /**   * The current version number to pass to Network Manager   * This must be initialized to < 0 so that the Network   * Manager will send over data on the first request.   * The Network Manager may send back an incremented   * version number, which is what we use on subsequent calls.   */  private int versionNumber = -1;  /**   * Handler for SAX callbacks   */  private SAXHandler handler = new SAXHandler();  private DefaultMutableTreeNode top;  private DefaultMutableTreeNode selectedNode;  // the label that tells us which node is being controlled.  private JLabel controlLabel;  // the button used to send SNMP Start  private JRadioButton startButton;  // the button used to send SNMP Stop  private JRadioButton stopButton;  // an invisible button to make it look like none are selected  private JRadioButton dummyButton;  /**   * Text Field and message pane to display the status messages   */  private JTextField m_display;  private JEditorPane messagePane;  /**   * The container object   */  Container contents;  JRootPane rootP;  SNMPCellRenderer renderer;  JTree m_tree;  DefaultTreeModel m_model;  /**   *    */  public SystemStatus(SNMPApplet applet)  {    this();    theApplet = applet;  }  /**   * Default constructor.   */  public SystemStatus()  {    super("SNMP GUI ");    setSize(500, 400);    OidNode oNode = new OidNode("root", null, OidNode.ROOT);    oNode.setDisplayString("vocal.com");    top = new DefaultMutableTreeNode(oNode);    controlLabel = new JLabel(" ");    startButton = new JRadioButton("Start Process");    startButton.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        if (selectedNode == null)        {          System.out.println("selected node is null");        }        else        {          OidNode node = (OidNode) (selectedNode.getUserObject());          synchronized (this)          {            sendSNMPStart(node);          }        }      }    });    dummyButton = new JRadioButton("none");    stopButton = new JRadioButton("Stop Process");    stopButton.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        if (selectedNode == null)        {          System.out.println("selected node is null");        }        else        {          OidNode node = (OidNode) (selectedNode.getUserObject());          synchronized (this)          {            sendSNMPStop(node);          }        }      }    });    /**     * Defines the root and each node of the tree as TreeNode instances     */    m_model = new DefaultTreeModel(top);    m_tree = new JTree(m_model);    m_tree.addTreeSelectionListener(new TreeSelectionListener()    {      public void valueChanged(TreeSelectionEvent e)      {        DefaultMutableTreeNode candidateNode =           (DefaultMutableTreeNode) (e.getPath().getLastPathComponent());        if (candidateNode != selectedNode)        {          // unselect the stop button          dummyButton.setSelected(true);        }        OidNode userObject = (OidNode) (candidateNode.getUserObject());        if (userObject.getType() == OidNode.PORT)        {          selectedNode = candidateNode;          controlLabel.setText(userObject.getDisplayString());          stopButton.setEnabled(true);          startButton.setEnabled(true);        }        else        {          selectedNode = null;          controlLabel.setText(" ");          stopButton.setEnabled(false);          startButton.setEnabled(false);        }      }    });    // allow only one node to be selected at a time.    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);    m_tree.setRootVisible(false);    /**     * Renderer object to render a tree cell based on its current states     */    renderer = new SNMPCellRenderer();    m_tree.setCellRenderer(renderer);    m_tree.setShowsRootHandles(true);    m_tree.setEditable(false);    m_tree.setSelectionPath(new TreePath(top));    m_tree.addTreeSelectionListener(new TreeSelectionListener()    {      /**       */      public void valueChanged(TreeSelectionEvent e)      {        DefaultMutableTreeNode node =           (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent();        if (node == null)        {          return;        }        Object nodeInfo = node.getUserObject();        if (nodeInfo instanceof OidNode)        {          OidNode nd = (OidNode) nodeInfo;        }      }    });    /**     * The root pane and Container object     */    rootP = getRootPane();    contents = rootP.getContentPane();    /**     * JScrollPane is created to provide scrolling capabilities,  tree is added to     * its JViewport     */    JScrollPane treeView = new JScrollPane();    treeView.getViewport().add(m_tree);    /**     * Create the messages viewing pane.     */    messagePane = new JEditorPane();    messagePane.setEditable(false);    JScrollPane msgView = new JScrollPane(messagePane);    // Add the scroll panes to a split pane    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);    // Make a panel for the treeView and stopStart panels.    JPanel topPanel = new JPanel();    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));    // Make a  panel for the stop/start buttons.    JPanel controlPanel = new JPanel();    controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));    controlPanel.setBorder(new TitledBorder(new EmptyBorder(5, 5, 5, 5),             "SNMP Control"));    // Make the things that go in the startStop box.    ButtonGroup startStopGroup = new ButtonGroup();    startStopGroup.add(startButton);    startStopGroup.add(stopButton);    startStopGroup.add(dummyButton);    controlPanel.add(controlLabel);    controlPanel.add(startButton);    controlPanel.add(stopButton);    controlPanel.add(Box.createGlue());    topPanel.add(treeView);    topPanel.add(controlPanel);    splitPane.setTopComponent(topPanel);    splitPane.setBottomComponent(msgView);    this.setSize(new Dimension(500, 500));    // args to Dimension are width, height    treeView.setMinimumSize(new Dimension(200, 50));    treeView.setPreferredSize(new Dimension(300, 300));    msgView.setMinimumSize(new Dimension(500, 50));    msgView.setPreferredSize(new Dimension(500, 200));    splitPane.setOneTouchExpandable(true);    splitPane.setPreferredSize(new Dimension(500, 500));    /**     * Add the split pane to this frame     */    contents.add(splitPane, BorderLayout.CENTER);    /**     * Object for text field     */    m_display = new JTextField();    m_display.setEditable(false);    /**     * Add the text field to this frame     */    contents.add(m_display, BorderLayout.SOUTH);    getContentPane().add(m_display, BorderLayout.SOUTH);    addWindowListener(new WindowAdapter()    {      /**       *        */      public void windowClosing(WindowEvent e)      {        stop();      }    });    setVisible(true);

⌨️ 快捷键说明

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