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

📄 videotool.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
*/



/*******************************************************************
 *                    Video Tools for Zeus                         *
 *   Provides functionality to use record and playback feature     *
 *******************************************************************/

package zeus.visualiser.basic;

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

import zeus.util.*;
import zeus.concepts.*;
import zeus.gui.*;
import zeus.actors.*;
import zeus.visualiser.*;


public abstract class VideoTool extends BasicTool {
  protected static final int PLAYBACK = 0;
  protected static final int ONLINE   = 1;

  protected static final int FORWARD  = 0;
  protected static final int BACKWARD = 1;

  private NumberDialog                    number_dialog = null;
  private EditableMultipleSelectionDialog dialog = null;
  private EditableDoubleSelectionDialog   proxy_dialog = null;

  protected VideoToolBar videoToolbar = null;
  protected StateInfo    state;

  public VideoTool(AgentContext context, VisualiserModel model) {
     super(context,model);
     state = new StateInfo();
     state.animating = true;
     state.mode = ONLINE;
     state.saving = false;
     videoToolbar = new VideoToolBar();
  }

  public void Exit() {
     this.setVisible(false);
     removeSubscriptions();
     if ( state.player != null ) {
        state.player.terminate();
        state.player = null;
     }
     this.dispose();
  }

  protected boolean stopPlayback() {
     if ( state.mode == PLAYBACK ) {
        int result = JOptionPane.showConfirmDialog(this,
           "There is an open database connection\nClose connection?",
           "Warning", JOptionPane.YES_NO_OPTION);
        if ( result == JOptionPane.YES_OPTION )
           Close();
     }
     return state.mode == ONLINE;
  }

  public void Sessions() {
     /**
       send a query to a DbProxy to return the names of
       saved sessions belonging to this agent
     */

     if ( !hubOK() ) return;

     String[] db_servers = model.getDbProxys();
     if ( dialog == null ) {
        dialog = new EditableMultipleSelectionDialog(this,"Select DbProxy");
        dialog.setLocationRelativeTo(this);
     }

     dialog.setListData(db_servers);
     Object[] selection = dialog.getSelection();

     if ( selection != null ) {
        model.addDbProxys(Misc.stringArray(dialog.getListData()));

        query("db_sessions " + getClass().getName(),
           Misc.stringArray(selection), "db_sessions");
     }
  }

  public void Delete() {
     /**
        send a request to a DbProxy to delete the specified
        saved session belonging to this agent
     */

     if ( !hubOK() ) return;

     String sessionType = this.getClass().getName();
     Hashtable input = model.getDbSessions(sessionType);
     if ( proxy_dialog == null ) {
        proxy_dialog = new EditableDoubleSelectionDialog(this,
	   "Select DbProxy & Session Name","DbProxy Agent","Session Name");
        proxy_dialog.setLocationRelativeTo(this);
     }

     proxy_dialog.setListData(input);
     Object[] selection = proxy_dialog.getSelection();

     if ( selection != null ) {
        Hashtable output = proxy_dialog.getListData();
	model.addDbSessions(sessionType,output);

        request("db_delete " + sessionType + " " + selection[1],
           (String)selection[0], "db_delete");
     }
  }

  public void Purge() {
     /**
        send a request to a DbProxy to purge all
        saved sessions belonging to this agent
     */

     if ( !hubOK() ) return;

     String[] db_servers = model.getDbProxys();
     if ( dialog == null ) {
        dialog = new EditableMultipleSelectionDialog(this,"Select DbProxy");
        dialog.setLocationRelativeTo(this);
     }

     dialog.setListData(db_servers);
     Object[] selection = dialog.getSelection();

     if ( selection != null ) {
        model.addDbProxys(Misc.stringArray(dialog.getListData()));

        request("db_purge " + getClass().getName(),
           Misc.stringArray(selection), "db_purge");
     }
  }

  public void Load() {
     if ( !hubOK() ) return;
     if ( !stopPlayback() ) return;

     if ( state.saving ) {
        int result = JOptionPane.showConfirmDialog(this,
            "There is an open database connection\n" +
            "and saving is in progress.\nClose current connection?",
	    "Warning", JOptionPane.YES_NO_OPTION);
        if ( result == JOptionPane.YES_OPTION)
           Close();
        else
           return;
     }

     String sessionType = this.getClass().getName();
     Hashtable input = model.getDbSessions(sessionType);
     if ( proxy_dialog == null ) {
        proxy_dialog = new EditableDoubleSelectionDialog(this,
	   "Select DbProxy & Session Name", "DbProxy Agent","Session Name");
        proxy_dialog.setLocationRelativeTo(this);
     }

     proxy_dialog.setListData(input);
     Object[] selection = proxy_dialog.getSelection();

     if ( selection != null ) {
        Hashtable output = proxy_dialog.getListData();
	model.addDbSessions(sessionType,output);

        // adjust buttons etc
        setMode(PLAYBACK);

        state.proxy = (String)selection[0];
        state.session = (String)selection[1];
        state.key = context.newId("LoadSessionKey");
        state.mode = PLAYBACK;
        state.player = new Player(this);

	request("db_open " + sessionType + " " + state.session +
	   " " + state.key, state.proxy, "db_open");
     }
  }

  public void Record() {
     if ( state.saving ) {
        int result = JOptionPane.showConfirmDialog(this,
            "There is an open database connection\n" +
            "and saving is in progress.\nClose current connection?",
	    "Warning", JOptionPane.YES_NO_OPTION);
        if ( result == JOptionPane.YES_OPTION)
           Close();
        else
           return;
     }

     String sessionType = this.getClass().getName();
     Hashtable input = model.getDbSessions(sessionType);
     if ( proxy_dialog == null ) {
        proxy_dialog = new EditableDoubleSelectionDialog(this,
	   "Select DbProxy & Session Name", "DbProxy Agent","Session Name");
        proxy_dialog.setLocationRelativeTo(this);
     }

     proxy_dialog.setListData(input);
     Object[] selection = proxy_dialog.getSelection();

     if ( selection != null ) {
        Hashtable output = proxy_dialog.getListData();
	model.addDbSessions(sessionType,output);

        state.proxy = (String)selection[0];
        state.session = (String)selection[1];
        state.key = context.newId("SaveSessionKey");
        state.errored = false;

	request("db_create " + sessionType + " " + state.session +
           " " + state.key, state.proxy, "db_create");
     }
  }

  public void Close() {
     if ( hubOK() && state.key != null ) {
        // close db connection
	request("db_close " + state.key, state.proxy, "db_close");
        state.key = null;
        // initialize view & reconstruct online society view
        if ( state.mode == PLAYBACK ) {
           if ( state.player != null ) {
              state.player.terminate();
              state.player = null;
           }
        }
     }
     setMode(ONLINE);
     state.mode = ONLINE;
     state.saving = false;
     state.errored = false;
  }

  public void Forward() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.forward();
  }

  public void Rewind() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.rewind();
  }

  public void FForward() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.fforward();
  }

  public void FRewind() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.frewind();
  }

  public void Stop() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.pause();
  }

  public void StepForward() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.forward_step();
  }

  public void ForwardEnd() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.last();
  }

  public void StepRewind() {
     if ( state.mode == PLAYBACK && !state.errored )
        state.player.rewind_step();
  }

  public void RewindBegin() {
     if ( state.mode == PLAYBACK && !state.errored )

⌨️ 快捷键说明

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