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

📄 aclaidlist.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  }


  /**
   *  Builds up the componenent
   *
   * @exception  Exception  Description of Exception
   */
  private void jbInit() throws Exception {
    this.setLayout(gridBagLayout1);
    viewButton.setBackground(Color.white);
    viewButton.setFont(new java.awt.Font("Dialog", 0, 11));
    viewButton.setForeground(new Color(0, 0, 83));
    viewButton.setMinimumSize(new Dimension(13, 5));
    viewButton.setPreferredSize(new Dimension(13, 11));
    viewButton.setToolTipText("edit/view AgentIDentifier (AID)");
    viewButton.setMargin(new Insets(0, 0, 0, 0));
    viewButton.setText("v");
    viewButton.addActionListener(
      new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          viewButton_actionPerformed(e);
        }
      });
    addButton.setBackground(Color.white);
    addButton.setFont(new java.awt.Font("Dialog", 0, 11));
    addButton.setForeground(new Color(0, 0, 83));
    addButton.setMinimumSize(new Dimension(13, 5));
    addButton.setPreferredSize(new Dimension(13, 11));
    addButton.setToolTipText("add AgentIDentifier (AID)");
    addButton.setMargin(new Insets(0, 0, 0, 0));
    addButton.setText("+");
    addButton.addActionListener(
      new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          addButton_actionPerformed(e);
        }
      });
    deleteButton.setBackground(Color.white);
    deleteButton.setFont(new java.awt.Font("Dialog", 0, 11));
    deleteButton.setForeground(new Color(0, 0, 83));
    deleteButton.setMinimumSize(new Dimension(13, 5));
    deleteButton.setPreferredSize(new Dimension(13, 11));
    deleteButton.setToolTipText("delete AgentIDentifier (AID)");
    deleteButton.setMargin(new Insets(0, 0, 0, 0));
    deleteButton.setText("x");
    deleteButton.addActionListener(
      new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          deleteButton_actionPerformed(e);
        }
      });
    contentList.setCellRenderer(aidListCellRenderer);
    contentList.addKeyListener(
      new java.awt.event.KeyAdapter() {
        public void keyPressed(KeyEvent e) {
          contentList_keyPressed(e);
        }
      });
    contentList.addMouseListener(
      new java.awt.event.MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
          contentList_mouseClicked(e);
        }
      });
    contentScrollPane.setBorder(BorderFactory.createLineBorder(Color.black));
    this.add(addButton, new GridBagConstraints(2, 1, GridBagConstraints.REMAINDER, 1, 0.0, 1.0
      , GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
    this.add(deleteButton, new GridBagConstraints(2, 2, GridBagConstraints.REMAINDER, 1, 0.0, 1.0
      , GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
    this.add(viewButton, new GridBagConstraints(2, 0, GridBagConstraints.REMAINDER, 1, 0.0, 1.0
      , GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
    this.add(contentScrollPane, new GridBagConstraints(0, 0, 1, 3, 1.0, 1.0
      , GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    contentScrollPane.getViewport().add(contentList, null);
  }


  public class AIDListCellRenderer extends JLabel implements ListCellRenderer {
    /**
     *  Constructor for the AIDListCellRenderer object
     */
    public AIDListCellRenderer() {
      setOpaque(true);
      setFont(new java.awt.Font("Dialog", 0, 11));
    }


    /**
     *  Gets the ListCellRendererComponent attribute of the
     *  AIDListCellRenderer object
     *
     * @param  list          Description of Parameter
     * @param  value         Description of Parameter
     * @param  index         Description of Parameter
     * @param  isSelected    Description of Parameter
     * @param  cellHasFocus  Description of Parameter
     * @return               The ListCellRendererComponent value
     */
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      if ((value != null) && (value instanceof AID)) {
        AID theAID = (AID)value;
        setText(theAID.getName());
      }
      setBackground(isSelected ? Color.blue : Color.white);
      setForeground(isSelected ? Color.white : Color.black);
      return this;
    }
  }


  /**
   *  This class listenes to the AIDList
   *
   * @author     Chris van Aart - Acklin B.V., the Netherlands
   * @created    April 26, 2002
   */

  public class AIDListListener implements ListDataListener {
    /**
     *  Description of the Method
     *
     * @param  obj        Description of Parameter
     * @param  fieldName  Description of Parameter
     */
    public void register(Object obj, String fieldName) {
      itsObj = obj;
      this.fieldName = fieldName;
    }


    /**
     *  Description of the Method
     *
     * @param  parm1  Description of Parameter
     */
    public void intervalAdded(ListDataEvent parm1) {
      DefaultListModel lm = (DefaultListModel)parm1.getSource();
      int index = parm1.getIndex0();
      AID newAID = (AID)lm.elementAt(index);
      String methodName = "add" + fieldName;
      String theType = "jade.core.AID";
      try {
        Method sn = itsObj.getClass().getMethod(methodName, new Class[]{Class.forName(theType)});
        Object os = newAID;
        sn.invoke(itsObj, new Object[]{os});
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }

    }


    /**
     *  Description of the Method
     *
     * @param  theRemovedAID  Description of Parameter
     */
    public void registerRemovedAID(AID theRemovedAID) {
      this.theRemovedAID = theRemovedAID;
    }


    /**
     *  Description of the Method
     *
     * @param  theChangedAID  Description of Parameter
     */
    public void registerChangedAID(AID theChangedAID) {
      this.theChangedAID = theChangedAID;
    }


    /**
     *  Description of the Method
     *
     * @param  parm1  Description of Parameter
     */
    public void intervalRemoved(ListDataEvent parm1) {
      String methodName = "remove" + fieldName;
      String theType = "jade.core.AID";
      try {
        Method sn = itsObj.getClass().getMethod(methodName, new Class[]{Class.forName(theType)});
        Object os = theRemovedAID;
        sn.invoke(itsObj, new Object[]{os});
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }
    }


    /**
     *  Description of the Method
     *
     * @param  parm1  Description of Parameter
     */
    public void contentsChanged(ListDataEvent parm1) {
      DefaultListModel lm = (DefaultListModel)parm1.getSource();
      int index = parm1.getIndex0();
      if (index < 0) {
        return;
      }

      String removeMethodName = "remove" + fieldName;
      String addMethodName = "remove" + fieldName;

      AID currentAID = (AID)lm.get(index);

      String theType = "jade.core.AID";
      try {
        Method removeMethod = itsObj.getClass().getMethod(removeMethodName, new Class[]{Class.forName(theType)});
        removeMethod.invoke(itsObj, new Object[]{currentAID});

        Method addMethod = itsObj.getClass().getMethod(addMethodName, new Class[]{Class.forName(theType)});
        removeMethod.invoke(itsObj, new Object[]{theChangedAID});
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }

    }


    String fieldName = "";

    private AID theRemovedAID, theChangedAID;

    private Object itsObj;
  }


  private String MSG = "msg";
  private String AID = "Aid";
  private JScrollPane contentScrollPane = new JScrollPane();
  private JList contentList = new JList();

  private GridBagLayout gridBagLayout1 = new GridBagLayout();
  private JButton viewButton = new JButton();
  private JButton addButton = new JButton();
  private JButton deleteButton = new JButton();

  private DefaultListModel listModel = new DefaultListModel();
  private AIDListCellRenderer aidListCellRenderer = new AIDListCellRenderer();
  private boolean editable = true;
  private String fieldName = "";
  private String mode = MSG;
  private Agent agent;
  private AIDListListener theDataListener;
  private ACLMessage itsMsg;
  private AID itsAid;
  private Object itsObj;

}
//  ***EOF***

⌨️ 快捷键说明

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