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

📄 societytool.java

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* The contents of this file are subject to the BT "ZEUS" Open Source 
* Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
* except in compliance with the Licence. You may obtain a copy of the Licence
* from $ZEUS_INSTALL/licence.html or alternatively from
* http://www.labs.bt.com/projects/agents/zeus/licence.htm
* 
* Except as stated in Clause 7 of the Licence, software distributed under the
* Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
* implied. See the Licence for the specific language governing rights and 
* limitations under the Licence.
* 
* The Original Code is within the package zeus.*.
* The Initial Developer of the Original Code is British Telecommunications
* public limited company, whose registered office is at 81 Newgate Street, 
* London, EC1A 7AJ, England. Portions created by British Telecommunications 
* public limited company are Copyright 1996-9. All Rights Reserved.
* 
* THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
*/



/*******************************************************************
 *          ZEUS Agent Society Viewer with Video Tools             *
 *        Allows the user to view the interaction of agents        *
 *         and use video tool features to examine sessions         *
 *******************************************************************/

package zeus.visualiser.society;

import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import zeus.util.*;
import zeus.concepts.*;
import zeus.gui.*;
import zeus.gui.graph.*;
import zeus.gui.help.*;
import zeus.actors.*;
import zeus.visualiser.VisualiserModel;
import zeus.visualiser.basic.*;


public class SocietyTool extends VideoTool {
   private static int count = 0;

   private EditableMultipleSelectionDialog update_dialog   = null;
   private EditableMultipleSelectionDialog message_dialog  = null;
   private NumberDialog                    number_dialog = null;

   private SocietyMenuBar menubar;

   protected SocietyModel     onlineModel, offlineModel;
   protected AnimationManager animationManager;
   protected Graph            graph;

   public SocietyTool(AgentContext context, VisualiserModel model) {
     super(context,model);
     setTitle(context.whoami() + " - SocietyTool:" + (count++));
     String path = SystemProps.getProperty("gif.dir") + File.separator +
                   "visualiser" + File.separator + "society-icon.gif";
     ImageIcon icon = new ImageIcon(path);
     setIconImage(icon.getImage());
     setBackground(Color.lightGray);

     onlineModel = new SocietyModel();
     offlineModel = new SocietyModel();

     SocietyPanel societyPanel = new SocietyPanel(onlineModel);
     graph = societyPanel.getGraph();
     animationManager = new AnimationManager(context,graph);

     // Create a panel to model the frame contents
     Container pane = getContentPane();
     pane.setLayout(new BorderLayout());
     pane.add(societyPanel, BorderLayout.CENTER);
     pane.add(videoToolbar,BorderLayout.NORTH);

     menubar = new SocietyMenuBar();
     setJMenuBar(menubar);

     pack();
     setVisible(true);
     setMode(ONLINE);
     initialRegistration();
   }

   public void Exit() {
     if ( animationManager != null )
        animationManager.terminate();
     super.Exit();
   }

   public void UpdateRelations() {
      if ( !hubOK() ) return;
      if ( !stopPlayback() ) return;
  
      String[] agents = model.getAgents();
      if ( update_dialog == null ) {
         update_dialog = new EditableMultipleSelectionDialog(this,
            "Select Agents", agents);
         update_dialog.setLocationRelativeTo(this);
      }
      else {
         Object[] chosen = update_dialog.getPriorSelection();
         update_dialog.setListData(agents);
         update_dialog.setSelection(chosen);
      }

      Object[] data = update_dialog.getSelection();
      model.addAgents(Misc.stringArray(update_dialog.getListData()));
      if ( data != null && data.length > 0 )
         query("your_relations",Misc.stringArray(data),"log_relations");
   }

   public void StreamMessages(boolean mode) {
      if ( !hubOK() ) return;
      if ( !stopPlayback() ) return;

      String[] agents = model.getAgents();
      if ( message_dialog == null ) {
         message_dialog = new EditableMultipleSelectionDialog(this,
            "Select Agents", agents);
         message_dialog.setLocationRelativeTo(this);
      }
      else {
         Object[] chosen = message_dialog.getPriorSelection();
         message_dialog.setListData(agents);
         message_dialog.setSelection(chosen);
      }

      Object[] data = message_dialog.getSelection();
      model.addAgents(Misc.stringArray(message_dialog.getListData()));
      subscribe(mode,model.keys[VisualiserModel.MESSAGE_KEY],
         Misc.stringArray(data),"log_message");
   }

   protected void setMode(int mode) {
     if ( mode == ONLINE ) {
        menubar.update(ONLINE);
        videoToolbar.setStatus(false);
        graph.setModel(onlineModel);
     }
     else {
        menubar.update(PLAYBACK);
        videoToolbar.setStatus(true);
        graph.setModel(offlineModel);
     }
   }

   protected void initialRegistration() {
      String type = SystemProps.getProperty("agent.names.agent");
      String[] agent = model.getAgents(type);
      for(int i = 0; i < agent.length; i++ )
         registerAgent(agent[i],type);

      type = SystemProps.getProperty("agent.names.facilitator");
      agent = model.getAgents(type);
      for(int i = 0; i <  agent.length; i++ )
         registerAgent(agent[i],type);

      type = SystemProps.getProperty("agent.names.visualiser");
      agent = model.getAgents(type);
      for(int i = 0; i <  agent.length; i++ )
         registerAgent(agent[i],type);

      type = SystemProps.getProperty("agent.names.dbProxy");
      agent = model.getAgents(type);
      for(int i = 0; i <  agent.length; i++ )
         registerAgent(agent[i],type);

      type = SystemProps.getProperty("agent.names.nameserver");
      agent = model.getAgents(type);
      for(int i = 0; i <  agent.length; i++ )
         registerAgent(agent[i],type);
   }

   protected void registerAgent(String name, String type) {
      onlineModel.addAgent(name,type);
      debug ("added online name = " + name ); 
   }

   protected void registerListOfPlaybackAgents(Vector List) {
      offlineModel.addAgents(List);
   }

   protected void  visualiseVideoData(int dir, Performative msg) {
      if ( state.mode == PLAYBACK && state.animating && filterMsg(msg) ) {
         // check if going forwards or backwards
         if ( dir == BACKWARD ) {
            String sender = msg.getReceiver();
            msg.setReceiver(msg.getSender());
            msg.setSender(sender);
         }
         animationManager.animate(msg);
      }
   }

   public void log_relations(Performative msg) {
      if (!msg.getType().equals("inform") ) return;
      Vector List = ZeusParser.relationshipList(msg.getContent());
      String agent = msg.getSender();
      onlineModel.addRelations(agent,List);
   }

   public void log_message(Performative msg) {
    debug("log_message 1"); 
try {
      Performative imsg = ZeusParser.performative(msg.getContent());
         debug("log_message 2"); 
      if ( state.mode == ONLINE && state.animating && filterMsg(imsg) )
         animationManager.animate(imsg);
            debug("log_message 3"); 

      // save to persistent db
      record_item(imsg);
}
catch(Exception e) {
       e.printStackTrace();
}
   }

   void Animation(boolean set) {
      state.animating = set;
      if ( !set ) animationManager.flushAnimator();
   }

   void setAnimationMode(int mode) {
      animationManager.setMode(mode);
   }

   void AnimationSpeed() {
      long speed = animationManager.getSpeed();
      if ( number_dialog == null ) {
         number_dialog = new NumberDialog(this,"Set Animation Speed",
            "Enter speed:");
         number_dialog.setLocationRelativeTo(this);
      }
      number_dialog.setValue(speed);
      Long value = number_dialog.getValue();
      if (value != null)
         animationManager.setSpeed(value.longValue());
   }

   void Help() {
      Point pt = getLocation();
      HelpWindow helpWin = new HelpWindow(this, pt, "visualiser", "Society Viewer");
      helpWin.setSize(new Dimension(getWidth(), 500));
      helpWin.setLocation(pt.x+24, pt.y+24);
      helpWin.validate();
   }

   public class SocietyMenuBar extends JMenuBar
                               implements ActionListener, ItemListener {

     protected JMenuItem connect, disconnect, exit;

⌨️ 快捷键说明

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