📄 mmcanvas.java
字号:
AclGui.showMsgInDialog(mess,mWnd);
}
}
}
public void mouseEntered(MouseEvent evt) {}
public void mouseExited(MouseEvent evt) {}
public void mouseReleased(MouseEvent evt) {}
public void mouseDragged(MouseEvent evt) {}
public void mouseMoved(MouseEvent evt) {
Agent selectedAgent = selAgent(evt);
if ((selectedAgent != null) && (typeCanv == true)) {
if (!nameShown) {
nameShown = true;
mPan.textArea.setText("Agent: ");
mPan.textArea.setFont(font2);
mPan.textArea.append(selectedAgent.agentName);
}
} else {
if (nameShown) {
nameShown = false;
mPan.textArea.setText(null);
}
}
}
//#DOTNET_EXCLUDE_END
private boolean checkNoSniffedVector(Agent agent) {
boolean isPresent=false;
Agent agentToCompare;
if(noSniffAgents.size()==0) return false;
else {
for (int i=0; i<noSniffAgents.size();i++) {
agentToCompare=(Agent)noSniffAgents.get(i);
if(agentToCompare.agentName.equals(agent.agentName)) {
isPresent=true;
positionAgent=i;
break;
}
}
if (isPresent) return true;
else return false;
}
}
//#DOTNET_EXCLUDE_BEGIN
public Message selMessage(MouseEvent evt) {
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
public Message selMessage(MouseEventArgs evt) {
#DOTNET_INCLUDE_END*/
int j = 0;
/*#DOTNET_INCLUDE_BEGIN
Point pClient = myPanel.PointToClient( new Point(evt.get_X(), evt.get_Y() ) );
Point pScreen = myPanel.PointToScreen( new Point(evt.get_X(), evt.get_Y() ) );
int xClient = pClient.get_X();
int yClient = pClient.get_Y();
int xScreen = pScreen.get_X();
int yScreen = pScreen.get_Y();
int panelHeight = otherCanv.getPanel().get_Height();
#DOTNET_INCLUDE_END*/
Iterator it = ml.getMessages();
while(it.hasNext()) {
Message mess = (Message)it.next();
String senderName = mess.getSender().getName();
//for(Iterator i = mess.getAllReceiver();i.hasNext(); )
//{
//String receiverName = ((AID)i.next()).getName();
String receiverName = mess.getUnicastReceiver().getName();
x1 = mess.getInitSeg(otherCanv.al.getPos(senderName));
x2 = mess.getEndSeg(otherCanv.al.getPos(receiverName));
y = mess.getOrdSeg(j++);
if(x1 < x2) {
//#DOTNET_EXCLUDE_BEGIN
if((evt.getX() >= x1+H_TOL) && (evt.getX() <= x2+H_TOL) &&
(evt.getY() >= y - V_TOL) && (evt.getY() <= y + V_TOL)) {
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
if((evt.get_X() >= x1+H_TOL) && (evt.get_X() <= x2+H_TOL) &&
(evt.get_Y()-panelHeight >= y - V_TOL) && (evt.get_Y()-panelHeight <= y + V_TOL)) {
#DOTNET_INCLUDE_END*/
return mess;
}
}
else {
//#DOTNET_EXCLUDE_BEGIN
if((evt.getX() >= x2 - H_TOL) && (evt.getX() <= x1 + H_TOL) &&
(evt.getY() >= y - V_TOL) && (evt.getY() <= y + V_TOL)) {
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
if((evt.get_X() >= x2 - H_TOL) && (evt.get_X() <= x1 + H_TOL) &&
(evt.get_Y()-panelHeight >= y - V_TOL) && (evt.get_Y()-panelHeight <= y + V_TOL)) {
#DOTNET_INCLUDE_END*/
return mess;
}
}
//}//for
}//while
return null;
}
/**
* Returns an Agent if an Agent has been selected form the user, otherwise
* returns null.
*
* @param evt mouse event
* @return Agent selected or null if no Agent was selected
*/
//#DOTNET_EXCLUDE_BEGIN
public Agent selAgent(MouseEvent evt) {
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
public Agent selAgent(MouseEventArgs evt) {
#DOTNET_INCLUDE_END*/
int j = 0;
int y1 = Agent.yRet;
int y2 = y1 + Agent.yRet;
try {
Iterator it = al.getAgents();
while(it.hasNext()) {
Agent ag = (Agent)it.next();
x1 = Agent.yRet + j*80;
x2 = x1 + Agent.bRet;
//#DOTNET_EXCLUDE_BEGIN
if((evt.getX() >= x1) && (evt.getX() <= x2) &&
(evt.getY() >= y1) && (evt.getY() <= y2)) {
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
if((evt.get_X() >= x1) && (evt.get_X() <= x2) &&
(evt.get_Y() >= y1) && (evt.get_Y() <= y2)) {
#DOTNET_INCLUDE_END*/
if (ag.agentName.equals("Other"))
{
return null;
} else {
return ag;
}
}
j++;
}
} catch (ConcurrentModificationException cme) {
// Ignore - next repaint will correct things
}
return null;
}
/**
* This method repaint both canvas checking the size of the scrollbars. The
* right procedure to follow is to call method setPreferredSize() the revalidate()
* method.
*/
private void repaintBothCanvas() {
MMCanvas c1 = panCan.canvAgent;
MMCanvas c2 = panCan.canvMess;
//#DOTNET_EXCLUDE_BEGIN
panCan.setPreferredSize(new Dimension(horDim,vertDim+50));
c1.setPreferredSize(new Dimension(horDim,50));
c2.setPreferredSize(new Dimension(horDim,vertDim));
panCan.revalidate();
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
panCan.getPanel().Invalidate();
#DOTNET_INCLUDE_END*/
c1.repaint();
c2.repaint();
}
/**
* Adds an agent to canvas agent then repaints it
*
* @param agent agent to be add
*/
public void rAgfromNoSniffVector(Agent agent) {
if (checkNoSniffedVector(agent)) {
noSniffAgents.remove(positionAgent);
repaintBothCanvas();
}
}
public void addAgent (Agent agent) {
al.addAgent(agent);
repaintBothCanvas();
}
/**
* Removes an agent from the canvas agent then repaints it
*
* @param agentName agent to be removed
*/
public void removeAgent (String agentName) {
try{
al.removeAgent(agentName);
repaintBothCanvas();
}
catch(Exception e) {}
}
/**
* Removes all the agents and messages from their lists then repaints the canvas
*/
public void removeAllAgents () {
//#DOTNET_EXCLUDE_BEGIN
SwingUtilities.invokeLater(new Runnable() {
public void run() {
al.removeAllAgents();
ml.removeAllMessages();
repaintBothCanvas();
}
});
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
al.removeAllAgents();
ml.removeAllMessages();
#DOTNET_INCLUDE_END*/
}
// method to repaint the NoSniffed agent
public void repaintNoSniffedAgent(Agent agent) {
if(!checkNoSniffedVector(agent)) noSniffAgents.add(agent);
repaintBothCanvas();
}
/**
* Adds a message to canvas message then repaints the canvas
*
* @param mess message to be added
*/
public void addMessage (final Message mess) {
//#DOTNET_EXCLUDE_BEGIN
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ml.addMessage(mess);
repaintBothCanvas();
}
});
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
ml.addMessage(mess);
repaintBothCanvas();
#DOTNET_INCLUDE_END*/
}
/**
* Removes all the messages in the message list then repaints the canvas
*/
public void removeAllMessages() {
try{
ml.removeAllMessages();
repaintBothCanvas();
}
catch (Exception e) {}
}
/**
* Looks if an agent is present on Agent Canvas
*
* @param agName agent name to look for
* @return true if agent is present, false otherwise
*/
public boolean isPresent (String agName) {
return al.isPresent(agName);
}
/**
* Returns an handler to the agent list. The agent list contains all the agents
* contained in the Agent Canvas displayed by grey or red boxes
*
* @return handler to agent list
*/
public AgentList getAgentList() {
return al;
}
/**
* Returns an handler to the message list. The message list contains all
* sniffed messages displayed on the Message Canavs as blue arrows
*
* @return handler to the message list
*/
public MessageList getMessageList() {
return ml;
}
/**
* Set the agent list handler as the parameter passed then repaints the canvas
*
* @param savedList new list of agents
*/
public void setAgentList(AgentList savedList) {
al = savedList;
repaintBothCanvas();
}
/**
* Set the message list handler as the parameter passed then repaints the canvas
*
* @param savedList new list of messages
*/
public void setMessageList(MessageList savedList) {
ml = savedList;
repaintBothCanvas();
}
/**
* Returns new messages and put them into canvas agent
*
* @param newMess new message
*/
public void recMessage(Message newMess) {
addMessage(newMess);
}
private String tail(int n, String s) {
try {
return s.substring(s.length()-n,s.length());
} catch (Exception any) {
return " ";
}
}
/**
* Trim off known prefixes.
*/
private String nameClip(String aName) {
String clipNames = mWnd.getProperties().getProperty("clip", null);
if (clipNames == null) {
return aName;
}
StringTokenizer parser = new StringTokenizer(clipNames, ";");
while (parser.hasMoreElements()) {
String clip = parser.nextToken();
if (aName.startsWith(clip)) {
return aName.substring(clip.length());
}
}
return aName;
}
/*#DOTNET_INCLUDE_BEGIN
public void repaint()
{
myPanel.Refresh();
}
#DOTNET_INCLUDE_END*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -