📄 aclgui.java
字号:
/*****************************************************************
JADE - Java Agent DEvelopment Framework is a framework to develop
multi-agent systems in compliance with the FIPA specifications.
Copyright (C) 2000 CSELT S.p.A.
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.gui;
//#J2ME_EXCLUDE_FILE
// Import required java classes
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
// Import required JADE classes
import jade.core.*;
import jade.lang.acl.*;
import jade.core.AID;
import jade.domain.FIPAAgentManagement.Envelope;
import jade.domain.FIPAAgentManagement.ReceivedObject;
import jade.tools.sl.SLFormatter;
import jade.domain.FIPANames;
import jade.util.Logger;
/**
* The AclGui class extends the Swing JPanel class by adding all the controls
* required to properly edit/show the fields of an an ACL message
* compliant to the <b>FIPA 97</b> specs. <p>
* <p>
* There are basically two ways of using the AclGui class.
* <ul>
* <li> <b>Non Static Mode</b>. As AclGui extends JPanel, an
* instance of AclGui can be directly added to whatever Container thus providing an easy way
* to permanently insert into a GUI a panel for the editing/display of an ACL message.<br>
* The <em>setMsg()</em> and <em>getMsg()</em> methods can be used to display a given ACL message in the panel
* and to retrieve the ACL message currently displayed.<br>
* The <em>setEnabled()</em> and <em>setSenderEnabled()</em>
* methods can be used to enable/disable modifications to all fields in the ACL message
* and/or the sender field respectively.<br>
* E.g.<br>
* This code creates an agent GUI with a panel (in the left part of the GUI) that displays each new
* message received by the agent
* <code>
* .....<br>
* AclGui acl;<br>
* .....<br>
* JFrame agentGui = new JFrame();<br>
* agentGui.getContentPane().setLayout(new BorderLayout());<br>
* acl = new AclGui();<br>
* acl.setEnabled(false);<br>
* agentGui.getContentPane().add("West", acl);<br>
* .....<br>
* </code>
* Each time a new message is received (assuming the message has been stored
* in the msg variable of type ACLMessage)
* <code>
* acl.setMsg(msg);<br>
* </code>
* </li>
* <li> <b>Static Mode</b>. The AclGui class also provides the <em>editMsgInDialog()</em> and <em>showMsgInDlg()</em>
* static methods that pop up a temporary dialog window (including an AclGui panel and the proper OK and
* Cancel buttons) by means of which it is possible to edit and show a given ACL message.<br>
* E.g.<br>
* This code creates a button that allows the user to edit an ACL message
* by means of a temporary dialog window
* <code>
* .....<br>
* ACLMessage msg;<br>
* .....<br>
* JButton b = new JButton("edit");<br>
* b.addActionListener(new ActionListener()<br>
* {<br>
* public void actionPerformed(ActionEvent e)<br>
* {<br>
* msg = AclGui.editMsgInDialog(new ACLMessage("", null);<br>
* }<br>
* } );<br>
* </code>
* </li>
* </ul>
@author Giovanni Caire - CSELT
@version $Date: 2005-04-15 17:45:02 +0200 (ven, 15 apr 2005) $ $Revision: 5669 $
@see jade.lang.acl.ACLMessage
*/
public class AclGui extends JPanel
{
// Controls for ACL message parameter editing
static String ADD_NEW_RECEIVER = "Insert receiver";
//the owner of the panel.
private Component ownerGui;
//the logger
private Logger logger = Logger.getMyLogger(this.getClass().getName());
/**
@serial
*/
AID SenderAID = new AID();
/**
@serial
*/
AID newAIDSender = null;
/**
@serial
*/
AID fromAID = new AID();
/**
@serial
*/
AID newAIDFrom = null;
/**
@serial
*/
VisualAIDList receiverListPanel;
/**
@serial
*/
VisualAIDList replyToListPanel;
/**
@serial
*/
VisualPropertiesList propertiesListPanel;
/**
@serial
*/
private boolean guiEnabledFlag;
/**
@serial
*/
private JTextField sender;
/**
@serial
*/
private boolean senderEnabledFlag;
/**
@serial
*/
private JComboBox communicativeAct;
/**
@serial
*/
private JTextArea content;
/**
@serial
*/
private JTextField language;
/**
@serial
*/
private JTextField ontology;
/**
@serial
*/
private JComboBox protocol;
/**
@serial
*/
private JTextField conversationId;
/**
@serial
*/
private JTextField inReplyTo;
/**
@serial
*/
private JTextField replyWith;
/**
@serial
*/
private JTextField replyBy;
/**
@serial
*/
private JTextField encoding;
/**
@serial
*/
private JButton replyBySet;
/**
@serial
*/
private Date replyByDate;
/**
@serial
*/
private Date dateDate;
/**
@serial
*/
private Date dateRecDate;
// Data for panel layout definition
/**
@serial
*/
GridBagLayout lm = new GridBagLayout();
/**
@serial
*/
GridBagConstraints constraint = new GridBagConstraints();
/**
@serial
*/
private int leftBorder, rightBorder, topBorder, bottomBorder;
/**
@serial
*/
private int xSpacing, ySpacing;
/**
@serial
*/
private int gridNCol, gridNRow;
/**
@serial
*/
private int colWidth[];
private static final int TEXT_SIZE = 30;
/**
@serial
*/
private Vector fipaActVector;
private static int N_FIPA_PROTOCOLS = 8;
private static String fipaProtocols[] = {FIPANames.InteractionProtocol.FIPA_ENGLISH_AUCTION,
FIPANames.InteractionProtocol.FIPA_DUTCH_AUCTION,
FIPANames.InteractionProtocol.FIPA_CONTRACT_NET,
FIPANames.InteractionProtocol.FIPA_ITERATED_CONTRACT_NET,
FIPANames.InteractionProtocol.FIPA_QUERY,
FIPANames.InteractionProtocol.FIPA_REQUEST,
FIPANames.InteractionProtocol.FIPA_REQUEST_WHEN,
FIPANames.InteractionProtocol.FIPA_PROPOSE };
/**
@serial
*/
private ArrayList fipaProtocolArrayList;
// Data for the editing of user defined iteration protocols
/**
@serial
*/
private int lastSelectedIndex;
/**
@serial
*/
private String lastSelectedItem;
private static final String LABEL_TO_ADD_PROT = "ADD USER-DEF PROTOCOL";
// These data are used to correctly handle the resizing of the AclGui panel
/**
@serial
*/
private JPanel aclPanel;
/**
@serial
*/
private Dimension minDim;
/**
@serial
*/
private boolean firstPaintFlag;
// Other data used
private static ACLMessage editedMsg;
/**
@serial
*/
private JButton senderButton;
/**
@serial
*/
private VisualAIDList toPanel;
/**
@serial
*/
private JTextField from;
/**
@serial
*/
private JTextArea comments;
/**
@serial
*/
private JTextField representation;
/**
@serial
*/
private JTextField payloadLength;
/**
@serial
*/
private JTextField payloadEncoding;
/**
@serial
*/
private JTextField date;
/**
@serial
*/
private VisualAIDList intendedReceiverPanel;
/**
@serial
*/
private JButton defaultEnvelopeButton;
/**
@serial
*/
private JButton fromButton;
/**
@serial
*/
private JButton dateButton;
/**
@serial
*/
private JButton dateRecButton;
/**
@serial
*/
private JTextField by;
/**
@serial
*/
private JTextField fromRec;
/**
@serial
*/
private JTextField dateRec;
/**
@serial
*/
private JTextField via;
/**
@serial
*/
private JTextField id;
private class AclMessagePanel extends JPanel
//#DOTNET_EXCLUDE_BEGIN
implements DropTargetListener
//#DOTNET_EXCLUDE_END
{
AclMessagePanel()
{
JLabel l;
int i;
// Initialize the Vector of interaction protocols
fipaProtocolArrayList = new ArrayList();
for (i = 0;i < N_FIPA_PROTOCOLS; ++i)
fipaProtocolArrayList.add((Object) fipaProtocols[i]);
aclPanel = new JPanel();
//#DOTNET_EXCLUDE_BEGIN
new DropTarget(aclPanel, this);
//#DOTNET_EXCLUDE_END
aclPanel.setLayout(lm);
formatGrid(20, // N of rows
3, // N of columns
5, // Right border
5, // Left border
5, // Top boredr
5, // Bottom border
2, // Space between columns
2); // Space between rows
setGridColumnWidth(0, 115);
setGridColumnWidth(1, 40);
setGridColumnWidth(2, 170);
// Sender (line # 0)
l = new JLabel("Sender:");
//#DOTNET_EXCLUDE_BEGIN
new DropTarget(l, this);
//#DOTNET_EXCLUDE_END
put(aclPanel,l, 0, 0, 1, 1, false);
senderEnabledFlag = true; // The sender field is enabled by default, but can be disabled with the setSenderEnabled() method.
sender = new JTextField();
sender.setPreferredSize(new Dimension(80,26));
sender.setMinimumSize(new Dimension(80,26));
sender.setMaximumSize(new Dimension(80,26));
sender.setEditable(false);
sender.setBackground(Color.white);
senderButton = new JButton("Set");
senderButton.setMargin(new Insets(2,3,2,3));
put(aclPanel,senderButton,1,0,1,1,false);
put(aclPanel,sender, 2, 0, 1, 1, false);
senderButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -