📄 aclgui.java
字号:
comments = new JTextArea(4,TEXT_SIZE);
JScrollPane commentsPane = new JScrollPane();
commentsPane.getViewport().setView(comments);
put(aclPanel,commentsPane,0,3,3,4,false);
commentsPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
commentsPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//aclRappresentation (line # 7)
l = new JLabel("ACLRepresentation:");
put(aclPanel,l, 0, 7, 1, 1, false);
representation = new JTextField();
representation.setBackground(Color.white);
put(aclPanel,representation, 1, 7, 2, 1, false);
//payloadLength (line # 8)
l = new JLabel("Payload Length:");
put(aclPanel,l, 0, 8, 1, 1, false);
payloadLength = new JTextField();
payloadLength.setBackground(Color.white);
put(aclPanel,payloadLength, 1, 8, 2, 1, false);
//payloadEncoding (line # 9)
l = new JLabel("Payload Encoding:");
put(aclPanel,l, 0, 9, 1, 1, false);
payloadEncoding = new JTextField();
payloadEncoding.setBackground(Color.white);
put(aclPanel,payloadEncoding, 1, 9, 2, 1, false);
//Date (line # 10)
dateDate = null;
l = new JLabel("Date:");
put(aclPanel,l, 0, 10, 1, 1, false);
dateButton = new JButton("Set");
dateButton.setMargin(new Insets(2,3,2,3));
date = new JTextField();
date.setBackground(Color.white);
put(aclPanel,dateButton, 1, 10, 1, 1, false);
put(aclPanel,date, 2, 10, 1, 1, false);
dateButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
//TimeChooser t = new TimeChooser(replyByDate);
TimeChooser t = new TimeChooser();
String d = date.getText();
if (!d.equals(""))
{
try
{
t.setDate(ISO8601.toDate(d));
}
catch (Exception ee) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Incorrect date format"); }
}
if (command.equals("Set"))
{
if (t.showEditTimeDlg(null) == TimeChooser.OK)
{
dateDate = t.getDate();
if (dateDate == null)
date.setText("");
else
date.setText(ISO8601.toString(dateDate));
}
}
else if (command.equals("View"))
{
t.showViewTimeDlg(null);
}
}
} );
//intendedReceiver (line #11)
l = new JLabel("Intended Receiver:");
put(aclPanel,l,0,11,1,1,false);
intendedReceiverPanel = new VisualAIDList(new ArrayList().iterator(),ownerGui);
intendedReceiverPanel.setDimension(new Dimension(205,37));
put(aclPanel,intendedReceiverPanel, 1, 11,2,1,false);
//ReceivedObject (line #12-15)
JPanel recPanel = new JPanel();
recPanel.setLayout(new BoxLayout(recPanel,BoxLayout.Y_AXIS));
JPanel tempPane = new JPanel();
tempPane.setLayout(new BoxLayout(tempPane,BoxLayout.X_AXIS));
recPanel.setBorder(new TitledBorder("Received Object"));
l = new JLabel("By:");
l.setPreferredSize(new Dimension(115,24));
l.setMinimumSize(new Dimension(115,24));
l.setMaximumSize(new Dimension(115,24));
tempPane.add(l);
by = new JTextField();
by.setBackground(Color.white);
tempPane.add(by);
recPanel.add(tempPane);
tempPane = new JPanel();
tempPane.setLayout(new BoxLayout(tempPane,BoxLayout.X_AXIS));
l = new JLabel("From:");
l.setPreferredSize(new Dimension(115,24));
l.setMinimumSize(new Dimension(115,24));
l.setMaximumSize(new Dimension(115,24));
tempPane.add(l);
fromRec = new JTextField();
fromRec.setBackground(Color.white);
tempPane.add(fromRec);
recPanel.add(tempPane);
tempPane = new JPanel();
tempPane.setLayout(new BoxLayout(tempPane,BoxLayout.X_AXIS));
dateRecDate = null;
l = new JLabel("Date:");
l.setPreferredSize(new Dimension(115,24));
l.setMinimumSize(new Dimension(115,24));
l.setMaximumSize(new Dimension(115,24));
tempPane.add(l);
dateRecButton = new JButton("Set");
tempPane.add(dateRecButton);
dateRecButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
//TimeChooser t = new TimeChooser(replyByDate);
TimeChooser t = new TimeChooser();
String d = dateRec.getText();
if (!d.equals(""))
{
try
{
t.setDate(ISO8601.toDate(d));
}
catch (Exception ee) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Incorrect date format"); }
}
if (command.equals("Set"))
{
if (t.showEditTimeDlg(null) == TimeChooser.OK)
{
dateRecDate = t.getDate();
if (dateRecDate == null)
dateRec.setText("");
else
dateRec.setText(ISO8601.toString(dateRecDate));
}
}
else if (command.equals("View"))
{
t.showViewTimeDlg(null);
}
}
} );
dateRec = new JTextField();
dateRec.setBackground(Color.white);
tempPane.add(dateRec);
recPanel.add(tempPane);
tempPane = new JPanel();
tempPane.setLayout(new BoxLayout(tempPane,BoxLayout.X_AXIS));
l = new JLabel("ID:");
l.setPreferredSize(new Dimension(115,24));
l.setMinimumSize(new Dimension(115,24));
l.setMaximumSize(new Dimension(115,24));
tempPane.add(l);
id = new JTextField();
id.setBackground(Color.white);
tempPane.add(id);
recPanel.add(tempPane);
tempPane = new JPanel();
tempPane.setLayout(new BoxLayout(tempPane,BoxLayout.X_AXIS));
l = new JLabel("Via:");
l.setPreferredSize(new Dimension(115,24));
l.setMinimumSize(new Dimension(115,24));
l.setMaximumSize(new Dimension(115,24));
tempPane.add(l);
via = new JTextField();
via.setBackground(Color.white);
tempPane.add(via);
recPanel.add(tempPane);
put(aclPanel,recPanel,0,12,3,1,false);
//(line 17)
JPanel tmpPanel = new JPanel();
//tmpPanel.setBackground(Color.lightGray);
defaultEnvelopeButton = new JButton("Set Default Envelope");
tmpPanel.add(defaultEnvelopeButton);
defaultEnvelopeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if(command.equals("Set Default Envelope"))
{
ACLMessage tmp = getMsg();
tmp.setDefaultEnvelope();
Envelope envtmp = tmp.getEnvelope();
showEnvelope(envtmp);
}
}
});
put(aclPanel,tmpPanel,0,17,3,1,false);
//setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(aclPanel);
}
}
/////////////////
// CONSTRUCTOR
/////////////////
/**
Ordinary <code>AclGui</code> constructor.
@see jade.lang.acl.ACLMessage#ACLMessage(int)
*/
public AclGui(Component owner)
{
firstPaintFlag = true;
guiEnabledFlag = true;
minDim = new Dimension();
ownerGui = owner;
JTabbedPane tabbed = new JTabbedPane();
AclMessagePanel aclPane = new AclMessagePanel();
EnvelopePanel envelope = new EnvelopePanel();
tabbed.addTab("ACLMessage",aclPane);
tabbed.addTab("Envelope",envelope);
//to enable the textfields if needed.
updateEnabled();
add(tabbed);
// Try inserting formatted SL content.
// any Exception is catched in order to remove unwished dependency
// on the jade.tools.sl package from this package at run-time.
try {
slFormatter = new SLFormatter();
} catch (Exception e) {
}
}
SLFormatter slFormatter;
////////////////////
// PRIVATE METHODS
////////////////////
private void formatGrid(int nr, int nc, int lb, int rb, int tb, int bb, int xs, int ys)
{
gridNRow = nr;
gridNCol = nc;
colWidth = new int[3];
//colWidth[0] = 120;
//colWidth[1] = 63;
//colWidth[2] = 180;
leftBorder = lb;
rightBorder = rb;
topBorder = tb;
bottomBorder = bb;
xSpacing = xs;
ySpacing = ys;
}
private void setGridColumnWidth(int col, int width)
{
colWidth[col] = width;
}
private void put(JPanel panel, JComponent c, int x, int y, int dx, int dy, boolean fill)
{
int leftMargin, rightMargin, topMargin, bottomMargin;
int preferredWidth, preferredHeight;
constraint.gridx = x;
constraint.gridy = y;
constraint.gridwidth = dx;
constraint.gridheight = dy;
constraint.anchor = GridBagConstraints.WEST;
if (fill)
constraint.fill = GridBagConstraints.BOTH;
else
constraint.fill = GridBagConstraints.VERTICAL;
leftMargin = (x == 0 ? leftBorder : 0);
rightMargin = (x+dx == gridNCol ? rightBorder : xSpacing);
topMargin = (y == 0 ? topBorder : 0);
bottomMargin = (y+dy == gridNRow ? bottomBorder : ySpacing);
int i;
preferredWidth = 0;
for (i = 0; i < dx; ++i)
preferredWidth += colWidth[x+i] + xSpacing;
preferredWidth -= xSpacing;
preferredHeight = c.getPreferredSize().height;
c.setPreferredSize(new Dimension(preferredWidth, preferredHeight));
constraint.insets = new Insets(topMargin, leftMargin, bottomMargin, rightMargin);
lm.setConstraints(c,constraint);
panel.add(c);
}
private void updateEnabled()
{
communicativeAct.setEnabled(guiEnabledFlag);
senderButton.setText((guiEnabledFlag && senderEnabledFlag) ? "Set" : "View");
receiverListPanel.setEnabled(guiEnabledFlag);
replyToListPanel.setEnabled(guiEnabledFlag);
propertiesListPanel.setEnabled(guiEnabledFlag);
replyWith.setEditable(guiEnabledFlag);
inReplyTo.setEditable(guiEnabledFlag);
conversationId.setEditable(guiEnabledFlag);
replyBy.setEditable(false);
replyBySet.setEnabled(true);
replyBySet.setText(guiEnabledFlag ? "Set" : "View");
encoding.setEditable(guiEnabledFlag);
protocol.setEnabled(guiEnabledFlag);
language.setEditable(guiEnabledFlag);
ontology.setEditable(guiEnabledFlag);
content.setEditable(guiEnabledFlag);
//Envelope
fromButton.setText(guiEnabledFlag && senderEnabledFlag ? "Set": "View");
toPanel.setEnabled(guiEnabledFlag);
comments.setEnabled(guiEnabledFlag);
representation.setEnabled(guiEnabledFlag);
payloadLength.setEnabled(guiEnabledFlag);
payloadEncoding.setEnabled(guiEnabledFlag);
date.setEditable(false);
dateButton.setText(guiEnabledFlag ? "Set" : "View");
intendedReceiverPanel.setEnabled(guiEnabledFlag);
defaultEnvelopeButton.setVisible(guiEnabledFlag);
//ReceivedObject
by.setEditable(guiEnabledFlag);
fromRec.setEditable(guiEnabledFlag);
dateRec.setEditable(false);
dateRecButton.setText(guiEnabledFlag ? "Set" : "View");
id.setEditable(guiEnabledFlag);
via.setEditable(guiEnabledFlag);
}
private void showEnvelope(Envelope envelope)
{
String param;
try {
this.fromAID = envelope.getFrom();
param = fromAID.getName();
} catch (NullPointerException e1) {
param = "";
this.fromAID = new AID();
}
from.setText(param);
//#DOTNET_EXCLUDE_BEGIN
toPanel.resetContent(envelope.getAllTo());
//#DOTNET_EXCLUDE_END
try{
AID fromAID = envelope.getFrom();
param = fromAID.getName();
}catch(NullPointerException e1){param = "";}
from.setText(param);
try{
param = envelope.getComments();
}catch(NullPointerException e1){param ="";}
comments.setText(param);
try{
param = envelope.getAclRepresentation();
}catch(NullPointerException e1){param ="";}
representation.setText(param);
try{
param = envelope.getPayloadLength().toString();
}catch(NullPointerException e1){param ="-1";}
payloadLength.setText(param);
try{
param = envelope.getPayloadEncoding();
}catch(NullPointerException e1){param ="";}
payloadEncoding.setText(param);
//Date
dateDate = envelope.getDate();
if (dateDate != null)
date.setText(ISO8601.toString(dateDate));
else
date.setText("");
//#DOTNET_EXCLUDE_BEGIN
intendedReceiverPanel.resetContent(envelope.getAllIntendedReceiver());
//#DOTNET_EXCLUDE_END
ReceivedObject recObject = envelope.getReceived();
try{
param = recObject.getBy();
}catch(NullPointerException e){
param = "";
}
by.setText(param);
try{
param = recObject.getFrom();
}catch(NullPointerException e){
param = "";
}
fromRec.setText(param);
try{
dateRecDate = recObject.getDate();
param = ISO8601.toString(dateRecDate);
}catch(NullPointerException e){
param = "";
}
dateRec.setText(param);
try{
param = recObject.getId();
}catch(NullPointerException e){
param = "";
}
id.setText(param);
try{
param = recObject.getVia();
}catch(NullPointerException e){
param = "";
}
via.setText(param);
}
/////////////////////////////////////////////
// MESSAGE GETTING and SETTING PUBLIC METHODS
/////////////////////////////////////////////
/**
Displays the specified ACL message into the AclGui panel
@param msg The ACL message to be displayed
@see AclGui#getMsg()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -