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

📄 aclgui.java

📁 JADE(JAVA Agent开发框架)是一个完全由JAVA语言开发的软件,它简化了多Agent系统的实现。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	    String command = e.getActionCommand();
	    AIDGui guiSender = new AIDGui(ownerGui);
        
	    if(command.equals("Set"))
	    {
	      AID senderToView = SenderAID;
	      //another sender was already inserted.
	      if(newAIDSender != null)
		senderToView = newAIDSender;
	      senderToView = guiSender.ShowAIDGui(senderToView,true,true);
	      //if the cancel button was clicked --> maintain the old value inserted.
	      if (senderToView != null)
	       {newAIDSender = senderToView;
		 //the name can be different
		sender.setText(newAIDSender.getName());
	       }
	    }
	    else
	    if(command.equals("View"))
	      guiSender.ShowAIDGui(SenderAID, false,false);
        
	  }
	});
    
	// Receiver (line # 1)
	l = new JLabel("Receivers:");
    //#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l,0,1,1,1,false);
	receiverListPanel = new VisualAIDList(new ArrayList().iterator(),ownerGui);
	receiverListPanel.setDimension(new Dimension(205,37));
	put(aclPanel,receiverListPanel,1,1,2,1,false);

    
	//Reply-to (line #2)
	l = new JLabel("Reply-to:");
    //#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 2, 1, 1,false);
	replyToListPanel = new VisualAIDList(new ArrayList().iterator(),ownerGui);
	replyToListPanel.setDimension(new Dimension(205,37));
	put(aclPanel,replyToListPanel,1,2,2,1,false);
      
	// Communicative act (line # 3)
	l = new JLabel("Communicative act:");
	//#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 3, 1, 1, false);  
	communicativeAct = new JComboBox(); 
    
	String[] comm_Act = ACLMessage.getAllPerformativeNames();
	for (int ii=0; ii<comm_Act.length; ii++)
	    communicativeAct.addItem(comm_Act[ii].toLowerCase());
      
	communicativeAct.setSelectedIndex(0);
	put(aclPanel,communicativeAct, 1, 3, 2, 1, true);

	// Content (line # 4-8)
	l = new JLabel("Content:");
	//#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 4, 3, 1, false);     
	content = new JTextArea(5,TEXT_SIZE);
	JScrollPane contentPane = new JScrollPane();
	contentPane.getViewport().setView(content);   
	put(aclPanel,contentPane, 0, 5, 3, 4, false);
	contentPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);    
	contentPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);    

	// Language (line # 9)
	l = new JLabel("Language:");
	//#DOTNET_EXCLUDE_BEGIN
    new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 9, 1, 1, false);     
	language = new JTextField();
	language.setBackground(Color.white);
	put(aclPanel,language, 1, 9, 2, 1, false);  
  
	//Encoding (line # 10)
	l = new JLabel("Encoding:");
    //#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 10, 1, 1, false);      
	encoding = new JTextField(); 
	encoding.setBackground(Color.white);
	put(aclPanel,encoding, 1, 10, 2, 1, false); 
    
	// Ontology (line # 11)
	l = new JLabel("Ontology:");
    //#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 11, 1, 1, false);      
	ontology = new JTextField();
	ontology.setBackground(Color.white);
	put(aclPanel,ontology, 1, 11, 2, 1, false); 

	// Protocol (line # 12)
	l = new JLabel("Protocol:");
    //#DOTNET_EXCLUDE_BEGIN
	new DropTarget(l, this);
    //#DOTNET_EXCLUDE_END
	put(aclPanel,l, 0, 12, 1, 1, false);      
	protocol = new JComboBox();   
	for (i = 0;i < fipaProtocolArrayList.size(); ++i)
	  protocol.addItem((String) fipaProtocolArrayList.get(i));
	protocol.addItem(LABEL_TO_ADD_PROT);
	protocol.addItem("Null");
	protocol.setSelectedItem("Null");
	lastSelectedIndex = protocol.getSelectedIndex();
	lastSelectedItem = (String) protocol.getSelectedItem();
	put(aclPanel,protocol, 1, 12, 2, 1, true);
	protocol.addActionListener( new ActionListener()
				      {
			public void actionPerformed(ActionEvent e)
			{    
			  String param = (String) protocol.getSelectedItem();
                        
			  // BEFORE THE CURRENT SELECTION THE JComboBox WAS NON EDITABLE (a FIPA protocol or null was selected)
			  if (!protocol.isEditable()) 
			  {
			    // If a user defined protocol has just been selected --> set editable to true
			    if (fipaProtocolArrayList.indexOf((Object) param) < 0 && !param.equals("Null"))
			    {
			      protocol.setEditable(true);
			    }
			  }
			  // BEFORE THE CURRENT SELECTION THE JComboBox WAS EDITABLE (an editable protocol was selected)
			  else 
			  {
			    // The user selected a FIPA protocol or null (he didn't perform any editing operation) 
			    if (fipaProtocolArrayList.indexOf((Object) param) >= 0 || param.equals("Null"))
			    {
			      protocol.setEditable(false);
			      protocol.setSelectedItem(param);
			    }
			    // The user selected the label to add a new protocol (he didn't perform any editing operation) 
			    else if (param.equals(LABEL_TO_ADD_PROT))
			    {
			      protocol.setSelectedItem(param);
			    } 
			    // The user added a new protocol
			    else if (lastSelectedItem.equals(LABEL_TO_ADD_PROT))
			    {     
			      // The new protocol is actually added only if it is != "" and is not already present  
			      if (!param.equals("")) 
			      {
				protocol.addItem(param);
				int cnt = protocol.getItemCount();
				protocol.setSelectedItem(param);
				int n = protocol.getSelectedIndex();
				if (n != cnt-1)
				  protocol.removeItemAt(cnt-1);
			      }
			      else 
			      {
				protocol.setEditable(false);
				protocol.setSelectedItem("Null");
			      }
			    }
			    // The user modified/deleted a previously added user defined protocol
			    else if (lastSelectedItem != LABEL_TO_ADD_PROT)
			    {
			      protocol.removeItemAt(lastSelectedIndex);  // The old protocol is removed
			      if (param.equals("")) // Deletion
			      {
				protocol.setEditable(false);
				protocol.setSelectedItem("Null");
			      }
			      else // Modification
			      {
				protocol.addItem(param);
				protocol.setSelectedItem(param);
			      }
			    }
			  }

			  lastSelectedIndex = protocol.getSelectedIndex();
			  lastSelectedItem = (String) protocol.getSelectedItem();
			}
		      } );

      // Conversation-id (line # 13)
      l = new JLabel("Conversation-id:");
      //#DOTNET_EXCLUDE_BEGIN
      new DropTarget(l, this);
      //#DOTNET_EXCLUDE_END
      put(aclPanel,l, 0, 13, 1, 1, false);      
      conversationId = new JTextField();
      conversationId.setBackground(Color.white);
      put(aclPanel,conversationId, 1, 13, 2, 1, false); 

      // In-reply-to (line # 14)
      l = new JLabel("In-reply-to:");
      //#DOTNET_EXCLUDE_BEGIN
      new DropTarget(l, this);
      //#DOTNET_EXCLUDE_END
      put(aclPanel,l, 0, 14, 1, 1, false);      
      inReplyTo = new JTextField();   
      inReplyTo.setBackground(Color.white);
      put(aclPanel,inReplyTo, 1, 14, 2, 1, false);  

      // Reply-with (line # 15)
      l = new JLabel("Reply-with:");
      //#DOTNET_EXCLUDE_BEGIN
      new DropTarget(l, this);
      //#DOTNET_EXCLUDE_END
      put(aclPanel,l, 0, 15, 1, 1, false);      
      replyWith = new JTextField();   
      replyWith.setBackground(Color.white);
      put(aclPanel,replyWith, 1, 15, 2, 1, false);  
    
      // Reply-by (line # 16)
      replyByDate = null;
      l = new JLabel("Reply-by:");
      //#DOTNET_EXCLUDE_BEGIN
      new DropTarget(l, this);
      //#DOTNET_EXCLUDE_END
      put(aclPanel,l, 0, 16, 1, 1, false);
      replyBySet = new JButton("Set");
      replyBySet.setMargin(new Insets(2,3,2,3));
      replyBy = new JTextField();
      replyBy.setBackground(Color.white);
      put(aclPanel,replyBySet, 1, 16, 1, 1, false);
      put(aclPanel,replyBy, 2, 16, 1, 1, false);  
      replyBySet.addActionListener(new  ActionListener()
	  { // BEGIN anonumous class
	      public void actionPerformed(ActionEvent e)
	      {
		String command = e.getActionCommand();
		//TimeChooser t = new TimeChooser(replyByDate);
		TimeChooser t = new TimeChooser();
		String d = replyBy.getText();
		if (!d.equals(""))
		{
		  try
		  {
		    t.setDate(ISO8601.toDate(d));
		  }
		  catch (Exception ee) { 
		  if(logger.isLoggable(Logger.SEVERE))
		  	logger.log(Logger.WARNING,"Incorrect date format"); }
		}
		if (command.equals("Set"))
		{
		  if (t.showEditTimeDlg(null) == TimeChooser.OK)
		  {
		    replyByDate = t.getDate();
		    if (replyByDate == null)
		      replyBy.setText("");
		    else
		      replyBy.setText(ISO8601.toString(replyByDate));
		  }
		}
		else if (command.equals("View"))
		{         
		  t.showViewTimeDlg(null);
		}
	      } // END actionPerformed(ActionEvent e)
	  } // END anonymous class
	);

    
      //Properties (line #17)
      l = new JLabel("User Properties:");
      //#DOTNET_EXCLUDE_BEGIN
      new DropTarget(l, this);
      //#DOTNET_EXCLUDE_END
      put(aclPanel,l, 0, 17, 1, 1, false);
      propertiesListPanel = new VisualPropertiesList(new Properties(),ownerGui);
      propertiesListPanel.setDimension(new Dimension(205,37));
      put(aclPanel,propertiesListPanel,1,17,2,1,false);
    
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      add(aclPanel);

    } // END AclMessagePanel()

    //#DOTNET_EXCLUDE_BEGIN
    public void dragOver(java.awt.dnd.DropTargetDragEvent p1) {
      if(logger.isLoggable(Logger.FINEST))
      	logger.log(Logger.FINEST,"dragOver");
    }    

    public void dropActionChanged(java.awt.dnd.DropTargetDragEvent p1) {
      if(logger.isLoggable(Logger.FINEST))
      	logger.log(Logger.FINEST,"dropActionChanged");
    }
    
    public void dragEnter(java.awt.dnd.DropTargetDragEvent dragEvent) {
      if(logger.isLoggable(Logger.FINEST))
      	logger.log(Logger.FINEST,"dragEnter");
    }

    public void dragExit(java.awt.dnd.DropTargetEvent p1) {
      if(logger.isLoggable(Logger.FINEST))
      	logger.log(Logger.FINEST,"dragExit");
    }

    public void drop(java.awt.dnd.DropTargetDropEvent dropEvent)
    {
	boolean completionStatus = false;
	java.util.List fileList = null;

	try {
	  dropEvent.acceptDrop(DnDConstants.ACTION_COPY);

	  Transferable xferInfo = dropEvent.getTransferable();
	  fileList = (java.util.List)(xferInfo.getTransferData(DataFlavor.javaFileListFlavor));
	  completionStatus = true;
	}
	catch (UnsupportedFlavorException exc) {
	    completionStatus = false;
	}
	catch (IOException exc) {
	    if(logger.isLoggable(Logger.WARNING))
	    	logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	    completionStatus = false;
	}
	finally {
	    dropEvent.dropComplete(completionStatus);
	}

	if (fileList != null)
	{
	   Iterator fileItor = fileList.iterator();
	   ACLParser aclParser = ACLParser.create();
	   while (fileItor.hasNext())
	   {
	       try {
		 java.io.File f = (java.io.File)(fileItor.next());
		 FileReader aclMsgFile = new FileReader(f);
		 Enumeration receivers = receiverListPanel.getContent();
		 setMsg( aclParser.parse(aclMsgFile) );
		 if ( receivers.hasMoreElements() ) {
		     if(logger.isLoggable(Logger.FINE))
		     	logger.log(Logger.FINE,"revert to saved list");
		     ArrayList list = new ArrayList();
		     while(receivers.hasMoreElements()) {
		       list.add(receivers.nextElement());
		     }
		     receiverListPanel.resetContent(list.iterator());
		 }
	       }
	       catch (IOException exc) {
		  if(logger.isLoggable(Logger.WARNING))
			  logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	       }
	       catch (ParseException exc) {
		  if(logger.isLoggable(Logger.WARNING))
		  	logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	       }
	       catch (Exception exc) {
		  if(logger.isLoggable(Logger.WARNING))
		  	logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	       }
	       catch (Error exc) {
		  if(logger.isLoggable(Logger.WARNING))
		  	logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	       }
	       catch (Throwable exc) {
		  if(logger.isLoggable(Logger.WARNING))
		  	logger.log(Logger.WARNING,"DragAndDrop operation failed: " + exc);
	       }
	   } //~ while (fileItor.hasNext())
	} //~ if (selectedItems != null)

    } // END drop(dropEvent)
    //#DOTNET_EXCLUDE_END

  } // END class AclMessagePanel
  
  //this private class build a panel to show the envelope field of an ACLMessage
  private class EnvelopePanel extends JPanel
  {
    EnvelopePanel()
    {
  
    JLabel l;
    int    i;
   
    //minDim = new Dimension();
    aclPanel = new JPanel();
    //aclPanel.setBackground(Color.lightGray); 
    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);
    
    // To  (line # 0)
    l = new JLabel("To:");
    put(aclPanel,l, 0, 0, 1, 1, false); 
    toPanel = new VisualAIDList(new ArrayList().iterator(),ownerGui);
    toPanel.setDimension(new Dimension(205,37));  
    put(aclPanel,toPanel, 1, 0, 2, 1, false); 
  
    //From (line #1)
    l = new JLabel("From:");
    put(aclPanel,l, 0, 1, 1, 1,false);
    fromButton = new JButton("Set");
    fromButton.setMargin(new Insets(2,3,2,3));
    put(aclPanel,fromButton,1,1,1,1,false);
    from = new JTextField();
    from.setEditable(false);
    from.setBackground(Color.white);
    put(aclPanel,from,2,1,1,1,false);
    fromButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
        String command = e.getActionCommand();
        AIDGui guiFrom = new AIDGui(ownerGui);
        if(command.equals("Set"))
        {
          AID fromToView = fromAID;
          if (newAIDFrom != null)
            fromToView = newAIDFrom;
          fromToView = guiFrom.ShowAIDGui(fromToView,true,true);
          if(fromToView != null)
            {
              newAIDFrom = fromToView;
              from.setText(newAIDFrom.getName());
            }
        }else
        {
          if(command.equals("View"))
            guiFrom.ShowAIDGui(fromAID,false,false);
        }
      }
    });
    
    //Comments (line # 2-6)
    l = new JLabel("Comments:");
    put(aclPanel,l,0,2,1,1,false);

⌨️ 快捷键说明

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