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

📄 frmchart.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
//Title:        Chart Window
//Version:
//Copyright:    Copyright (c) 1999
//Author:       Adam Cheyer
//Company:      SRI International
//Description:  Displays profiling charts

/**
 * 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.
*/

package com.sri.oaa2.agt.monitor;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.html.*;
import java.awt.event.*;


public class frmChart extends JFrame {
  BorderLayout borderLayout1 = new BorderLayout();
  JScrollPane jScrollPane1 = new JScrollPane();
  JToolBar jToolBar1 = new JToolBar();
  JRadioButton rbSent = new JRadioButton();
  JRadioButton rbReceived = new JRadioButton();
  Histogram histo = new Histogram();
  JButton btnTest = new JButton();
  JLabel lblStatus = new JLabel();

  // Class variables -----------------------------------
  frmMonitor fMonitor;

  public frmChart(frmMonitor f) {
    try  {
      fMonitor = f;
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }


  private void jbInit() throws Exception {

    // Main window
    this.getContentPane().setLayout(borderLayout1);

    histo.setSuffix(" bytes");
    histo.setRoundsValue(true);
    histo.setCentered(false);
    histo.setLeftJustified(true);
    histo.setShowZeroValue(true);
    histo.setPreferredSize(new Dimension(500,300));

    rbSent.setText("Sent");
    rbSent.setSelected(true);
    rbSent.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        rbSentReceived_actionPerformed(e);
      }
    });
    rbReceived.setText("Received");
    rbReceived.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        rbSentReceived_actionPerformed(e);
      }
    });
    btnTest.setText("TEST");
    btnTest.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
         fMonitor.resetAllAgentInfo();
         refreshBarInfo();
      }
    });
//     jToolBar1.add(btnTest);
    jToolBar1.add(rbSent);
    jToolBar1.add(rbReceived);

    lblStatus.setText(" ");

    // Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(rbSent);
    group.add(rbReceived);

    this.getContentPane().add(jToolBar1, BorderLayout.NORTH);
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    this.getContentPane().add(lblStatus, BorderLayout.SOUTH);
    jScrollPane1.getViewport().add(histo);
  }

  void refreshBarInfo() {
     histo.removeAllBars();
     if (rbSent.isSelected()) {
        histo.setMaxValue(fMonitor.maxBytesSent * 120 / 100);
        lblStatus.setText("Total bytes sent: " + fMonitor.totalBytesSent);
     }
     else {
        histo.setMaxValue(fMonitor.maxBytesReceived * 120 / 100);
        lblStatus.setText("Total bytes received: " + fMonitor.totalBytesReceived);
     }

     for (int i = 0, count = 0; i < fMonitor.agtList.size(); i++) {
        agtInfo agt = (agtInfo) fMonitor.agtList.elementAt(i);
        // Print all agents except Facilitator...
        if (!agt.shortId.equals("0")) {
           histo.addSeries(" " + agt.name + " (" + agt.shortId + ") ", Color.green);
           histo.setPrecision(0);
           if (rbSent.isSelected())
              histo.setValue(count, agt.bytesSent);
           else
              histo.setValue(count, agt.bytesReceived);
           count = count + 1;
        }
     }
     repaint();
     pack();
  }

  public void rbSentReceived_actionPerformed(ActionEvent e) {
     for (int i = 0, count = 0; i < fMonitor.agtList.size(); i++) {
        agtInfo agt = (agtInfo) fMonitor.agtList.elementAt(i);
        // Do for all agents except Facilitator
        if (!agt.shortId.equals("0")) {
           if (e.getSource() == rbSent) {
              histo.setValue(count, agt.bytesSent);
           }
           else {
              histo.setValue(count, agt.bytesReceived);
           }
           count = count + 1;
        }
     }
     if (e.getSource() == rbSent) {
        lblStatus.setText("Total bytes sent: " + fMonitor.totalBytesSent);
        histo.setMaxValue(fMonitor.maxBytesSent * 120 / 100);
     } else {
        lblStatus.setText("Total bytes received: " + fMonitor.totalBytesReceived);
        histo.setMaxValue(fMonitor.maxBytesReceived * 120 / 100);
     }
  }

}


⌨️ 快捷键说明

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