📄 aclaidlist.java
字号:
/******************************************************************
* JADE - Java Agent DEvelopment Framework is a framework to develop
* multi-agent systems in compliance with the FIPA specifications.
* Copyright (C) 2002 TILAB S.p.A.
*
* This file is donated by Acklin B.V. to the JADE project.
*
*
* GNU Lesser General Public License
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation,
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* ***************************************************************/
package jade.tools.gui;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import java.lang.reflect.*;
import javax.swing.*;
import javax.swing.DefaultListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import jade.core.AID;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;
import jade.util.leap.Iterator;
/**
* This class is used to show a list of AIDs. AIDs can be edited, inserted
* and deleted.
*
* @author Chris van Aart - Acklin B.V., the Netherlands
* @created April 26, 2002
*/
public class ACLAIDList extends JPanel {
/**
* Constructor for the ACLAIDList object
*
* @param agent link to agent
*/
public ACLAIDList(Agent agent) {
this.agent = agent;
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the Editable attribute of the ACLAIDList object
*
* @param theBool The new Editable value
*/
public void setEditable(boolean theBool) {
if (!theBool) {
editable = false;
this.addButton.setEnabled(false);
this.deleteButton.setEnabled(false);
}
}
/**
* register Object and accompagnied field name in ACLMessage
*
* @param fieldName the fieldname
* @param o Description of Parameter
*/
public void register(Object o, String fieldName) {
listModel.removeAllElements();
this.itsObj = o;
mode = MSG;
this.fieldName = fieldName;
String methodName = "getAll" + fieldName;
try {
Method sn = itsObj.getClass().getMethod(methodName, (Class[]) null);
Iterator itor = (Iterator)sn.invoke(itsObj, new Object[]{});
while (itor.hasNext()) {
AID theAID = (AID)itor.next();
listModel.addElement(theAID);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
theDataListener = new AIDListListener();
theDataListener.register(itsObj, fieldName);
listModel.addListDataListener(theDataListener);
contentList.setModel(listModel);
}
/**
* register AID and fieldname from ACLMessage
*
* @param aid the AID to register
* @param fieldName fieldname of ACLMessage
*/
public void register(AID aid, String fieldName) {
this.itsAid = aid;
mode = AID;
this.fieldName = fieldName;
String methodName = "getAll" + fieldName;
try {
Method sn = aid.getClass().getMethod(methodName, (Class[]) null);
Iterator itor = (Iterator)sn.invoke(aid, new Object[]{});
while (itor.hasNext()) {
AID theAID = (AID)itor.next();
listModel.addElement(theAID);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
theDataListener = new AIDListListener();
theDataListener.register(aid, fieldName);
listModel.addListDataListener(theDataListener);
contentList.setModel(listModel);
}
/**
* show the current selected AID
*/
void doView() {
int index = this.contentList.getSelectedIndex();
if (index < 0) {
return;
}
AID currentAID = (AID)listModel.getElementAt(index);
AID editAID = (AID)currentAID.clone();
ACLAIDDialog theDialog = new ACLAIDDialog(agent);
theDialog.setLocation((int)getLocationOnScreen().getX(), (int)getLocationOnScreen().getY());
theDialog.setItsAID(editAID);
theDialog.setEditable(editable);
theDialog.setTitle(editable ? "Edit AID of: " + currentAID.getName() : "View AID of:" + currentAID.getName());
theDialog.show();
if (theDialog.getOK()) {
theDataListener.registerChangedAID(theDialog.getItsAID());
listModel.setElementAt(editAID, index);
}
}
/**
* Triggered by delete button
*
* @param e ActionEvent belonging to delete button
*/
void deleteButton_actionPerformed(ActionEvent e) {
doDelete();
}
/**
* delete selected AID
*/
void doDelete() {
int index = contentList.getSelectedIndex();
if (index >= 0) {
theDataListener.registerRemovedAID((AID)listModel.getElementAt(index));
this.listModel.remove(index);
}
}
/**
* Triggered by add button
*
* @param e ActionEvent belonging to add button
*/
void addButton_actionPerformed(ActionEvent e) {
doAdd();
}
/**
* Add a AID to the list
*/
void doAdd() {
ACLAIDDialog theGui = new ACLAIDDialog(agent);
theGui.setTitle("<new AID>");
theGui.setLocation((int)getLocationOnScreen().getX(), (int)getLocationOnScreen().getY());
theGui.localCheckBox.setSelected(false);
theGui.show();
if (theGui.getOK()) {
listModel.addElement(theGui.getItsAID());
}
}
/**
* Triggered by the view button
*
* @param e ActionEvent belonging to view button
*/
void viewButton_actionPerformed(ActionEvent e) {
doView();
}
/**
* Triggered when clicking with mouse pointer. On doubleclick, call
* doView()
*
* @param e MouseEvent beloning to mouseClicked
*/
void contentList_mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
doView();
}
}
/**
* Triggered when pressing a key. Enter will call doView(), Insert will
* call doAdd(), and Delete will call doDelete().
*
* @param e KeyEvent beloning to keyPressed
*/
void contentList_keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_ENTER) {
doView();
}
if (!editable) {
return;
}
if (e.getKeyCode() == e.VK_INSERT) {
doAdd();
}
if (e.getKeyCode() == e.VK_DELETE) {
doDelete();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -