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

📄 dispatcher.java

📁 sound recorder which supports .wav format files
💻 JAVA
字号:
package com.vimas.interfaceapplet;

import java.applet.AppletContext;
import java.util.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Vimas technologies</p>
 * @author miha
 * @version 1.0
 */

public class Dispatcher implements Observer
{
  InterfaceApplet ia=null;
  RPAppletInterface rpi=null;

  private boolean isSaved=false;
  private boolean isProcessing=false;//rec or play

  int confirmRequirer=0;
  //=0 - report
  //=1 - open
  //=2 - record

  String UserServerFolder=new String();

public Dispatcher(InterfaceApplet ia)
  {
  this.ia=ia;
  Initializer i = new Initializer(ia.getAppletContext());
  i.addObserver(this);
  Thread th= new Thread(i);
  th.start();
  //disabling buttons
  ia.open.setEnabled(false);
  ia.save.setEnabled(false);
  ia.play.setEnabled(false);
  ia.pause.setEnabled(false);
  ia.record.setEnabled(false);
  ia.stop.setEnabled(false);
  }
//******************************************************************************
   private void updateButtonsEnabling()
   {
     boolean isPlayEnable = false;
     boolean isPauseEnable = false;
     boolean isRecordEnable = false;
     boolean isStopEnable = false;
     boolean isOpenEnable = false;
     boolean isSaveEnable = false;

     if (this.isProcessing)
     {
       isRecordEnable = false;
       isPlayEnable = false;
       isOpenEnable = false;
       isSaveEnable = false;
       isStopEnable = true;
       isPauseEnable = true;
     }
     else
     {
       isPlayEnable = true;
       isRecordEnable = true;
       isOpenEnable = true;
       isSaveEnable = true;
       isStopEnable = false;
       isPauseEnable = false;
     }

     if (isSaved) isSaveEnable = false;
     else isSaveEnable = !isProcessing; //not play/rec - may save

     ia.open.setEnabled(isOpenEnable);
     ia.save.setEnabled(isSaveEnable);
     ia.play.setEnabled(isPlayEnable);
     ia.pause.setEnabled(isPauseEnable);
     ia.record.setEnabled(isRecordEnable);
     ia.stop.setEnabled(isStopEnable);
   }
//~~~~~~~~~~~~~RPAPPLET METHODS, INVOCED BY INTERFACE APPLET~~~~~~~~~~~~~~~~~~~~
//******************************************************************************
public void stop()
{
rpi.STOP();
}
//******************************************************************************
public void record()
{
  rpi.RECORD();
}
//******************************************************************************
 public void play()
 {
 rpi.PLAYBACK();
 }
//******************************************************************************
public void pause()
{
  rpi.PAUSE();
}
//******************************************************************************
 public void open()
 {
 if(Messages.DiskVersion) {rpi.WEBPLAY(new String());return;}
 String path=new String();
 if(!UserServerFolder.equals(""))path+=UserServerFolder+"/";
 if(ia.getSelectedFileName()!=null)
   {
     path+=ia.getSelectedFileName();
     rpi.WEBPLAY(path);
   }
 }
//******************************************************************************
public void save()
{
  if(Messages.DiskVersion) {rpi.UPLOAD(new String());return;}
  UploadDialogThread dth = new UploadDialogThread();
 dth.setParams(this);
// this.confirmRequirer=0;
 Thread th=new Thread(dth);
 th.start();
}
//******************************************************************************
public void save(String s)
{
  System.out.println("IA:listen="+s);
  if(s.equalsIgnoreCase("-1neHo4uUpload"))return;
  rpi.UPLOAD(s);
}

//******************************************************************************
public void update(Observable o, Object obj)
  {
    //System.out.println("IA:DISPATCHER:Class="+o.getClass().getName());
    if(o.getClass().getName().equalsIgnoreCase("com.vimas.interfaceapplet.Initializer"))
    {
      rpi = new RPAppletInterface(obj);
      this.updateButtonsEnabling();
      ia.setMainPanelAvailable();
    }
    if(o.getClass().getName().equalsIgnoreCase("com.vimas.interfaceapplet.DialogFrame$Obs"))
    {
//      System.out.println("IA:bla1");
      this.confirmReceived(obj);
    }
    if(o.getClass().getName().equalsIgnoreCase("com.vimas.interfaceapplet.UploadFileDialog$Obs"))
    {
      //System.out.println("IA:bla2");
      this.save((String)obj);//.confirmReceived(obj);
    }


  }
//~~~~~~~~~~~~~~~~~~~~INTERFACE APPLET METHODS, INVOCED BY RPAPPLET~~~~~~~~~~~~~
//******************************************************************************
public void setStatus_RP(String num, String s)
{
int n=0;
  n=Integer.parseInt(num);
  if(n==2){isProcessing=true;isSaved=false;}//recording
  if(n==5)isProcessing=true;//playing
  if(n==4)isProcessing=false;//stop
  if(n==10){isSaved=true;isProcessing=true;}//file listening
  if(n==6)isSaved=true;//saved
//  if(n==10)isProcessing=true;
  if(n==14)
  {
    //ia.status.setText("");
    DialogFrameThread dth = new DialogFrameThread();
    dth.setParams(null, s);
    s="";
    Thread th=new Thread(dth);
    th.start();
  }
  this.updateButtonsEnabling();

ia.status.setText(s);
//  System.out.println("setStatus_RP: num="+num+" : "+s);
}
//******************************************************************************
 public void report_RP(String num, String s)
  {

  DialogFrameThread dth = new DialogFrameThread();
  dth.setParams(this,s);
  this.confirmRequirer=0;
  Thread th=new Thread(dth);
  th.start();
  }
//******************************************************************************
  public void setTimer_RP(String s)
  {
    StringTokenizer st= new StringTokenizer(s,"/");
    ia.curtime.setText(st.nextToken());
    ia.postime.setText("       "+st.nextToken());
  }
//******************************************************************************
  public void confirmOpen(String num, String s)
  {
    DialogFrameThread dth = new DialogFrameThread();
    dth.setParams(this, s);
    this.confirmRequirer = 1;
    Thread th=new Thread(dth);
    th.start();
  //System.out.println("confirmOpen: num="+num+" : "+s);
  }
//******************************************************************************
  public void confirmRecord(String num, String s)
  {
//    System.out.println("confirmRecord: num="+num+" : "+s);
    try
    {
      DialogFrameThread dth = new DialogFrameThread();
      dth.setParams(this, s);
      this.confirmRequirer = 2;
      Thread th=new Thread(dth);
      th.start();
    }
    catch(Exception ex)
    {
    System.out.println("IA: confirmRecord ex "+ex);
    }
  //System.out.println("confirmRecord: num="+num+" : "+s);
  }
//******************************************************************************
  public void setFilename(String s)
  {
//  System.out.println("setFilename> "+s);
   if(Messages.DiskVersion) ((java.awt.TextField)ia.filename).setText(s);
  }
//******************************************************************************
  public void addName(String s)
  {
    ia.addFileName(s);
  }
//******************************************************************************
  public void setRecordLevel(String s)
 {
   //System.out.println("setRecordLevel:"+s);
 }
//******************************************************************************
public void confirmReceived(Object o)
{
  //if (o==null) System.out.println("bla, null");
    Integer i = (Integer) o;
    if (this.confirmRequirer == 1)
    {
      if (i.intValue() == 1)this.open();
      else this.stop();
    }
    if (this.confirmRequirer == 2)
    {
      if (i.intValue() == 1)this.record();
      else this.stop();
    }

}
//******************************************************************************
  public void setUserServerFolder(String UserServerFolder)
  {
    this.UserServerFolder = UserServerFolder;
  }
//******************************************************************************
//******************************************************************************
//******************************************************************************
//******************************************************************************

}

⌨️ 快捷键说明

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