📄 aclpanel.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;
//java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import jade.core.AID;
import jade.core.Agent;
import jade.domain.FIPAAgentManagement.Envelope;
import jade.domain.FIPAAgentManagement.ReceivedObject;
import jade.lang.acl.*;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.ISO8601;
import jade.lang.acl.StringACLCodec;
import jade.tools.sl.SLFormatter;
import jade.util.Logger;
/**
* Description of the Class
*
* @author Chris van Aart - Acklin B.V., the Netherlands
* @created April 26, 2002
*/
public class ACLPanel extends JPanel {
private Logger logger = Logger.getMyLogger(this.getClass().getName());
/**
* Constructor for the ACLPanel object
*
* @param agent Description of Parameter
*/
public ACLPanel(Agent agent) {
try {
this.agent = agent;
receiverList = new ACLAIDList(agent);
replytoList = new ACLAIDList(agent);
envToList = new ACLAIDList(agent);
envIntendedReceiversList = new ACLAIDList(agent);
jbInit();
itsMsg.setSender(agent.getAID());
setItsMsg(itsMsg);
editsVector.add(performativesComboBox);
editsVector.add(languageTextField);
editsVector.add(ontologyTextField);
editsVector.add(encodingTextField);
editsVector.add(protocolComboBox);
editsVector.add(inreplytoTextField);
editsVector.add(replywithTextField);
editsVector.add(ontologyTextField);
editsVector.add(conversationTextField);
editsVector.add(receiverList);
editsVector.add(replytoList);
editsVector.add(contentTextArea);
editsVector.add(userpropList);
editsVector.add(envToList);
editsVector.add(envCommentsTextArea);
editsVector.add(envACLReprTextField);
editsVector.add(envPayloadEncodingTextField);
editsVector.add(envPayloadLengthTextField);
editsVector.add(envIntendedReceiversList);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Gets the ItsMsg attribute of the ACLPanel object
*
* @return The ItsMsg value
*/
public ACLMessage getItsMsg() {
return itsMsg;
}
/**
* Sets the ItsMsg attribute of the ACLPanel object
*
* @param msg The new ItsMsg value
*/
public void setItsMsg(ACLMessage msg) {
itsMsg = msg;
itsEnvelope = msg.getEnvelope();
if (itsEnvelope == null) {
itsEnvelope = new Envelope();
msg.setEnvelope(itsEnvelope);
}
//message
senderTextField.setText(itsMsg.getSender() != null ? itsMsg.getSender().getName() : "");
performativesComboBox.registerPerformatives(itsMsg);
languageTextField.register(itsMsg, "Language");
ontologyTextField.register(itsMsg, "Ontology");
encodingTextField.register(itsMsg, "Encoding");
protocolComboBox.registerProtocol(itsMsg);
inreplytoTextField.register(itsMsg, "InReplyTo");
replywithTextField.register(itsMsg, "ReplyWith");
replybyTextField.setText(itsMsg.getReplyByDate() != null ? ISO8601.toString(itsMsg.getReplyByDate()) : "");
conversationTextField.register(itsMsg, "ConversationId");
receiverList.register(itsMsg, "Receiver");
replytoList.register(itsMsg, "ReplyTo");
contentTextArea.register(itsMsg, "Content");
userpropList.register(itsMsg, "");
//env
envToList.register(itsEnvelope, "To");
envFromTextField.setText((itsEnvelope.getFrom() != null ? itsEnvelope.getFrom().getName() : ""));
envCommentsTextArea.register(itsEnvelope, "Comments");
envACLReprTextField.register(itsEnvelope, "AclRepresentation");
envPayloadEncodingTextField.register(itsEnvelope, "PayloadEncoding");
envPayloadLengthTextField.register(itsEnvelope, "PayloadLength");
envDateTextField.setText(itsEnvelope.getDate() != null ? ISO8601.toString(itsEnvelope.getDate()) : "");
envIntendedReceiversList.register(itsEnvelope, "IntendedReceiver");
}
/**
* Sets the ReadOnly attribute of the ACLPanel object
*/
public void setReadOnly() {
setEnabled(false);
editable = false;
}
/**
* Sets the Disabled attribute of the ACLPanel object
*
* @param theBool The new Enabled value
*/
public void setEnabled(boolean theBool) {
editable = theBool;
this.defaultEnvelopeButton.setEnabled(theBool);
String methodName = "setEditable";
for (int i = 0; i < editsVector.size(); i++) {
Object obj = editsVector.get(i);
try {
Method sn = obj.getClass().getMethod(methodName, new Class[]{Boolean.TYPE});
Object os = new Boolean(editable);
sn.invoke(obj, new Object[]{os});
}
catch (Exception ex) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Obj: " + obj.getClass().toString() + " " + ex.getMessage());
}
}
}
/**
* Description of the Method
*/
public void doSystemOut() {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.INFO,"\n" + itsMsg.toString() + "\n");
}
/**
* Description of the Method
*/
public void saveACL() {
UIManager.put("FileChooser.saveButtonToolTipText", "Save ACLMessage");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new ACLFileFilter());
// since JDK1.3 chooser.setAcceptAllFileFilterUsed(false);
chooser.setSelectedFile(new File("itsmessage.acl"));
chooser.setDialogTitle("Save ACLMessage");
if (currentDir != null) {
chooser.setCurrentDirectory(currentDir);
}
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
currentDir = chooser.getCurrentDirectory();
String fileName = chooser.getSelectedFile().getAbsolutePath();
if (!fileName.endsWith(".acl")) {
fileName = fileName + ".acl";
}
try {
FileWriter f = new FileWriter(fileName);
StringACLCodec codec = new StringACLCodec(null, f);
codec.write(itsMsg);
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");
}
}
}
public void loadACL() {
UIManager.put("FileChooser.openButtonToolTipText", "Open ACLMessage");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new ACLFileFilter());
// since JDK1.3 chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogTitle("Open ACLMessage");
if (currentDir != null) {
chooser.setCurrentDirectory(currentDir);
}
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
currentDir = chooser.getCurrentDirectory();
String fileName = chooser.getSelectedFile().getAbsolutePath();
try {
StringACLCodec codec = new StringACLCodec(new FileReader(fileName), null);
ACLMessage msg = codec.decode();
this.setItsMsg(msg);
}
catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(null, "File not found: " + fileName + e1.getMessage(), "Error Message", JOptionPane.ERROR_MESSAGE);
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"File Not Found: " + fileName);
}
catch (ACLCodec.CodecException e2) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Wrong ACL Message in file: " + fileName);
// e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Wrong ACL Message in file: " + fileName + "\n" + e2.getMessage(), "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
}
public void doZoomContent() {
ACLContentDialog theDialog = new ACLContentDialog(null, "ACLMessage content", true);
theDialog.setItsContent(this.getItsMsg());
theDialog.setEditable(editable);
theDialog.setLocation((int)getLocationOnScreen().getX(), (int)getLocationOnScreen().getY());
theDialog.show();
this.contentTextArea.update();
}
void setDefaultEnvelope() {
itsMsg.setDefaultEnvelope();
setItsMsg(itsMsg);
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.CONFIG,":" + this.itsEnvelope.toString());
}
/**
* Description of the Method
*
* @param e Description of Parameter
*/
void senderButton_actionPerformed(ActionEvent e) {
doShowSender();
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -