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

📄 frmmonitor.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

//Title:       OAA Monitor
//Version:
//Copyright:   Copyright (c) 1999
//Author:      Adam Cheyer
//Company:     SRI International
//Description: Monitor program for OAA agent community

/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

/* History
 *  11/15/99 v 2.0.3
 *               - version number to 2.0.3 to stay in sync across distribution
 *  11/11/99 v 2.0.2
 *               - chart moved to be local to monitor agent, not general GUI tool
 *  8/15/99 v 2.0.1
 *  6/28/99      - Ported to OAA 2.0
 *  3/5/99       - Added cleanupAfterDisconnect
 *  1/22/99      - Let icons be any size, not just 40x40
 *               - Added buttons to toolbar to shrink and grow radius
 * 11/18/98 v 1.02
 *               - Fixed number of bugs (e.g. multiple copies)
 * 10/24/98 v 1.01
 *               - Removed "package" from source
 *               - Moved frmAbout and frmHelp to tools.gui package
 *               - Changed "solve(ksdata())" to read_bb to handle old-style
 *                 facilitators
 *               - Added "todo" section to doc
 * 10/23/98 v 1.0  First release
 */

package com.sri.oaa2.agt.monitor;

// includes
import java.util.*;
import java.net.*;
import java.lang.Math;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import com.sri.oaa2.lib.*;
import com.sri.oaa2.com.*;
import com.sri.oaa2.icl.*;
import com.sri.oaa2.guiutils.*;


/**
 * frmMonitor: Primary display for monitor program
 */
public class frmMonitor extends JFrame {

  // Visual elements
  JScrollPane jScrollPane1 = new JScrollPane();
  JMenuBar menuBar1 = new JMenuBar();
  JMenu menuFile = new JMenu();
  JMenuItem mnuConnect = new JMenuItem();
  JMenuItem mnuLoad = new JMenuItem();
  JMenuItem mnuSave = new JMenuItem();
  JMenuItem mnuExit = new JMenuItem();
  JMenu menuLog = new JMenu();
  JMenuItem mnuShowLog = new JMenuItem();
  JMenuItem mnuClearLog = new JMenuItem();
  JMenuItem mnuSetFilter = new JMenuItem();
  JMenuItem mnuFindLog = new JMenuItem();
  JMenuItem mnuFindAgain = new JMenuItem();
  JMenuItem mnuSaveLog = new JMenuItem();
  JMenuItem mnuSaveOTML = new JMenuItem();
  JMenu menuProfile = new JMenu();
  JMenu menuOptions = new JMenu();
  JCheckBoxMenuItem mnuDrawGraphics = new JCheckBoxMenuItem();
  JCheckBoxMenuItem mnuWindowsLook = new JCheckBoxMenuItem();
  JCheckBoxMenuItem mnuMotifLook = new JCheckBoxMenuItem();
  JCheckBoxMenuItem mnuMetalLook = new JCheckBoxMenuItem();
  JMenu menuHelp = new JMenu();
  JMenuItem menuHelpAbout = new JMenuItem();
  JMenuItem mnuHelp = new JMenuItem();
  ImageIcon imgFile;
  ImageIcon imgHelp;
  ImageIcon imgFind;
  ImageIcon imgNextEvent;
  ImageIcon imgPrevEvent;
  ImageIcon imgFirstEvent;
  ImageIcon imgLastEvent;
  ImageIcon imgRecording;
  ImageIcon imgNotRecording;
  ImageIcon imgMonitor;
  ImageIcon imgSmallerRadius;
  ImageIcon imgBiggerRadius;
  BorderLayout borderLayout1 = new BorderLayout();
  JToolBar jToolBar1 = new JToolBar();
  JLabel lblStatus = new JLabel();
  JButton btnShowLog = new JButton();
  BevelBorder bevBorder = new BevelBorder(BevelBorder.RAISED);

  JSplitPane jSplitPane1;
  JPanel pnlMonitor = new JPanel();
  JButton btnFacilitator = new JButton();
  JPanel pnlInfo = new JPanel();
  JLabel lblSolvables = new JLabel();
  JLabel lblAgentName = new JLabel();
  JLabel lblAgentLanguage = new JLabel();
  JLabel lblAgentHost = new JLabel();
  JLabel lblAgentVersion = new JLabel();
  JLabel lblAgentSend = new JLabel();
  JLabel lblAgentReceive = new JLabel();
  JLabel lblTotalBytes = new JLabel();
  JLabel lblTotalMsgs = new JLabel();

  JComboBox cboSolvables = new JComboBox();
  JButton btnNextEvent = new JButton();
  JButton btnPrevEvent = new JButton();
  JButton btnFirstEvent = new JButton();
  JButton btnLastEvent = new JButton();
  JButton btnSmallerRadius = new JButton();
  JButton btnBiggerRadius = new JButton();

  // Popup menu variables
  JPopupMenu jAgentPopupMenu = new JPopupMenu();
  JMenuItem  jMenuPing = new JMenuItem();
  JMenuItem  jMenuKill = new JMenuItem();

  JButton btnRecording = new JButton();

  // OAA variables
  LibOaa oaa = null;                                    // OAA Library class
  String oaaName = "oaa_monitor";                       // Initial agent name
  String oaaSolvables = "[m_data(Op,D),m_ev(Op,Id,Ev)]";// Agent solvables
  String Version = "2.3.1";                             // Monitor version
  
  // Class variables
  frmEvBrowser evBrowser = null;                        // Pointer to event browser window
  frmChart chartWindow = null;                          // Pointer to the profiler window
  frmEvFilter evFilter = null;                          // Pointer to the event filter window

  int minH = 0, minW = 0;                               // min size of panel
  Vector agtList = new Vector();                        // stores list of all agents
  String[] mArgs;                                       // Command line parameters
  agtInfo selectedAgent = null;
  agtInfo popupAgent = null;
  int totalBytesSent = 0;
  int totalBytesReceived = 0;
  int maxBytesSent = 0;
  int maxBytesReceived = 0;
  double radiusRatio = 1.0;
  JMenuItem mnuChartTimes = new JMenuItem();
  JMenuItem mnuChartData = new JMenuItem();

  // Constructor
  public frmMonitor(String[] args) {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    mArgs = args;
    try  {
      jbInit(args);
      btnShowLog.setIcon(imgFind);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit(String[] args) throws Exception  {

    // Main form
    this.setSize(new Dimension(550, 400));
    this.setTitle("OAA Monitor");
    this.getContentPane().setLayout(borderLayout1);

   /**************************************************************************
    * OAA Initialisations
    **************************************************************************/
    // Create instance of OAA using TCP as the communication protocol
    oaa = new LibOaa(new LibCom(new LibComTcpProtocol(), args));
    
    // Attach function to default handler for incoming requests
    oaa.oaaRegisterCallback("app_do_event",
      new OAAEventListener() {
        public boolean doOAAEvent(IclTerm goal, IclList params, IclList answers) {
          return oaaAppDoEvent(goal, params, answers);
        }
      });

    // Toolbar
    imgFile = new ImageIcon(getClass().getResource("images/openFile.gif"));
    imgHelp = new ImageIcon(getClass().getResource("images/help.gif"));
    imgFind = new ImageIcon(getClass().getResource("images/find.gif"));
    imgFirstEvent = new ImageIcon(getClass().getResource("images/first.gif"));
    imgNextEvent = new ImageIcon(getClass().getResource("images/nexte.gif"));
    imgPrevEvent = new ImageIcon(getClass().getResource("images/preve.gif"));
    imgLastEvent = new ImageIcon(getClass().getResource("images/last.gif"));
    imgBiggerRadius = new ImageIcon(getClass().getResource("images/radiusb.gif"));
    imgSmallerRadius = new ImageIcon(getClass().getResource("images/radiuss.gif"));
    imgRecording = new ImageIcon(getClass().getResource("images/rec.gif"));
    imgNotRecording = new ImageIcon(getClass().getResource("images/notrec.gif"));
    imgMonitor = new ImageIcon(getClass().getResource("images/oaa_monitor.gif"));

    this.setIconImage(imgMonitor.getImage());

//    btnOpen.setIcon(imgOpen);
    btnShowLog.setText("Show Log");
    btnShowLog.setIcon(imgFind);
    btnShowLog.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnShowLog_actionPerformed(e);
      }
    });
    btnNextEvent.setIcon(imgNextEvent);
    btnNextEvent.setToolTipText("Step to NEXT event");
    btnNextEvent.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnNextEvent_actionPerformed(e);
      }
    });
    btnPrevEvent.setIcon(imgPrevEvent);
    btnPrevEvent.setToolTipText("Step to PREVIOUS event");
    btnPrevEvent.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnPrevEvent_actionPerformed(e);
      }
    });
    btnFirstEvent.setIcon(imgFirstEvent);
    btnFirstEvent.setToolTipText("Reset stepper to FIRST event");
    btnFirstEvent.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnFirstEvent_actionPerformed(e);
      }
    });
    btnLastEvent.setIcon(imgLastEvent);
    btnLastEvent.setToolTipText("Reset stepper to LAST event");
    btnLastEvent.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnFirstEvent_actionPerformed(e);
      }
    });
    btnRecording.setIcon(imgNotRecording);
    btnRecording.setToolTipText("Not recording events, click to toggle");
    btnRecording.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
         if (btnRecording.getIcon() == imgRecording) {
            btnRecording.setIcon(imgNotRecording);
            btnRecording.setToolTipText("NOT recording events, click to toggle");
         }
         else {
            btnRecording.setIcon(imgRecording);
            btnRecording.setToolTipText("Recording events...");
         }
      }
    });
    btnBiggerRadius.setIcon(imgBiggerRadius);
    btnBiggerRadius.setToolTipText("Increase radius");
    btnBiggerRadius.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnBiggerRadius_actionPerformed(e);
      }
    });
    btnSmallerRadius.setIcon(imgSmallerRadius);
    btnSmallerRadius.setToolTipText("Decrease radius");
    btnSmallerRadius.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnSmallerRadius_actionPerformed(e);
      }
    });

    mnuChartTimes.setEnabled(false);
    mnuChartData.setEnabled(false);
    jToolBar1.add(btnShowLog, null);
    jToolBar1.add(btnFirstEvent, null);
    jToolBar1.add(btnPrevEvent, null);
    jToolBar1.add(btnNextEvent, null);
    jToolBar1.add(btnLastEvent, null);
    jToolBar1.add(btnRecording, null);
    jToolBar1.addSeparator();
    jToolBar1.add(btnSmallerRadius, null);
    jToolBar1.add(btnBiggerRadius, null);
    jToolBar1.setFloatable(false);

    // Menus

    // File menu
    menuFile.setText("File");
    mnuConnect.setText("OAA Connect");
    mnuConnect.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        makeOAAConnection(false);
      }
    });
    mnuLoad.setText("Load session");
    mnuLoad.setEnabled(false);
    mnuSave.setText("Save session");
    mnuSave.setEnabled(false);
    mnuSaveLog.setText("Save log text");
    mnuSaveLog.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuSaveLog_actionPerformed(e);
      }
    });
    mnuSaveOTML.setText("Save log as OTML");
    mnuSaveOTML.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuSaveOTML_actionPerformed(e);
      }
    });
    mnuExit.setText("Exit");
    mnuExit.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        fileExit_actionPerformed(e);
      }
    });

    // Log menu
    menuLog.setText("Event log");
    mnuShowLog.setText("Show log window");
    mnuClearLog.setText("Clear log");
    mnuSetFilter.setText("Set Event Filters");
    mnuClearLog.setEnabled(false);
    mnuFindLog.setText("Find in log");
    mnuFindLog.setAccelerator(KeyStroke.getKeyStroke('F', java.awt.Event.CTRL_MASK));

    mnuFindAgain.setText("Find again");
    mnuFindAgain.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));
    mnuShowLog.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnShowLog_actionPerformed(e);
      }
    });
    mnuClearLog.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
         evBrowser.btnClear_actionPerformed(e);
      }
    });
    mnuSetFilter.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuSetFilter_actionPerformed(e);
      }
    });
    mnuFindLog.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuFindLog_actionPerformed(e);
      }
    });
    mnuFindAgain.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuFindLog_actionPerformed(e);
      }
    });

    // profile menu
    menuProfile.setText("Profile");

    // Options menu
    String uiName = UIManager.getLookAndFeel().getName();
    menuOptions.setText("Options");
    mnuDrawGraphics.setText(" Draw graphics");
    mnuDrawGraphics.setState(true);
    mnuMotifLook.setText("Motif Look");
    mnuMotifLook.setState(uiName.equals("Motif"));
    mnuMotifLook.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
         if (mnuMotifLook.getState()) {
            //setNewLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
            mnuMetalLook.setState(false);
            mnuWindowsLook.setState(false);
         }
         else {
            mnuMotifLook.setState(true);
         }
      }
    });
    mnuMetalLook.setText("Metal Look");
    mnuMetalLook.setState(uiName.equals("Metal"));
    mnuMetalLook.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
         if (mnuMetalLook.getState()) {
            //setNewLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());
            mnuMotifLook.setState(false);
            mnuWindowsLook.setState(false);
         }
         else {
            mnuMetalLook.setState(true);
         }
      }
    });
    mnuWindowsLook.setText("Windows Look");
    mnuWindowsLook.setState(uiName.equals("Windows"));
    mnuWindowsLook.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
         if (mnuWindowsLook.getState()) {
            //setNewLookAndFeel(new javax.swing.plaf.windows.WindowsLookAndFeel());
            mnuMotifLook.setState(false);
            mnuMetalLook.setState(false);
         }
         else {

⌨️ 快捷键说明

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