⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmcanvas.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
           x2 = mess.getEndSeg(xDest);
           y = mess.getOrdSeg(yDim++);

           /* Were we fill the coordinate array for the arrow tip */

           xCoords[0] = x2-6;
           xCoords[1] = x2-6;
           xCoords[2] = x2+2;
		   //#DOTNET_EXCLUDE_BEGIN
           yCoords[0] = y-5;
           yCoords[1] = y+5;
           yCoords[2] = y;
		   //#DOTNET_EXCLUDE_END
		   /*#DOTNET_INCLUDE_BEGIN
		   yCoords[0] = y-5+myOffset;
		   yCoords[1] = y+5+myOffset;
		   yCoords[2] = y+myOffset;
		   #DOTNET_INCLUDE_END*/

           if(x1 > x2) {
	         xCoords[0] = x2+10;
	         xCoords[1] = x2+10;
	         xCoords[2] = x2+2;
           }

           // First we lookup convID, replywith and replyto to see if any of them
           // have a colorindex.  If any of them do, then that becomes the one that
           // we will use.
           Integer colorIndex = new Integer(-1);
           //System.out.println("Starting color:" + mess.getPerformative() +
           //    " CID:" + mess.getConversationId() +
           //    " RW:" + mess.getReplyWith() +
           //    " RT:" + mess.getInReplyTo());
           
           Object conversationKey = null;
           if (mess.getConversationId() != null) {
        	   conversationKey = mess.getConversationId();
           }
           else if (mess.getReplyWith() != null) {
        	   conversationKey = mess.getReplyWith();
           }
           else if (mess.getInReplyTo() != null) {
        	   conversationKey = mess.getInReplyTo();
           }
           
           Color messageColor = null;
           if (conversationKey != null) {
	           if (mapToColor.containsKey(conversationKey)) {
	               colorIndex = (Integer)mapToColor.get(conversationKey);        	   
	           }
	           else {
	        	   colorIndex = getNewColorIndex();
	        	   mapToColor.put(conversationKey, colorIndex);
	           }
	           messageColor = colorTable[colorIndex.intValue() % colorTable.length];
           }
           else {
        	   messageColor = noConversationColor;
           }
           /*if (mess.getConversationId() != null) {
             if (mapToColor.containsKey(mess.getConversationId())) {
                colorIndex = (Integer)mapToColor.get(mess.getConversationId());
                //System.out.println("Found CID:" + colorIndex);
             }
           }
           if (mess.getReplyWith() != null && colorIndex.intValue() == -1) {
             if (mapToColor.containsKey(mess.getReplyWith())) {
                colorIndex = (Integer)mapToColor.get(mess.getReplyWith());
                //System.out.println("Found RW:" + colorIndex);
             }
           } 
           if (mess.getInReplyTo() != null && colorIndex.intValue() == -1) {
             if (mapToColor.containsKey(mess.getInReplyTo())) {
                colorIndex = (Integer)mapToColor.get(mess.getInReplyTo());
                //System.out.println("Found RT:" + colorIndex);
             }
           }

           // If not, then we get the next color value.
           if (colorIndex.intValue() == -1) {
             colorCounter = new Integer(colorCounter.intValue() + 1);
             colorIndex = colorCounter;
             //System.out.println("Making new:" + colorIndex);
           }

           // Now, we store this value on all non-null ids.
           if (mess.getConversationId() != null) {
             //System.out.println("CID:" + mess.getConversationId()+ " was: " + mapToColor.get(mess.getConversationId()));
             mapToColor.put(mess.getConversationId(), colorIndex);
           }
           if (mess.getReplyWith() != null) {
             //System.out.println("RW:" + mess.getReplyWith()+ " was: " + mapToColor.get(mess.getReplyWith()));
             mapToColor.put(mess.getReplyWith(), colorIndex);
           }
           if (mess.getInReplyTo() != null) {
             //System.out.println("RT:" + mess.getInReplyTo() + " was: " + mapToColor.get(mess.getInReplyTo()));
             mapToColor.put(mess.getInReplyTo(), colorIndex);
           }
           //System.out.println("Done");*/
           
           
		   //#DOTNET_EXCLUDE_BEGIN
           g.setColor(messageColor);
           g.drawRect(x1-3,y-4,4,8);
           g.fillRect(x1-3,y-4,4,8);

		   // This code displays the name of the performative centered above the
		   // arrow.  At some point, might want to make this optional.
     	   g.setFont(font3);
		   FontMetrics fmPerf = g.getFontMetrics();
		   
		   String perf = mess.getPerformative(mess.getPerformative());
		   //#DOTNET_EXCLUDE_END
		   /*#DOTNET_INCLUDE_BEGIN
		   color = colorTable[colorIndex.intValue() % colorTable.length];
		   Pen pen = new Pen(color);
		   SolidBrush sb = new SolidBrush(color);
		   g.DrawRectangle(pen, x1-3, y-4+myOffset, 4, 8);
		   g.FillRectangle(sb, x1-3, y-4+myOffset, 4, 8);
	   
	       // This code displays the name of the performative centered above the
           // arrow.  At some point, might want to make this optional.
		   String perf = mess.getPerformative(mess.getPerformative());
		   SizeF sizefPerf = g.MeasureString(perf, font3);
		   #DOTNET_INCLUDE_END*/

           // Add ConversationId and ReplyWith
           int numberToShow=3;
           perf=perf + ":" + colorIndex
                     + " (" + tail(numberToShow,mess.getConversationId()) 
                     + "  " + tail(numberToShow,mess.getReplyWith()) 
                     + "  " + tail(numberToShow,mess.getInReplyTo()) + " )";

		   //#DOTNET_EXCLUDE_BEGIN
           int perfWidth = fmPerf.stringWidth(perf);
		   //#DOTNET_EXCLUDE_END
		   /*#DOTNET_INCLUDE_BEGIN
		   int perfWidth = (int) sizefPerf.get_Width();
		   int perfHeight = (int) sizefPerf.get_Height();
		   #DOTNET_INCLUDE_END*/
           if (x2 > x1) 
		   {
		     //#DOTNET_EXCLUDE_BEGIN
             g.drawString(perf, x1+((x2-x1)/2)-perfWidth/2, y-4);
		     //#DOTNET_EXCLUDE_END
		     /*#DOTNET_INCLUDE_BEGIN
			 g.DrawString(perf, font3, sb, x1+((x2-x1)/2)-perfWidth/2, y+myOffset);
			 #DOTNET_INCLUDE_END*/
           } 
		   else 
		   {
		     //#DOTNET_EXCLUDE_BEGIN
             g.drawString(perf, x2+((x1-x2)/2)-perfWidth/2, y-4);
		     //#DOTNET_EXCLUDE_END
			 /*#DOTNET_INCLUDE_BEGIN
			 g.DrawString(perf, font3, sb, x2+((x1-x2)/2)-perfWidth/2, y+myOffset);
			 #DOTNET_INCLUDE_END*/
           }
        
		   /*#DOTNET_INCLUDE_BEGIN
		   int deep = y+myOffset+perfHeight;
		   if ( deep > myPanel.get_Height() )
		   {
			   myPanel.set_Height( deep+perfHeight );
		   }
		   #DOTNET_INCLUDE_END*/

           // disegno segmento messaggio
           for(int k=-1; k<=1; k++) {
             if (x2 > x1) {
			   //#DOTNET_EXCLUDE_BEGIN
	           g.drawLine(x1,y+k,x2,y+k);
			   //#DOTNET_EXCLUDE_END
			   /*#DOTNET_INCLUDE_BEGIN
			   g.DrawLine(pen, x1, y+k+myOffset, x2, y+k+myOffset);
			   #DOTNET_INCLUDE_END*/
             } 
			 else 
			 {
			   //#DOTNET_EXCLUDE_BEGIN
	           g.drawLine(x1,y+k,x2+4,y+k);
			   //#DOTNET_EXCLUDE_END
			   /*#DOTNET_INCLUDE_BEGIN
			   g.DrawLine(pen, x1, y+k+myOffset, x2+4, y+k+myOffset);
			   #DOTNET_INCLUDE_END*/
             }
           }

           // disegno freccetta del receiver
		   //#DOTNET_EXCLUDE_BEGIN
		   g.drawPolygon(xCoords,yCoords,3);
           g.fillPolygon(xCoords,yCoords,3);
		   //#DOTNET_EXCLUDE_END
		   /*#DOTNET_INCLUDE_BEGIN
  		   Point[] xyPoints = new Point[xCoords.length];
		
		   for (int i=0; i<xCoords.length; i++)
		   {
			xyPoints[i] = new Point(xCoords[i], yCoords[i]);
		   }//End FOR block

		   g.DrawPolygon(pen, xyPoints);
		   g.FillPolygon(sb, xyPoints);
		   #DOTNET_INCLUDE_END*/

         //}
         AllReceiver++;
         //AllReceiver = AllReceiver+receiverForAMessage;
       } // while

       int msgNum = ml.size();
       for(int num = 0; num < xCanvDim; num++) {
         // Here we update the green lines of the timeline
	     //#DOTNET_EXCLUDE_BEGIN
         int x =  jade.tools.sniffer.Agent.yRet/2+num*80;
         g.setColor(new Color(0,100,50));
	     //#DOTNET_EXCLUDE_END
	     /*#DOTNET_INCLUDE_BEGIN
		 int x = (int) jade.tools.sniffer.Agent.yRet/2+num*80;
		 color = Color.FromArgb(0, 100, 50);
		 #DOTNET_INCLUDE_END*/
         //g.drawLine(x+xOffset,1,x+xOffset,timeUnitWidth*(msgNum+1));
         int counter = 0;
         for(Iterator i = ml.getMessages(); i.hasNext(); ) {
         	Message msg = (Message)i.next();
         	//int singleMsgCounter =0;
         	//for(Iterator j = msg.getAllReceiver(); j.hasNext(); )
         	//{  j.next();
         	//   singleMsgCounter++;
          //         msg.setMessageNumber(counter + singleMsgCounter);
         	//}
          //counter = counter + singleMsgCounter;        
         	msg.setMessageNumber(counter++);
         }
	     //#DOTNET_EXCLUDE_BEGIN
         g.drawLine(x+xOffset,1,x+xOffset,timeUnitWidth*(counter+1));
		 //#DOTNET_EXCLUDE_END
	     /*#DOTNET_INCLUDE_BEGIN
		 Pen pen = new Pen(color);
		 g.DrawLine(pen, x+xOffset, 1+myOffset, x+xOffset, timeUnitWidth*(counter+1)+myOffset);
		 #DOTNET_INCLUDE_END*/
       }

	   //#DOTNET_EXCLUDE_BEGIN
       g.setColor(new Color(150,50,50));
	   //#DOTNET_EXCLUDE_END
	   /*#DOTNET_INCLUDE_BEGIN
	   color = Color.FromArgb(150, 50, 50);
	   #DOTNET_INCLUDE_END*/
       Integer msgNumWrapped;
       for (int t=0; t <=AllReceiver; t++) {
          // Here we update the red numbers of the timeline
          msgNumWrapped = new Integer(t);
	      //#DOTNET_EXCLUDE_BEGIN
          g.drawString(msgNumWrapped.toString(),10,timeUnitWidth*(t)+15);
	      //#DOTNET_EXCLUDE_END
	      /*#DOTNET_INCLUDE_BEGIN
		  Font f = new Font("Arial", 10);
		  g.DrawString(msgNumWrapped.ToString(), f, new SolidBrush(color), 10, timeUnitWidth*(t)+15+myOffset);
		  #DOTNET_INCLUDE_END*/
       }
       horDim = 100+(xCanvDim*80);
       vertDim = 100+(yDim*20);
	   /*#DOTNET_INCLUDE_BEGIN
	   int deep = timeUnitWidth*(AllReceiver)+15+myOffset;
	   if ( deep > myPanel.get_Height() )
	   {
		myPanel.set_Height( deep+Agent.hRet*2 );
	   }
	   #DOTNET_INCLUDE_END*/
    }// if
  } catch (ConcurrentModificationException cme) {
     // Ignore - next repaint will correct things
  }
 } // Method

  private Integer getNewColorIndex() {
	  for (int i = 0; i < colorTable.length; ++i) {
		  Integer index = new Integer(i);
		  if (!mapToColor.containsValue(index)) {
			  return index;
		  }
	  }
	  Integer index = new Integer(colorCounter);
	  colorCounter++;
	  if (colorCounter >= colorTable.length) {
		  colorCounter = 0;
	  }
	  return index;
  }
  /**
   * Method invoked everytime the use clicks on a blue arrow: it updates the TextMessage
   * component displaying the type of the message.
   *
   * @param evt mouse event
   */
  //#DOTNET_EXCLUDE_BEGIN
  public void mousePressed(MouseEvent evt) {
  //#DOTNET_EXCLUDE_END
  /*#DOTNET_INCLUDE_BEGIN
  public void OnMousePressed(Object o, MouseEventArgs evt) {
   String messageToDisplay	= "";
  #DOTNET_INCLUDE_END*/
   String info				= "";
   Message mess;
   int numberToShow=5;

    if( ((mess = selMessage(evt)) != null) && (typeCanv == false)) {
       info = "  Message:" + mess.getMessageNumber() + " ";
       //#DOTNET_EXCLUDE_BEGIN
	   mPan.textArea.setText(" ");
       //mPan.textArea.setFont(font1);
       mPan.textArea.setText(info);
       mPan.textArea.setFont(font2);
       mPan.textArea.append(ACLMessage.getPerformative(
	   //#DOTNET_EXCLUDE_END
	   /*#DOTNET_INCLUDE_BEGIN
  	   messageToDisplay = jade.lang.acl.ACLMessage.getPerformative(
	   #DOTNET_INCLUDE_END*/
        mess.getPerformative())
         + " ( cid=" + tail(numberToShow,mess.getConversationId()) 
         + " rw="   + tail(numberToShow,mess.getReplyWith()) 
         + " irt="   + tail(numberToShow,mess.getInReplyTo()) 
         + " proto=" + mess.getProtocol()
         + " onto=" + mess.getOntology()
	   //#DOTNET_EXCLUDE_BEGIN
         + " )" );
	   //#DOTNET_EXCLUDE_END
	   /*#DOTNET_INCLUDE_BEGIN
	   + " )";
	   #DOTNET_INCLUDE_END*/
    } else {
        Agent selectedAgent = selAgent(evt);
        if ((selectedAgent != null) && (typeCanv == true)) {
			//#DOTNET_EXCLUDE_BEGIN
            mPan.textArea.setText("Agent: ");
            mPan.textArea.setFont(font2);
            mPan.textArea.append(selectedAgent.agentName);
			//#DOTNET_EXCLUDE_END
			/*#DOTNET_INCLUDE_BEGIN
			info = "Agent: ";
			messageToDisplay = selectedAgent.agentName;
			#DOTNET_INCLUDE_END*/
        }
    }
    /*#DOTNET_INCLUDE_BEGIN
	mWnd.textBox1.set_Font( font4 );
	mWnd.textBox1.set_Text(info + messageToDisplay);
	#DOTNET_INCLUDE_END*/

   }

  //#DOTNET_EXCLUDE_BEGIN
  /**
   * This method is invoked every time a user double-click on a blue arrow in the message canvas: the double-click occurs
   * on a blue arrow in the message canavs, a dialog box is displayed with the entire
   * message.
   *
   * @param evt mouse event
   */
   public void mouseClicked(MouseEvent evt) {
    Agent ag;
    Message mess;
    String info;
      if(evt.getClickCount() == 2) {

       if( ((mess = selMessage(evt)) != null) && (typeCanv == false)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -