📄 aclgui.java
字号:
*/
public void setMsg(ACLMessage msg)
{
int i;
String param, lowerCase;
int perf = msg.getPerformative();
lowerCase = (ACLMessage.getPerformative(perf)).toLowerCase();
//No control if the ACLMessage is a well-known one
//if not present the first of the comboBox is selected
communicativeAct.setSelectedItem(lowerCase);
try {
this.SenderAID = msg.getSender();
param = SenderAID.getName();
} catch (NullPointerException e) {
param = "";
this.SenderAID = new AID();
}
sender.setText(param);
//#DOTNET_EXCLUDE_BEGIN
receiverListPanel.resetContent(msg.getAllReceiver());
replyToListPanel.resetContent(msg.getAllReplyTo());
//#DOTNET_EXCLUDE_END
Enumeration e = msg.getAllUserDefinedParameters().propertyNames();
ArrayList list = new ArrayList();
while(e.hasMoreElements())
list.add(e.nextElement());
propertiesListPanel.resetContent(list.iterator());
propertiesListPanel.setContentProperties(msg.getAllUserDefinedParameters());
if ((param = msg.getReplyWith()) == null) param = "";
replyWith.setText(param);
if ((param = msg.getInReplyTo()) == null) param = "";
inReplyTo.setText(param);
if ((param = msg.getConversationId()) == null) param = "";
conversationId.setText(param);
try {
param=ISO8601.toString(msg.getReplyByDate());
} catch (Exception exc) {
param="";
}
replyBy.setText(param);
if((param = msg.getProtocol()) == null)
protocol.setSelectedItem("Null");
else if (param.equals("") || param.equalsIgnoreCase("Null"))
protocol.setSelectedItem("Null");
else
{
lowerCase = param.toLowerCase();
if ((i = fipaProtocolArrayList.indexOf((Object) lowerCase)) < 0)
{
// This is done to avoid inserting the same user-defined protocol more than once
protocol.addItem(param);
int cnt = protocol.getItemCount();
protocol.setSelectedItem(param);
int n = protocol.getSelectedIndex();
if (n != cnt-1)
protocol.removeItemAt(cnt-1);
}
else
protocol.setSelectedIndex(i);
}
String lang;
if ((lang = msg.getLanguage()) == null) lang = "";
language.setText(lang);
if ((param = msg.getOntology()) == null) param = "";
ontology.setText(param);
if ((param = msg.getContent()) == null) param = "";
if ( (lang.equalsIgnoreCase(FIPANames.ContentLanguage.FIPA_SL0) ||
lang.equalsIgnoreCase(FIPANames.ContentLanguage.FIPA_SL1) ||
lang.equalsIgnoreCase(FIPANames.ContentLanguage.FIPA_SL2) ||
lang.equalsIgnoreCase(FIPANames.ContentLanguage.FIPA_SL)) &&
(slFormatter != null))
// Try inserting formatted SL content.
param = slFormatter.format(param);
content.setText(param);
if((param = msg.getEncoding())== null) param = "";
encoding.setText(param);
//Envelope
Envelope envelope = msg.getEnvelope();
if(envelope != null)
showEnvelope(envelope);
}
/**
Get the ACL message currently displayed by the AclGui panel
@return The ACL message currently displayed by the AclGui panel as an ACLMessage object
@see AclGui#setMsg(ACLMessage msg)
*/
public ACLMessage getMsg()
{
String param;
param = (String) communicativeAct.getSelectedItem();
int perf = ACLMessage.getInteger(param);
ACLMessage msg = new ACLMessage(perf);
if(newAIDSender != null)
SenderAID = newAIDSender;
/*if ( ((param = sender.getText()).trim()).length() > 0 )
SenderAID.setName(param);*/
// check if SenderAID has a guid. SenderAID is surely not null here
if (SenderAID.getName().length() > 0)
msg.setSender(SenderAID);
Enumeration rec_Enum = receiverListPanel.getContent();
while(rec_Enum.hasMoreElements())
msg.addReceiver((AID)rec_Enum.nextElement());
Enumeration replyTo_Enum = replyToListPanel.getContent();
while(replyTo_Enum.hasMoreElements())
msg.addReplyTo((AID)replyTo_Enum.nextElement());
Properties user_Prop = propertiesListPanel.getContentProperties();
Enumeration keys = user_Prop.propertyNames();
while(keys.hasMoreElements())
{
String k = (String)keys.nextElement();
msg.addUserDefinedParameter(k,user_Prop.getProperty(k));
}
param = replyWith.getText().trim();
if (param.length() > 0)
msg.setReplyWith(param);
param = inReplyTo.getText().trim();
if (param.length() > 0)
msg.setInReplyTo(param);
param = conversationId.getText().trim();
if (param.length() > 0)
msg.setConversationId(param);
param = replyBy.getText().trim();
try {
msg.setReplyByDate(ISO8601.toDate(param));
} catch (Exception e) {}
if (!(param = (String) protocol.getSelectedItem()).equals("Null"))
msg.setProtocol(param);
param = language.getText().trim();
if (param.length()>0)
msg.setLanguage(param);
param = ontology.getText().trim();
if (param.length()>0)
msg.setOntology(param);
param = content.getText().trim();
if (param.length()>0)
msg.setContent(param);
param = (encoding.getText()).trim();
if(param.length() > 0)
msg.setEncoding(param);
Envelope env = new Envelope();
Enumeration to_Enum = toPanel.getContent();
while(to_Enum.hasMoreElements())
env.addTo((AID)to_Enum.nextElement());
if(newAIDFrom!= null)
fromAID = newAIDFrom;
if (fromAID.getName().length() > 0)
env.setFrom(fromAID);
param = comments.getText().trim();
if(param.length()>0)
env.setComments(param);
param = representation.getText().trim();
if(param.length()>0)
env.setAclRepresentation(param);
try {
param = payloadLength.getText().trim();
env.setPayloadLength(new Long(param));
} catch (Exception e) {
//System.err.println("Incorrect int format. payloadLength must be an integer. Automatic reset to -1.");
//env.setPayloadLength(new Long(-1));
//payloadLength.setText("-1");
}
param = payloadEncoding.getText().trim();
if(param.length()>0)
env.setPayloadEncoding(param);
//setDate require a Date not a String
if (dateDate != null)
env.setDate(dateDate);
Enumeration int_Enum = intendedReceiverPanel.getContent();
while(int_Enum.hasMoreElements())
env.addIntendedReceiver((AID)int_Enum.nextElement());
param = language.getText().trim();
if (param.length()>0)
msg.setLanguage(param);
/* ReceivedObject recObject = new ReceivedObject();
boolean filled = false;
param = by.getText().trim();
if(param.length()>0)
{
filled = true;
recObject.setBy(param);
}
param = fromRec.getText().trim();
if(param.length()>0)
{
filled = true;
recObject.setFrom(param);
}
if (dateRecDate != null)
{
filled = true;
recObject.setDate(dateRecDate);
}
param = id.getText().trim();
if(param.length()>0)
{
filled = true;
recObject.setId(param);
}
param = via.getText().trim();
if(param.length()>0)
{
filled = true;
recObject.setVia(param);
}
if(filled)
env.setReceived(recObject);
*/
msg.setEnvelope(env);
return msg;
}
/////////////////////////
// UTILITY PUBLIC METHODS
/////////////////////////
/**
Enables/disables the editability of all the controls in an AclGui panel (default is enabled)
@param enabledFlag If true enables editability
@see AclGui#setSenderEnabled(boolean enabledFlag)
*/
public void setEnabled(boolean enabledFlag)
{
guiEnabledFlag = enabledFlag;
updateEnabled();
}
/**
Enables/disables the editability of the sender field of an AclGui panel (default is enabled)
@param enabledFlag If true enables editability
@see AclGui#setEnabled(boolean enabledFlag)
*/
public void setSenderEnabled(boolean enabledFlag)
{
senderEnabledFlag = enabledFlag;
updateEnabled();
}
/**
Set the specified border to the AclGui panel
@param b Specifies the type of border
*/
/*public void setBorder(Border b)
{
if (aclPanel != null)
aclPanel.setBorder(b);
}*/
/**
Paint the AclGui panel
*/
public void paint(Graphics g)
{
if (firstPaintFlag)
{
firstPaintFlag = false;
minDim = aclPanel.getSize();
}
else
aclPanel.setMinimumSize(minDim);
super.paint(g);
}
//////////////////
// STATIC METHODS
//////////////////
/**
Pops up a dialog window including an editing-disabled AclGui panel and displays the specified
ACL message in it.
@param m The ACL message to be displayed
@param parent The parent window of the dialog window
@see AclGui#editMsgInDialog(ACLMessage msg, Frame parent)
*/
public static void showMsgInDialog(ACLMessage msg, Frame parent)
{
final JDialog tempAclDlg = new JDialog(parent, "ACL Message", true);
AclGui aclPanel = new AclGui(parent);
//aclPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
aclPanel.setEnabled(false);
aclPanel.setMsg(msg);
JButton okButton = new JButton("OK");
JPanel buttonPanel = new JPanel();
// Use default (FlowLayout) layout manager to dispose the OK button
buttonPanel.add(okButton);
tempAclDlg.getContentPane().setLayout(new BorderLayout());
tempAclDlg.getContentPane().add("Center", aclPanel);
tempAclDlg.getContentPane().add("South", buttonPanel);
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tempAclDlg.dispose();
}
} );
tempAclDlg.pack();
tempAclDlg.setResizable(false);
if (parent != null) {
int locx = parent.getX() + (parent.getWidth() - tempAclDlg.getWidth()) / 2;
if (locx < 0)
locx = 0;
int locy = parent.getY() + (parent.getHeight() - tempAclDlg.getHeight()) / 2;
if (locy < 0)
locy = 0;
tempAclDlg.setLocation(locx,locy);
}
tempAclDlg.show();
}
/**
Pops up a dialog window including an editing-enabled AclGui panel and displays the specified
ACL message in it. The dialog window also includes an OK and a Cancel button to accept or
discard the performed editing.
@param m The ACL message to be initially displayed
@param parent The parent window of the dialog window
@return The ACL message displayed in the dialog window or null depending on whether the user close the window
by clicking the OK or Cancel button
@see AclGui#showMsgInDialog(ACLMessage msg, Frame parent)
*/
public static ACLMessage editMsgInDialog(ACLMessage msg, Frame parent)
{
final JDialog tempAclDlg = new JDialog(parent, "ACL Message", true);
final AclGui aclPanel = new AclGui(parent);
aclPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
aclPanel.setSenderEnabled(true);
aclPanel.setMsg(msg);
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("Cancel");
okButton.setPreferredSize(cancelButton.getPreferredSize());
JPanel buttonPanel = new JPanel();
// Use default (FlowLayout) layout manager to dispose the OK and Cancel buttons
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
tempAclDlg.getContentPane().setLayout(new BorderLayout());
tempAclDlg.getContentPane().add("Center", aclPanel);
tempAclDlg.getContentPane().add("South", buttonPanel);
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
editedMsg = aclPanel.getMsg();
tempAclDlg.dispose();
}
} );
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
editedMsg = null;
tempAclDlg.dispose();
}
} );
tempAclDlg.pack();
tempAclDlg.setResizable(false);
if (parent != null)
{
int x = parent.getX() + (parent.getWidth() - tempAclDlg.getWidth()) / 2;
int y = parent.getY() + (parent.getHeight() - tempAclDlg.getHeight()) / 2;
tempAclDlg.setLocation(x > 0 ? x :0, y>0 ? y :0);
}
tempAclDlg.show();
ACLMessage m = null;
if (editedMsg != null)
m = (ACLMessage) editedMsg.clone();
return m;
}
/*public static void main(String[] args)
{
JFrame f = new JFrame();
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.setLanguage("language");
msg.setOntology("onto");
Envelope env = new Envelope();
env.setComments("Commento");
env.setAclRepresentation("ACLRepresentation");
msg.setEnvelope(env);
AclGui.showMsgInDialog(msg,f);
f.pack();
f.show();
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -