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

📄 frmevbrowser.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               agt.bytesSent = agt.bytesSent + ev.length();
               if (agt.bytesSent > fMonitor.maxBytesSent)
                  fMonitor.maxBytesSent = agt.bytesSent;
               fMonitor.totalBytesSent = fMonitor.totalBytesSent + agt.bytesSent;
            }

            // Update agent info screen
            if ((fMonitor.selectedAgent != null) &&
                (agt.id.compareTo(fMonitor.selectedAgent.id) == 0) &&
                (agt.name.compareTo(fMonitor.selectedAgent.name) == 0)) {
                 fMonitor.lblAgentSend.setText("Sent: " + agt.bytesSent + " bytes");
                 fMonitor.lblAgentReceive.setText("Received: " + agt.bytesReceived + " bytes");
            }
            fMonitor.lblTotalMsgs.setText("Total # msgs: " + evtLog.size());
            fMonitor.lblTotalBytes.setText("Total bytes: " + (fMonitor.totalBytesSent + fMonitor.totalBytesReceived));

            // Update profile chart
            if (fMonitor.chartWindow.isVisible()) {
               int barNum = fMonitor.agtList.indexOf(agt);
               if (barNum != -1)
                  if (fMonitor.chartWindow.rbSent.isSelected()) {
                    fMonitor.chartWindow.histo.setValue(barNum, agt.bytesSent);
                    fMonitor.chartWindow.histo.setMaxValue(fMonitor.maxBytesSent * 120 / 100);
                  }
                  else {
                    fMonitor.chartWindow.histo.setValue(barNum, agt.bytesReceived);
                    fMonitor.chartWindow.histo.setMaxValue(fMonitor.maxBytesReceived * 120 / 100);
                  }
            }
         }

         // If this doesn't appear intuitive, remember that the event OP is seen from
         // the perspective of the Facilitator.  If it is sending the event, our
         // agent receives it.
         if (op.compareTo("send") == 0) {
             op = "<<<";
         }
         if (op.compareTo("receive") == 0) {
             op = ">>>";
         }

         if (addToLog) {
            String t[] = new String[2];
            String s;
            Integer numSolutions = new Integer(1);
            s = evtLog.size()+": "+agt.name + " (" + agt.shortId + ") " + op +" " +
                 formatEvent(ev, true);
            // A very strange bug happens if s gets too big...
            if (s.length() > 4195) s = s.substring(0, 4195);
            evtLogF.addElement(s);
            // If there are multiple solutions, break them out and format them one per line
            if (lastSolutions != null) 
               // Remember: iclNthTerm(I) is 1-based, not 0-based!
               for (int i = 0; i < lastSolutions.size(); i++) {
                  s = "      " + numSolutions.toString() + ". " + lastSolutions.getTerm(i).toString();
                  // A very strange bug happens if s gets too big...
                  if (s.length() > 4195) s = s.substring(0, 4195);
                  evtLogF.addElement(s);
                  numSolutions = new Integer(numSolutions.intValue() + 1);
               }
            lastSolutions = null;
         }

         // Add to log trace window
         if (addToWindow && this.isVisible()) {
            if (chkOneAgent.isSelected() && (fMonitor.selectedAgent != null)) {
               // Going to be slow, should be optimized, but relatively rare case
               //  ( running with event window open and chkOneAgent selected)
               if (fMonitor.selectedAgent == agt) {
                  chkOneAgent_actionPerformed(null);
               }
            }
            else {
               if (rbHighLevel.isSelected())
                  lstEvents.setListData(evtLogF);
               else lstEvents.setListData(evtLog);
               lstEvents.repaint();
            }
         }

         // Draw arrow on screen
         if (drawGraphic && fMonitor.mnuDrawGraphics.getState()) {
            String fev = formatEvent(ev, rbHighLevel.isSelected());
            fMonitor.setStatus(fev, true);
            fMonitor.lblStatus.setToolTipText(fev);
            fMonitor.btnNextEvent.setToolTipText(fev);
            drawMsgArrow(agt, (op.compareTo("<<<") == 0));
         }
      }
      else System.out.println("Error: event trigger for unknown AgtId: "+AgtId+"\n  "+event.toString());
  }

  // Given an event index, looks up its position and then
  // highlights the entire line
  void highlightEvent(int evtAt) {
     ListModel L = lstEvents.getModel();
     if (this.isVisible()) {
        if (rbHighLevel.isSelected() ||
              (chkOneAgent.isSelected() && (fMonitor.selectedAgent != null))) {
           int i;
           int p;
           Integer I = new Integer(-1);
           String ev;

           // Try to get a headstart...
           if (chkOneAgent.isSelected())
              i = 0;
           else i = evtAt;

           if ((i >= 0) && (i < L.getSize()) && (evtAt >= 0)) {
              while ((i < L.getSize()) && (I.intValue() != evtAt + 1)) {
                  ev = (String) L.getElementAt(i);
                  p = ev.indexOf(": ");
                  if ((p > 0) && (p < 7))
                     I = new Integer(ev.substring(0, p));
                  i = i + 1;
              }
              if (I.intValue() == evtAt+1) {
                 lstEvents.setSelectedIndex(i-1);
                 setScrollVisible((i-1), L.getSize());
              }
              else lstEvents.setSelectedIndex(-1);
           }
           else lstEvents.setSelectedIndex(-1);  // Erase selection
        }
        // evtAt = line selection for rbLowLevel...
        else {
           lstEvents.setSelectedIndex(evtAt);
           setScrollVisible(evtAt, L.getSize());
        }
     }
  }

  /**
   * Position the listbox scrollbar so the selected index is visible.
   */
  void setScrollVisible(int index, int max) {
    JScrollBar j = jScrollPane1.getVerticalScrollBar();
    j.setValue(index * j.getMaximum() / max);
  }

  void findText(String text) {
     findStr = text;
     findPos = -1;
     findTextAgain();
  }

  void findTextAgain() {
     if (!this.isVisible()) {
        this.setVisible(true);
        rbLevel_actionPerformed(null);
     }
     fMonitor.setStatus(" ", false);
     if (findStr.compareTo("") == 0)
        fMonitor.mnuFindLog_actionPerformed(null);
     else {
        boolean found = false;
        String s;
        if (lstEvents.getSelectedIndex() >= 0)
           findPos = lstEvents.getSelectedIndex() + 1;
        while ((findPos < lstEvents.getModel().getSize()) && !found) {
           s = (String) lstEvents.getModel().getElementAt(findPos);
           found = s.indexOf(findStr) >= 0;
           findPos = findPos + 1;
        }
        if (!found) {
           fMonitor.setStatus("'" + findStr + "' not found in log window.", true);
           findPos = -1;
        }
        else {
           lstEvents.setSelectedIndex(findPos-1);
           setScrollVisible((findPos-1), lstEvents.getModel().getSize());
           this.toFront();
        }
     }
  }

  // Erases the event log and clears the log window
  public void btnClear_actionPerformed(ActionEvent e) {
    evtLog.removeAllElements();
    evtLogF.removeAllElements();
    lstEvents.setListData(evtLog);
    lstEvents.repaint();
    enableEventFunctions(false);
    evtAt = -1;
    fMonitor.resetAllAgentInfo();
  }

  // Pops up the SetFilter window
  void btnFilter_actionPerformed(ActionEvent e) {
    fMonitor.mnuSetFilter_actionPerformed(e);
  }

  // Used by both "level" radio buttons
  // Redraws the event log window at the right level of detail
  void rbLevel_actionPerformed(ActionEvent e) {
    if (rbHighLevel.isSelected())
       lstEvents.setListData(evtLogF);
    else lstEvents.setListData(evtLog);
    highlightEvent(evtAt);
    lstEvents.repaint();
  }

  // Steps to the next event (either overall or for specific agent)
  void nextEvent() {
     String ev;
     int p;
     if (chkOneAgent.isSelected() && (fMonitor.selectedAgent != null)) {
        String id;
        do {
          evtAt = evtAt + 1;
          if (evtAt < evtLog.size()) {
             ev = (String) evtLog.elementAt(evtAt);
             p = ev.indexOf(": ");
             if ((p > 0) && (p < 7))
                ev = ev.substring(p + 2);

             // ev = OP, ID, EVENT
             id = (IclTerm.fromString(true, ev).getTerm(1)).toString();
          }
          else id = "";
        }
        while ((evtAt < evtLog.size()) &&
               (fMonitor.selectedAgent.shortId.compareTo(id) != 0));
     }
     else evtAt = evtAt + 1;
     if (evtAt >= evtLog.size()) {
        fMonitor.setStatus("End of event list -- reset to beginning.", false);
        // Erase last arrow
        drawMsgArrow(null, false);
        evtAt = -1;
     }
     else {
        ev = (String) evtLog.elementAt(evtAt);
        p = ev.indexOf(": ");
        if ((p > 0) && (p < 7))
           ev = ev.substring(p + 2);
        addEvent(IclTerm.fromString(true, ev), false, false, true);
     }
     highlightEvent(evtAt);
 }

  // Steps to the next event (either overall or for specific agent)
  void prevEvent() {
     String ev;
     int p;
     if (chkOneAgent.isSelected() && (fMonitor.selectedAgent != null)) {
        String id;
        do {
          evtAt = evtAt - 1;
          if (evtAt > -1) {
             ev = (String) evtLog.elementAt(evtAt);
             p = ev.indexOf(": ");
             if ((p > 0) && (p < 7))
                ev = ev.substring(p + 2);

             // ev = OP, ID, EVENT
             id = (IclTerm.fromString(true, ev).getTerm(1)).toString();
          }
          else id = "";
        }
        while ((evtAt > -1) &&
               (fMonitor.selectedAgent.shortId.compareTo(id) != 0));
     }
     else evtAt = evtAt - 1;
     if (evtAt < 0) {
        fMonitor.setStatus("Beginning of event list.", false);
        // Erase last arrow
        drawMsgArrow(null, false);
        evtAt = -1;
     }
     else {
        ev = (String) evtLog.elementAt(evtAt);
        p = ev.indexOf(": ");
        if ((p > 0) && (p < 7))
           ev = ev.substring(p + 2);
        addEvent(IclTerm.fromString(true, ev), false, false, true);
     }
     highlightEvent(evtAt);
  }

  // Resets the event pointer to the beginning
  void firstEvent() {
     fMonitor.setStatus("Beginning of event list.", false);
     evtAt = -1;
     // Erase last arrow
     drawMsgArrow(null, false);
     highlightEvent(evtAt);
  }

  // Resets the event pointer to the end
  void lastEvent() {
     fMonitor.setStatus("End of event list.", false);
     evtAt = evtLog.size();
     // Erase last arrow
     drawMsgArrow(null, false);
     highlightEvent(evtAt);
  }

  // If chkOneAgent is selected, set display so that only events
  // for the currently active agent are displayed
  void chkOneAgent_actionPerformed(ActionEvent e) {
    String line;
    int p;
    String ks;
    String op;
    String ev;
    String t[] = new String[2];
    agtInfo agt;
    IclTerm stLine;
    Integer numSolutions = new Integer(1);
    Vector agtEvents = new Vector();
    if (chkOneAgent.isSelected() && (fMonitor.selectedAgent != null)) {

        for (int i=0; i < evtLog.size(); i++) {
           line = (String) evtLog.elementAt(i);
           // in form    LINENUM: m_ev(Op,AgtId,Event)
           p = line.indexOf(": ");
           if ((p > 0) && (p < 7))
              line = line.substring(p + 2);
           stLine = IclTerm.fromString(true, line);
           op = stLine.getTerm(0).toString();
           ks = stLine.getTerm(1).getTerm(1).toString();
           ev = stLine.getTerm(2).toString();
           if (ks.compareTo(fMonitor.selectedAgent.shortId) == 0) {
              if (rbHighLevel.isSelected()) {
                  agt = fMonitor.findAgentByIdName(ks, null);
                  if (agt != null) {
                     // If this doesn't appear intuitive, remember that the event OP is seen from
                     // the perspective of the Facilitator.  If it is sending the event, our
                     // agent receives it.
                     if (op.compareTo("send") == 0)
                         op = "<<<";
                     if (op.compareTo("receive") == 0)
                         op = ">>>";
                     agtEvents.addElement((i+1)+": "+agt.name + " (" + agt.id + ") " + op +" " +
                          formatEvent(ev, true));
                     // If there are multiple solutions, break them out and format them one per line
                     if (lastSolutions != null)
                        // Remember: iclNthTerm(I) is 1-based, not 0-based!
                        for (int k = 0; k < lastSolutions.size(); k++) {
                           agtEvents.addElement("      " + numSolutions.toString() + ". " + lastSolutions.getTerm(k).toString());
                           numSolutions = new Integer(numSolutions.intValue() + 1);
                        }
                     lastSolutions = null;
                  }
              }
              else {
                 agtEvents.addElement(evtLog.elementAt(i));
              }
           }
        }
        lstEvents.setListData(agtEvents);
        evtAt = -1;
        highlightEvent(evtAt);
        lstEvents.repaint();
    }
    else rbLevel_actionPerformed(e);
  }

  void lstEvents_keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_F3)
       findTextAgain();
    else
    if ((e.getKeyCode() == KeyEvent.VK_F) && (e.isControlDown()))
       fMonitor.mnuFindLog_actionPerformed(null);
  }

  void enableEventFunctions(boolean eventsExist) {
     fMonitor.btnNextEvent.setEnabled(eventsExist);
     fMonitor.btnPrevEvent.setEnabled(eventsExist);
     fMonitor.btnFirstEvent.setEnabled(eventsExist);
     fMonitor.btnLastEvent.setEnabled(eventsExist);
     fMonitor.mnuFindLog.setEnabled(eventsExist);
     fMonitor.mnuFindAgain.setEnabled(eventsExist);
     fMonitor.mnuSaveLog.setEnabled(eventsExist);
     fMonitor.mnuSaveOTML.setEnabled(eventsExist);
     fMonitor.mnuClearLog.setEnabled(eventsExist);
     fMonitor.mnuChartData.setEnabled(eventsExist);
  }


  // Used so that we can pack the window to refresh, using last real size
  void this_componentResized(ComponentEvent e) {
//       Dimension D = this.getSize();
//      D.setSize(D.width - 8, D.height - jToolBar1.getHeight() - 32);
//      jScrollPane1.setPreferredSize(D);
  }
}


⌨️ 快捷键说明

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