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

📄 acltracepanel.java

📁 JADE(JAVA Agent开发框架)是一个完全由JAVA语言开发的软件,它简化了多Agent系统的实现。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

          StringACLCodec codec = new StringACLCodec(new StringReader(new String(chararray)), null);
          ACLMessage theMsg = codec.decode();

          this.addMessageNode(direction, theTime, theMsg);

        }
        br.close();
        f.close();

      }
      catch (FileNotFoundException e3) {
        if(logger.isLoggable(Logger.WARNING))
        	logger.log(Logger.WARNING,"Can't open file: " + fileName);
      }
      catch (IOException e4) {
        if(logger.isLoggable(Logger.WARNING))
        	logger.log(Logger.WARNING,"IO Exception");
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }


  public void clearACLModel() {

    int size = aclModel.getChildCount(this.aclRoot);
    for (int i = size - 1; i >= 0; i--) {
      ACLMessageNode theNode = (ACLMessageNode)aclModel.getChild(this.aclRoot, i);
      this.aclRoot.remove(theNode);
    }
    this.aclIndex = 0;
    this.aclModel.reload();
    aclTree.validate();
    aclTree.repaint();
  }


  public void doSort() {

    int direction = this.sortComboBox.getSelectedIndex();
    int ascending = (this.ascRadioButton.isSelected() ? 1 : -1);
    ACLMessageNodeComparator anc = new ACLMessageNodeComparator(direction, ascending);
    int size = aclModel.getChildCount(this.aclRoot);
    if (size < 2) {
      return;
    }
    Object[] theList = new Object[size];

    for (int i = 0; i < size; i++) {
      ACLMessageNode theNode = (ACLMessageNode)aclModel.getChild(this.aclRoot, i);
      theList[i] = theNode;
    }

    java.util.Arrays.sort(theList, anc);
    this.clearACLModel();
    sorting = true;
    for (int i = 0; i < size; i++) {
      ACLMessageNode theNode = (ACLMessageNode)theList[i];
      this.addMessageNode(theNode);
    }
    sorting = false;
    this.aclModel.reload();
    aclTree.validate();
    aclTree.repaint();

  }



  /**
   *  Gets the TimeStamp attribute of the ACLTreePanel object
   *
   * @return    The TimeStamp value
   */
  String getTimeStamp() {

    return dateFormat.format(new Date());
  }


  /**
   *  refresh the List
   */
  void refresh() {
    aclTree.validate();
    aclTree.updateUI();
  }


  /**
   *  triggered when mousePressed
   *
   * @param  e  the MouseEvent
   */
  void aclTree_mouseClicked(MouseEvent e) {
    try {
	//since JDK1.3 TreePath tp = aclTree.getAnchorSelectionPath();
      TreePath tp = aclTree.getSelectionPath();
      if (tp == null) {
        currentACL = null;
      }

      else {
        currentACL = ((ACLMessageNode)tp.getPathComponent(1)).getMessage();
      }

      if (e.getModifiers() == 4) {
        if (currentACL == null) {
          JOptionPane.showMessageDialog(null, "No ACL", "Select a Message", JOptionPane.ERROR_MESSAGE);
          return;
        }
        x = e.getX();
        y = e.getY();
        this.thePopupMenu.show(this, e.getX(), e.getY());
      }
      if ((e.getModifiers() == 16) && (e.getClickCount() == 2)) {
        if (currentACL == null) {
          JOptionPane.showMessageDialog(null, "No ACL", "Select a Message", JOptionPane.ERROR_MESSAGE);
          return;
        }
        showCurrentACL(e.getX(), e.getY());
      }
    }
    catch (Exception ex) {
      //index out of range
    }
  }


  /**
   *  triggered when systemMenuItem
   *
   * @param  e  ActionEvent
   */
  void systemMenuItem_actionPerformed(ActionEvent e) {
    if (currentACL == null) {
      return;
    }
  }


  /**
   *  showCurrentACL
   *
   * @param  e  ActionEvent
   */
  void zoomMenuItem_actionPerformed(ActionEvent e) {
    doShowCurrentACL();
  }


  /**
   *  saveACL
   *
   * @param  e  ActionEvent
   */
  void saveMenuItem_actionPerformed(ActionEvent e) {
    saveACL();
  }


  /**
   *  show ACLStatisticsFrame
   *
   * @param  e  ActionEvent
   */
  void stasticsMenuItem_actionPerformed(ActionEvent e) {
    showStastistics();
  }



  /**
   *  listener for keyTyped
   *
   * @param  e  KeyEvent
   */
  void aclTree_keyTyped(KeyEvent e) {
    if (e.getKeyCode() == e.VK_DELETE) {
      deleteCurrent();
    }

  }


  /**
   *  deleteMenuItem
   *
   * @param  e  ActionEvent
   */
  void deleteMenuItem_actionPerformed(ActionEvent e) {
    this.deleteCurrent();
  }


  void sortButton_actionPerformed(ActionEvent e) {
    this.doSort();
  }


  void sortComboBox_itemStateChanged(ItemEvent e) {
    doSort();
  }


  void ascRadioButton_itemStateChanged(ItemEvent e) {
    doSort();
  }


  void descRadioButton_itemStateChanged(ItemEvent e) {
    doSort();
  }


  void aboutMenuItem_mouseClicked(MouseEvent e) {
    this.doShowAbout();
  }


  void saveQMenuItem_actionPerformed(ActionEvent e) {
    this.saveQueue();
  }


  void clearQMenuItem_actionPerformed(ActionEvent e) {
    this.clearACLModel();
  }


  void openQMenuItem_actionPerformed(ActionEvent e) {
    this.loadQueue();
  }


  void aboutMenuItem_actionPerformed(ActionEvent e) {
    this.doShowAbout();
  }



  private void fillSortComboBoxModel() {
    sortComboBoxModel.addElement("date");
    sortComboBoxModel.addElement("direction");
    sortComboBoxModel.addElement("sender");
    sortComboBoxModel.addElement("receiver");
    sortComboBoxModel.addElement("performative");
    sortComboBoxModel.addElement("ontology");
  }



  /**
   *  show the Current ACLMessage
   *
   * @param  x  x location
   * @param  y  y location
   */
  private void showCurrentACL(int x, int y) {
    if (currentACL == null) {
      return;
    }
    ACLFrame.show(currentACL, agent);
  }


  /**
   *  build up TreePanel
   *
   * @exception  Exception  Description of Exception
   */
  private void jbInit() throws Exception {
    border1 = BorderFactory.createLineBorder(Color.black, 2);
    titledBorder1 = new TitledBorder(border1, "actions");
    border2 = BorderFactory.createLineBorder(Color.black, 0);
    border3 = BorderFactory.createLineBorder(Color.darkGray, 1);
    this.setLayout(gridBagLayout2);
    aclTree.setModel(aclModel);
    aclTree.addKeyListener(new ACLTreePanel_aclTree_keyAdapter(this));
    aclTree.addMouseListener(new ACLTreePanel_aclTree_mouseAdapter(this));
    this.addMouseListener(new ACLTreePanel_this_mouseAdapter(this));
    systemMenuItem.setBackground(Color.white);
    systemMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    systemMenuItem.setMnemonic('O');
    systemMenuItem.setText("System.out");
    systemMenuItem.addActionListener(new ACLTreePanel_systemMenuItem_actionAdapter(this));
    zoomMenuItem.setBackground(Color.white);
    zoomMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    zoomMenuItem.setMnemonic('V');
    zoomMenuItem.setText("View ACLMessage");
    zoomMenuItem.addActionListener(new ACLTreePanel_zoomMenuItem_actionAdapter(this));
    thePopupMenu.setBackground(Color.white);
    thePopupMenu.setBorder(BorderFactory.createLineBorder(Color.black));
    thePopupMenu.setOpaque(false);
    saveMenuItem.setBackground(Color.white);
    saveMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    saveMenuItem.setMnemonic('S');
    saveMenuItem.setText("Save ACLMessage");
    saveMenuItem.addActionListener(new ACLTreePanel_saveMenuItem_actionAdapter(this));
    stasticsMenuItem.setBackground(Color.white);
    stasticsMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    stasticsMenuItem.setMnemonic('T');
    stasticsMenuItem.setText("Show Statistics");
    stasticsMenuItem.addActionListener(new ACLTreePanel_stasticsMenuItem_actionAdapter(this));
    aboutMenuItem.setBackground(Color.white);
    aboutMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    aboutMenuItem.setForeground(new Color(0, 0, 140));
    aboutMenuItem.setMnemonic('A');
    aboutMenuItem.setText("About");
    aboutMenuItem.addActionListener(new ACLTracePanel_aboutMenuItem_actionAdapter(this));
    deleteMenuItem.setBackground(Color.white);
    deleteMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    deleteMenuItem.setMnemonic('D');
    deleteMenuItem.setText("Delete ACLMessage");
    deleteMenuItem.addActionListener(new ACLTreePanel_deleteMenuItem_actionAdapter(this));
    jLabel1.setBackground(Color.white);
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel1.setOpaque(true);
    jLabel1.setText("sort by:");
    ascRadioButton.setSelected(true);
    ascRadioButton.setText("Ascending");
    ascRadioButton.setToolTipText("Sort ACLMessage Trace Ascending");
    ascRadioButton.setBackground(Color.white);
    ascRadioButton.setFont(new java.awt.Font("Dialog", 0, 12));
    ascRadioButton.addItemListener(new ACLTracePanel_ascRadioButton_itemAdapter(this));
    descRadioButton.setText("Descending");
    descRadioButton.setToolTipText("Sort ACLMessage Trace Descending");
    descRadioButton.setBackground(Color.white);
    descRadioButton.setFont(new java.awt.Font("Dialog", 0, 12));
    descRadioButton.addItemListener(new ACLTracePanel_descRadioButton_itemAdapter(this));
    sortButton.setForeground(Color.white);
    sortButton.setBorder(border2);
    sortButton.setMaximumSize(new Dimension(23, 20));
    sortButton.setPreferredSize(new Dimension(23, 20));
    sortButton.setToolTipText("Sort ACLMessage Trace");
    sortButton.setIcon(sortIcon);
    sortButton.addActionListener(new ACLTracePanel_sortButton_actionAdapter(this));
    sortButton.addActionListener(new ACLTracePanel_sortButton_actionAdapter(this));

    this.setBackground(Color.white);
    sortComboBox.setBackground(Color.white);
    sortComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
    sortComboBox.setForeground(Color.blue);
    sortComboBox.setToolTipText("Select on which field to sort the ACLMessage Trace");
    sortComboBox.addItemListener(new ACLTracePanel_sortComboBox_itemAdapter(this));
    aclTreeScrollPane.setBorder(border3);
    saveQMenuItem.setBackground(Color.white);
    saveQMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    saveQMenuItem.setMnemonic('A');
    saveQMenuItem.setText("Save ACLMessage Trace");
    saveQMenuItem.addActionListener(
      new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          saveQMenuItem_actionPerformed(e);
        }
      });
    openQMenuItem.setBackground(Color.white);
    openQMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    openQMenuItem.setMnemonic('P');
    openQMenuItem.setText("Open ACLMessage Trace");
    openQMenuItem.addActionListener(new ACLTracePanel_openQMenuItem_actionAdapter(this));
    clearQMenuItem.setBackground(Color.white);
    clearQMenuItem.setFont(new java.awt.Font("Dialog", 0, 11));
    clearQMenuItem.setMnemonic('C');
    clearQMenuItem.setText("Clear ACLMessage Trace");
    clearQMenuItem.addActionListener(new ACLTracePanel_clearQMenuItem_actionAdapter(this));
    this.add(aclTreeScrollPane, new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0
      , GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    this.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
      , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.add(sortComboBox, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
      , GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    this.add(ascRadioButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
      , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.add(descRadioButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
      , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.add(sortButton, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
      , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    aclTreeScrollPane.getViewport().add(aclTree, null);
    thePopupMenu.add(systemMenuItem);
    thePopupMenu.add(zoomMenuItem);
    thePopupMenu.addSeparator();
    thePopupMenu.add(saveMenuItem);
    thePopupMenu.add(deleteMenuItem);
    thePopupMenu.addSeparator();
    thePopupMenu.add(saveQMenuItem);
    thePopupMenu.add(openQMenuItem);
    thePopupMenu.add(clearQMenuItem);
    thePopupMenu.addSeparator();
    thePopupMenu.add(stasticsMenuItem);
    thePopupMenu.add(aboutMenuItem);
    sortingButtonGroup.add(ascRadioButton);
    sortingButtonGroup.add(descRadioButton);
  }


  private class ACLMessageNodeComparator implements Comparator {

    public ACLMessageNodeComparator(int mode, int sorting) {
      this.mode = mode;
      this.sorting = sorting;
    }


    public int compare(Object o1, Object o2) {
      ACLMessageNode node1 = (ACLMessageNode)o1;
      ACLMessageNode node2 = (ACLMessageNode)o2;

      String comp1 = "";
      String comp2 = "";

      switch (mode) {
        case DIRECTION:
          comp1 = (node1.getDirection() != null ? node1.getDirection() : "");
          comp2 = (node2.getDirection() != null ? node2.getDirection() : "");
          break;
        case DATE:
          Date date1 = node1.getTheDate();
          Date date2 = node2.getTheDate();
          return sorting * date1.compareTo(date2);
        case SENDER:
          comp1 = (node1.getMessage().getSender() != null ? node1.getMessage().getSender().getName() : "");
          comp2 = (node2.getMessage().getSender() != null ? node2.getMessage().getSender().getName() : "");
          break;
        case RECEIVER:
          comp1 = (node1.getMessage().getAllReceiver().hasNext() ? ((AID)node1.getMessage().getAllReceiver().next()).getName() : "");
          comp2 = (node2.getMessage().getAllReceiver().hasNext() ? ((AID)node2.getMessage().getAllReceiver().next()).getName() : "");
          break;
        case PERFORMATIVE:
          comp1 = ACLMessage.getPerformative(node1.getMessage().getPerformative());
          comp2 = ACLMessage.getPerformative(node2.getMessage().getPerformative());
          break;
        case ONTOLOGY:
          comp1 = (node1.getMessage().getOntology() != null ? node1.getMessage().getOntology() : "");
          comp2 = (node2.getMessage().getOntology() != null ? node2.getMessage().getOntology() : "");
          break;
      }

      return sorting * comp1.compareTo(comp2);

⌨️ 快捷键说明

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