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

📄 dfagentdscdlg.java

📁 JADE(JAVA Agent开发框架)是一个完全由JAVA语言开发的软件,它简化了多Agent系统的实现。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		// Languages
		JPanel pLanguages = new JPanel();
		pLanguages.setLayout(new BorderLayout());
		pLanguages .setBorder(BorderFactory.createTitledBorder("Languages"));
    languagesListPanel = new VisualStringList(dfdAgent.getAllLanguages(),dlgParent);
		languagesListPanel.setDimension(new Dimension(400,45));
		languagesListPanel.setEnabled(editable);
		pLanguages.add(languagesListPanel);
    main.add(pLanguages);
		main.add(Box.createRigidArea(new Dimension (0,3)));
		
		// Interaction protocols 
		JPanel pProtocols = new JPanel();
		pProtocols .setLayout(new BorderLayout());	
		pProtocols .setBorder(BorderFactory.createTitledBorder("Interaction-protocols"));
	  protocolsListPanel = new VisualStringList(dfdAgent.getAllProtocols(),dlgParent);
		protocolsListPanel.setDimension(new Dimension(400,45));
		protocolsListPanel.setEnabled(editable);
		pProtocols.add(protocolsListPanel);
		main.add(pProtocols);
		main.add(Box.createRigidArea(new Dimension (0,3)));
   
    // Services list
		JPanel pServices = new JPanel();
		pServices.setBorder(BorderFactory.createTitledBorder("Agent services"));
	  servicesListPanel = new VisualServicesList(dfdAgent.getAllServices(),dlgParent);
	  servicesListPanel.setDimension(new Dimension(400,45));
	  servicesListPanel.setEnabled(editable);
	  servicesListPanel.setCheckMandatorySlots(checkMandatorySlots);
	  pServices.add(servicesListPanel);
	  main.add(pServices);
          
              /* lease-time panel
               * The duration or time at which the lease time for this registration
               * will expire. The default value of lease time is assumed to be 
               * unlimeted
               */
               JPanel pLeaseTime = new JPanel();
               
               
               pLeaseTime.setEnabled(editable);
               pLeaseTime.setToolTipText("The duration at which the lease for this registration will expire");
               
               pLeaseTime.setSize(400, 45);
               pLeaseTime.setBorder(BorderFactory.createTitledBorder("Lease Time"));
               java.util.Date dleasetime = dfdAgent.getLeaseTime();
               if(dleasetime == null) {
                    textFieldLeaseTime = new JTextField("unlimited");
               } else {
                    textFieldLeaseTime = new JTextField(dleasetime.toString());
               }
               textFieldLeaseTime.setPreferredSize(new Dimension(335,26));
               textFieldLeaseTime.setMinimumSize(new Dimension(335,26));
               textFieldLeaseTime.setMaximumSize(new Dimension(335,26));

               textFieldLeaseTime.setEnabled(false); 
               
               // add 2 buttons: one to set the date and the second to set the time
               // of the lease-time unlimeted
               
               setLTDateb = new JButton("Set");
               setLTDateb.setEnabled(editable);
               setLTDateb.setToolTipText("Set the date at which the lease time will expire");
               
               pLeaseTime.add(setLTDateb);
               pLeaseTime.add(textFieldLeaseTime); 
               // when the button setLT is presse the dialog jade.gui.TimeChooser
               // is shown to set the date 
               // this is value is used to set the value of DFAgentDescription returned
               // by the dialog (name of var is out see below)
               absDateLeaseTime = dfdAgent.getLeaseTime();
               setLTDateb.addActionListener(this);
               // when the button 'unlimited is pressed set the lease time to 
               // the default value and the update the text field that shows 
               // the value of the lease time
             
               
               main.add(pLeaseTime);
          
    getContentPane().add(main,BorderLayout.NORTH);
			
		// OK BUTTON
		bPane = new JPanel();
		bPane.setLayout(new BoxLayout(bPane, BoxLayout.X_AXIS));
		JButton bOK = new JButton("OK");
		bOK.addActionListener( new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{    
				String param = (String) e.getActionCommand();
				if (param.equals("OK"))
					{ // the user pressed the OK button
            if(editable)
            { // if it is editable then I have to collect all data in the GUI and create a DFAgentDescription to return to the caller
            	out = new DFAgentDescription();
            	
            	if(checkSlots)
            		//AID
            	  if (newAID == null) //newAID was set when the "Set" button was pressed
            		{
            			JOptionPane.showMessageDialog(dlgParent,"AID must have a non-empty name.","Error Message",JOptionPane.ERROR_MESSAGE); 
 						      return;
            	  }
								// There is no need to check the slots of ServiceDescription because it is
            	  // done already by ServiceDscDlg
            	  	
              out.setName(newAID);
            	            		
            	//Ontologies
            	Enumeration onto = ontologiesListPanel.getContent();
            	while(onto.hasMoreElements())
            		out.addOntologies((String)onto.nextElement());
            	
            	//Protocols
            	Enumeration proto = protocolsListPanel.getContent();
            	while(proto.hasMoreElements())
            		out.addProtocols((String)proto.nextElement());
            		
            	//Languages
            	Enumeration lang = languagesListPanel.getContent();
            	while(lang.hasMoreElements())
            		out.addLanguages((String)lang.nextElement());
            	
            	//Services
            	Enumeration serv = servicesListPanel.getContent();
            	while(serv.hasMoreElements())
            	  out.addServices((ServiceDescription)serv.nextElement());
                // lease-time
                out.setLeaseTime(absDateLeaseTime);
                
            	  	
            }
            else
              out = dfdAgent; // if not editable returns the old dfd
            
						dispose();
					}
			} 
		} );
		
		bPane.add(bOK);
		
		if(editable)
		{
			JButton cancelButton = new JButton("Cancel");
			cancelButton.addActionListener(new ActionListener()
			{
			
				public void actionPerformed(ActionEvent e)
				{
					String param = e.getActionCommand();
					if(param.equals("Cancel"))
					{
						out = null;
						dispose();
					}
				}
			});
			
			bPane.add(cancelButton);
		}
		main.add(Box.createRigidArea(new Dimension(300,20)));
		main.add(bPane);
		main.add(Box.createRigidArea(new Dimension(300,20)));
		getContentPane().add(main, BorderLayout.CENTER);

		setModal(true);
		setResizable(false);
	
		ShowCorrect();
		return out;
    
	}
        
       
        
	private void ShowCorrect() 
 	 {
    pack();
   
    try{
		//#DOTNET_EXCLUDE_BEGIN
    	int x = getOwner().getX() + (getOwner().getWidth() - getWidth()) / 2;
    	int y = getOwner().getY() + (getOwner().getHeight() - getHeight()) / 2; 
		//#DOTNET_EXCLUDE_END
		/*#DOTNET_INCLUDE_BEGIN
    	int x = getOwner().getX() + (getOwner().WIDTH - getWidth()) / 2;
    	int y = getOwner().getY() + (getOwner().HEIGHT - getHeight()) / 2; 
		#DOTNET_INCLUDE_END*/
    	setLocation(x>0 ? x:0,y>0 ? y:0);
    }catch(Exception e){}

    setVisible(true);
    toFront();
 	 }

    //#APIDOC_EXCLUDE_BEGIN       
        /* Handle action after the button of inesub panel are pressed */
       public void actionPerformed(ActionEvent e) {
            JButton sourceEvent = (JButton) e.getSource();
            // when the button setLT is presse the dialog jade.gui.TimeChooser
            // is shown to set the date 
            // this is value is used to set the value of DFAgentDescription returned
            // by the dialog (name of var is out see below)
            if(sourceEvent.equals(setLTDateb)) {
                TimeChooser timeChooser = new TimeChooser();
                if (timeChooser.showEditTimeDlg(null) == TimeChooser.OK) {
                    if(timeChooser.getDate()!= null) {    
                        absDateLeaseTime = timeChooser.getDate();
                        textFieldLeaseTime.setText(absDateLeaseTime.toString());
                    } else {
                       // the button "Reset" on the time choose impors pressed
                       // the set the valut
                       // set the lease time to 
                       // the default value and the update the text field that shows 
                       // the value of the lease time
                        absDateLeaseTime = new java.util.Date(-1);
                        textFieldLeaseTime.setText("unlimited");

                    }
                    
                    
                }
            // when the button 'unlimited is pressed set the lease time to 
           // the default value and the update the text field that shows 
           // the value of the lease time
           
                return;
            }
            return;
        }
    //#APIDOC_EXCLUDE_END                

	
}

⌨️ 快捷键说明

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