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

📄 frmmonitor.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            mnuWindowsLook.setState(true);
         }
      }
    });


    // help menu
    menuHelp.setText("Help");
    menuHelpAbout.setText("About");
    menuHelpAbout.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        helpAbout_actionPerformed(e);
      }
    });
    mnuHelp.setText("Help on Monitor");
    mnuHelp.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        help_actionPerformed(e);
      }
    });

    menuFile.add(mnuConnect);
    menuFile.add(mnuLoad);
    menuFile.add(mnuSave);
    menuFile.add(mnuExit);
    menuLog.add(mnuShowLog);
    menuLog.add(mnuClearLog);
    menuLog.add(mnuSetFilter);
    menuLog.add(mnuFindLog);
    menuLog.add(mnuFindAgain);
    menuLog.add(mnuSaveLog);
    menuLog.add(mnuSaveOTML);
    menuProfile.add(mnuChartData);
    menuProfile.add(mnuChartTimes);
    menuHelp.add(mnuHelp);
    menuHelp.add(menuHelpAbout);
    menuBar1.add(menuFile);
    menuBar1.add(menuLog);
    menuBar1.add(menuProfile);
    menuBar1.add(menuOptions);
    menuOptions.add(mnuDrawGraphics);
    menuOptions.addSeparator();
    menuOptions.add(mnuWindowsLook);
    menuOptions.add(mnuMotifLook);
    menuOptions.add(mnuMetalLook);
    menuBar1.add(menuHelp);
    this.setJMenuBar(menuBar1);

    // Popup Menu
    jMenuPing.setText("Ping");
    jMenuKill.setText("Kill");
    jAgentPopupMenu.add(jMenuPing);
    jAgentPopupMenu.add(jMenuKill);

    // StatusBar
    lblStatus.setText(" ");
    lblStatus.setBorder(bevBorder);
    this.getContentPane().add(jToolBar1, BorderLayout.NORTH);
    this.getContentPane().add(lblStatus, BorderLayout.SOUTH);

    // Info Panel: displays information about each agent
    pnlInfo.setPreferredSize(new Dimension(200, 100));
    pnlInfo.setMinimumSize(new Dimension(150, 70));
    pnlInfo.setLayout(null);
    lblAgentName.setText(" Name: ");
    lblAgentName.setBorder(bevBorder);
    lblAgentName.setBounds(10,5,180,25);
    pnlInfo.add(lblAgentName);
    lblSolvables.setText("Solvables:");
    lblSolvables.setBounds(10,35,180,15);
    pnlInfo.add(lblSolvables);
    cboSolvables.setBounds(10,50,180,25);
    cboSolvables.setEnabled(false);
    lblAgentLanguage.setText("Language: ");
    lblAgentLanguage.setBounds(10, 90, 180, 15);
    lblAgentVersion.setText("OAA Version: ");
    lblAgentVersion.setBounds(10, 110, 180, 15);
    lblAgentHost.setText("Host: ");
    lblAgentHost.setBounds(10, 130, 180, 15);
    lblAgentSend.setText("Agent sent: ");
    lblAgentSend.setBounds(10, 160, 180, 15);
    lblAgentReceive.setText("Agent received: ");
    lblAgentReceive.setBounds(10, 180, 180, 15);
    lblTotalMsgs.setText("Total # msgs: ");
    lblTotalMsgs.setBounds(10, 210, 180, 15);
    lblTotalBytes.setText("Total bytes: " + (totalBytesSent + totalBytesReceived));
    lblTotalBytes.setBounds(10, 230, 180, 15);
    pnlInfo.add(cboSolvables);
    pnlInfo.add(lblAgentLanguage);
    pnlInfo.add(lblAgentVersion);
    pnlInfo.add(lblAgentHost);
    pnlInfo.add(lblAgentSend);
    pnlInfo.add(lblAgentReceive);
    pnlInfo.add(lblTotalMsgs);
    pnlInfo.add(lblTotalBytes);
    pnlInfo.addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentResized(ComponentEvent e) {
        pnlInfo_componentResized(e);
      }
    });

    // Monitor Panel : displays community of agents in a circle
    pnlMonitor.addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentResized(ComponentEvent e) {
        pnlMonitor_componentResized(e);
      }
    });
    pnlMonitor.setLayout(null);
    btnFacilitator.setToolTipText("FACILITATOR");
    btnFacilitator.setText("Facilitator");
    btnFacilitator.setEnabled(false);
    btnFacilitator.setBounds(40, 40, 100, 100);
       // Add event handler for "click" event of each agent
    btnFacilitator.addActionListener(new ActionListener()  {
       public void actionPerformed(ActionEvent e) {
         btnFacilitatorClicked();
       }
    });    
    pnlMonitor.add(btnFacilitator);

    pnlMonitor.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        unselectAgent();
      }
    });

    jScrollPane1.getViewport().add(pnlMonitor);

    // Split Panel
    jSplitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, pnlInfo, jScrollPane1);

    this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);

    // EventBrowser window
    evBrowser = new frmEvBrowser(this);
    evBrowser.enableEventFunctions(false);
    enableAgentFunctions(false);

    // Event filter window
    evFilter = new frmEvFilter(this);

    // Chart Window
    chartWindow = new frmChart(this);
    mnuChartData.setText("Chart data size");
    mnuChartTimes.setText("Chart times");
    mnuChartData.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mnuProfData_actionPerformed(e);
      }
    });

    // Connect to facilitator if autoconnection specified
    makeOAAConnection(true);
  }

//File | Exit action performed
  public void fileExit_actionPerformed(ActionEvent e) {
    System.exit(0);
  }

/**
 * File | SaveLog action performed
 */
  public void mnuSaveLog_actionPerformed(ActionEvent e) {
     String startDirectory;
     String filename;
     FileDialog fd = new FileDialog(this,"Event Log Text",FileDialog.SAVE);
     fd.setFile("*.txt");
     fd.show();
     startDirectory = fd.getDirectory();
     filename = fd.getFile();
     if (filename != null) {
        try  {
          BufferedWriter f = new BufferedWriter(new FileWriter(startDirectory + filename));
          int lc = evBrowser.lstEvents.getModel().getSize();

          for (int i = 0; i < lc; i++) {
             f.write((String) evBrowser.lstEvents.getModel().getElementAt(i));
             f.newLine();
          }
          f.close();
          setStatus("File saved: " + startDirectory+filename, false);
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
     }
  }

/**
 * File | SaveLogAsOTML action performed
 */
  public void mnuSaveOTML_actionPerformed(ActionEvent e) {
    //// Popup a dialog with a list showing choices for "Initiating Agent".

    // Strings for the dialog. 
    final String okString = "OK";
    final String cancelString = "Cancel";
    final String helpString = "Help";
    final String helpMessage = 
"An active OTML script uses <send> events to initiate behavior in an OAA system,\n" +
"then uses <toFac> and <fromFac> to match events and confirm the expcted behavior.\n" +
"A passive OTML script has no <send> events. Some application other than OaaTest\n" +
"(perhaps a GUI) initiates behavior and the OTML script uses <toFac> and <fromFac>\n" +
"to confirm the expected behavior.\n" +
"\n" +
"If an 'Initiating Agent' is selected, generate an active script that uses <send>\n" +
"whenever the Initiating Agent sent an event. All other events become <toFac> and <fromFac>.\n" +
"If no agent selected, generate a passive script.";
    String message = 
"Active OTML file: Select Initiating Agent from list.\n" +
"Passive OTML file: Leave list unselected.\n" +
"Click Help for more info.";
    
    // Help button.
    JButton helpButton = new JButton(helpString);
    helpButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(frmMonitor.this,helpMessage,"OTML File Generation Help",
                                      JOptionPane.INFORMATION_MESSAGE);        
      }    
    });

    // Needed to use OTML methods.
    OTML.AgentDatabase agentDB = new OTML.AgentDatabase () {
      public agtInfo findAgentById(String id) {
        return findAgentByIdName(id,null);  
      }
    };

    // Get list of possible Initiating Agents.
    String[] agentNames = OTML.agentsInLog(evBrowser.evtLog.iterator(),agentDB);
 
    // Display the Initiating Agent dialog.
    JList jlist = new JList(agentNames);
    jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jscroll = new JScrollPane(jlist);
    Object[] dialogBody = {message,jscroll};
    // TODO: Help button not quite displayed same way as OK and CANCEL.
    // Windows only, look fine on UNIX.
    int option = JOptionPane.showOptionDialog(this,dialogBody,"OTML File Generation",
      JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,
      new Object [] {okString,cancelString,helpButton},okString);
    switch (option) {
      case JOptionPane.CLOSED_OPTION: // dialog closed
      case 1: // cancel
        return;
      case 0: // ok, continue
        break;
    }

    // Which agent was selected.
    String selectedId = null;
    int selectedIndex = jlist.getSelectedIndex();
    if (selectedIndex >= 0) {
      String name = agentNames[selectedIndex];
      agtInfo info = findAgentByIdName(null,name);
      if (info != null) {
        selectedId = info.shortId;
      }
    }

    // Popup a FileDialog and save file.
    FileDialog fd = new FileDialog(this,"Save Log as OTML",FileDialog.SAVE);
    fd.setFile("*.otml");
    fd.show();
    if (fd.getFile() != null) {
      File file = new File(fd.getDirectory(),fd.getFile());
      try  {        
        OTML.saveLogAsOTML(evBrowser.evtLog.iterator(),file,selectedId,agentDB);
        setStatus("File saved: " + file, false);
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }
   }
  }

 /**
  * Log | Find action performed
  */
  public void mnuFindLog_actionPerformed(ActionEvent e) {
     if ((e == null) || (e.getSource() == mnuFindLog)) {
        String inputValue =
           JOptionPane.showInputDialog(this, "Search for:", "Find", JOptionPane.PLAIN_MESSAGE);
        if ((inputValue != null) && (inputValue.compareTo("") != 0))
           evBrowser.findText(inputValue);
     }
    else evBrowser.findTextAgain();
  }

/**
 * Help | About action performed
 */
  public void helpAbout_actionPerformed(ActionEvent e) {
    OaaAboutDialog dlg = new OaaAboutDialog("OAA Monitor", Version);
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = getSize();
    Point loc = getLocation();
    setStatus(" ", false);
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setVisible(true);
  }

 /**
 * Help | Monitor action performed
 */
  public void help_actionPerformed(ActionEvent e) {
    btnShowLog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    OaaHelpDialog dlg = new OaaHelpDialog(getClass().getResource("monitor_help.html"));
    
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = getSize();
    Point loc = getLocation();
    setStatus(" ", false);
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
//    dlg.setModal(true);
    btnShowLog.setCursor(Cursor.getDefaultCursor());
    dlg.setVisible(true);
  }

/**
 * Profile | Data sizes action performed
 */
  public void mnuProfData_actionPerformed(ActionEvent e) {
     setStatus(" ", false);
     chartWindow.refreshBarInfo();
     chartWindow.setVisible(true);
     chartWindow.toFront();
  }


/**
 * Overriden so we can exit on System Close
 */
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      fileExit_actionPerformed(null);
    }
  }

/**
 * Callback to handle incoming messages
 * <p>
 * @param  goal    Incoming goal routed by Facilitator for execution
 * @param  params  List of params potentially specifying constraints on how goal should be executed.
 * @param  answers AppDoEvent should return any answers to the goal by adding them to this IclList
 * @return         True if the goal was processed by this callback (e.g., answers is valid), false otherwise
 */
  
  public boolean oaaAppDoEvent(IclTerm goal, IclList params, IclList answers) {
 
     // DEBUG
     // System.out.println("------------> In DoEvent");
     // System.out.println("------------> DoEvent : Goal " + goal);
     // System.out.println("------------> DoEvent : Params " + params);
     // System.out.println("Numargs " + goal.iclNumTerms());
     
     // if (answers!=null)
     //   answers.iclAddToList(IclUtils.icl("inform_ui(1,2)"));
    
     // goal will be a structure, so grab it's name and number of args
     String goalName;
     if(goal.isStruct()) {
       goalName = ((IclStruct)goal).getFunctor();
     }
     else {
       goalName = goal.toString();
     }
     int numArgs = goal.size();
     
     // When agents connect or disconnect, the "agent_data" element changes
     // on the facilitator, and a trigger fires this event to notify us
     //   m_data(Op,AgtInfo)  
     //      Op     : remove (quits), add or replace (new agent connects or updates)
     //      AgtInfo: contains list containing agent data  OR
     //               if removing, just the ID for the agent
     if (goalName.equals("m_data") && (numArgs == 2)) {
        IclTerm op = goal.getTerm(0);
        IclTerm info = goal.getTerm(1);
        String opString;
        if(op.isStruct()) {
          opString = ((IclStruct)op).getFunctor();
        }
        else {
          opString = op.toString();
        }
        
        if (opString.equals("remove")) {
           RemoveAgentById(info);
        } else
        if (opString.equals("add")) {
           AddAgentInfo(info, true); // true: first time, request host/version data
        }
        else
        if (opString.equals("replace")) {
           AddAgentInfo(info, false); // false: after first time, don't need host/version anymore
                                      // just update solvables and such
        }
     } else

     // An event trigger sends us all (or selected) send and receive
     // events managed by the Facilitator
     if (goalName.equals("m_ev") && (numArgs == 3)) {
        // Only record if record button says so...

⌨️ 快捷键说明

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