home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 December / PCO1296.ISO / filesbbs / frei / clip.arj / CLIP.EXE / ClipControl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-06-09  |  6.4 KB  |  250 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Button;
  4. import java.awt.Checkbox;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Dimension;
  9. import java.awt.Event;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12.  
  13. public class ClipControl extends Applet implements Runnable {
  14.    int width = 260;
  15.    int height = 40;
  16.    String url = "http://www.cs.indiana.edu/hyplan/kinzler/fun/shr_sounds/index.html";
  17.    String clipname;
  18.    URL clipurl;
  19.    boolean backload = false;
  20.    boolean backplay = false;
  21.    AudioClip clip;
  22.    Button play;
  23.    Button loop;
  24.    Button stop;
  25.    Checkbox load;
  26.    Event pend;
  27.    Thread thrd;
  28.    boolean loading = false;
  29.    String[][] pinfo = new String[][]{{"clip", "URL", "audio clip"}, {"bgcolor", "color", "background color"}, {"fgcolor", "color", "foreground color"}, {"playlabel", "string", "play button label [Play]"}, {"looplabel", "string", "loop button label [Loop]"}, {"stoplabel", "string", "stop button label [Stop]"}, {"loadlabel", "string", "load button label [Load]"}, {"noload", "boolean", "don't show load button [false]"}, {"preload", "boolean", "load clip at start [false]"}, {"preplay", "boolean", "play clip at start [false]"}, {"preloop", "boolean", "loop clip at start [false]"}, {"backload", "boolean", "keep loading on applet stop [false]"}, {"backplay", "boolean", "keep playing on applet stop [false]"}};
  30.  
  31.    public String getAppletInfo() {
  32.       return "ClipControl - a AudioClip control applet with play/loop/stop/load buttons\nSteve Kinzler, kinzler@cs.indiana.edu, May 96\n" + this.url + "\nVersion 1.1.0";
  33.    }
  34.  
  35.    public String[][] getParameterInfo() {
  36.       return this.pinfo;
  37.    }
  38.  
  39.    public synchronized void init() {
  40.       Dimension var1 = ((Component)this).size();
  41.       if (var1.width > 0) {
  42.          this.width = var1.width;
  43.       }
  44.  
  45.       if (var1.height > 0) {
  46.          this.height = var1.height;
  47.       }
  48.  
  49.       ((Applet)this).resize(this.width, this.height);
  50.       String var2 = ((Applet)this).getParameter("BGCOLOR");
  51.       if (var2 != null && var2.startsWith("#")) {
  52.          int var3 = Integer.parseInt(var2.substring(1), 16);
  53.          ((Component)this).setBackground(new Color(var3));
  54.       }
  55.  
  56.       var2 = ((Applet)this).getParameter("FGCOLOR");
  57.       if (var2 != null && var2.startsWith("#")) {
  58.          int var14 = Integer.parseInt(var2.substring(1), 16);
  59.          ((Component)this).setForeground(new Color(var14));
  60.       }
  61.  
  62.       var2 = this.clipname = ((Applet)this).getParameter("CLIP");
  63.  
  64.       try {
  65.          this.clipurl = var2 != null ? new URL(((Applet)this).getDocumentBase(), var2) : null;
  66.       } catch (MalformedURLException var4) {
  67.          this.clipurl = null;
  68.       }
  69.  
  70.       if (this.clipurl != null) {
  71.          var2 = ((Applet)this).getParameter("PLAYLABEL");
  72.          if (this.play != null) {
  73.             ((Container)this).remove(this.play);
  74.          }
  75.  
  76.          this.play = new Button(var2 != null ? var2 : "Play");
  77.          ((Container)this).add(this.play);
  78.          var2 = ((Applet)this).getParameter("LOOPLABEL");
  79.          if (this.loop != null) {
  80.             ((Container)this).remove(this.loop);
  81.          }
  82.  
  83.          this.loop = new Button(var2 != null ? var2 : "Loop");
  84.          ((Container)this).add(this.loop);
  85.          var2 = ((Applet)this).getParameter("STOPLABEL");
  86.          if (this.stop != null) {
  87.             ((Container)this).remove(this.stop);
  88.          }
  89.  
  90.          this.stop = new Button(var2 != null ? var2 : "Stop");
  91.          ((Container)this).add(this.stop);
  92.          var2 = ((Applet)this).getParameter("LOADLABEL");
  93.          if (this.load != null) {
  94.             ((Container)this).remove(this.load);
  95.          }
  96.  
  97.          this.load = new Checkbox(var2 != null ? var2 : "Load");
  98.          if (this.loading) {
  99.             this.load.setState(true);
  100.          }
  101.  
  102.          var2 = ((Applet)this).getParameter("NOLOAD");
  103.          if (this.clip == null && (var2 == null || !var2.equals("true") || false)) {
  104.             ((Container)this).add(this.load);
  105.          }
  106.  
  107.          var2 = ((Applet)this).getParameter("BACKLOAD");
  108.          this.backload = var2 != null ? var2.equals("true") : false;
  109.          var2 = ((Applet)this).getParameter("BACKPLAY");
  110.          this.backplay = var2 != null ? var2.equals("true") : false;
  111.          this.preAction("PRELOAD", this.load);
  112.          this.preAction("PRELOOP", this.loop);
  113.          this.preAction("PREPLAY", this.play);
  114.       }
  115.    }
  116.  
  117.    void preAction(String var1, Component var2) {
  118.       String var3 = ((Applet)this).getParameter(var1);
  119.       if (var3 != null && var3.equals("true") && true) {
  120.          this.action(new Event(var2, 1001, this), this);
  121.       }
  122.    }
  123.  
  124.    public boolean mouseEnter(Event var1, int var2, int var3) {
  125.       ((Applet)this).showStatus(this.url);
  126.       return true;
  127.    }
  128.  
  129.    public boolean mouseExit(Event var1, int var2, int var3) {
  130.       ((Applet)this).showStatus((String)null);
  131.       return true;
  132.    }
  133.  
  134.    public boolean mouseUp(Event var1, int var2, int var3) {
  135.       if (this.url != null) {
  136.          try {
  137.             ((Applet)this).getAppletContext().showDocument(new URL(this.url));
  138.          } catch (MalformedURLException var4) {
  139.             this.url = null;
  140.             ((Applet)this).showStatus("Ignoring Malformed Home URL");
  141.          }
  142.       }
  143.  
  144.       return true;
  145.    }
  146.  
  147.    public synchronized boolean keyDown(Event var1, int var2) {
  148.       if (this.clip != null) {
  149.          this.clip.stop();
  150.       }
  151.  
  152.       if (this.thrd != null) {
  153.          this.thrd.stop();
  154.       }
  155.  
  156.       this.load.setState(false);
  157.       this.clip = null;
  158.       this.pend = null;
  159.       this.thrd = null;
  160.       this.loading = false;
  161.       this.getClip((Event)null);
  162.       return true;
  163.    }
  164.  
  165.    public boolean action(Event var1, Object var2) {
  166.       if (var1.target == null) {
  167.          return true;
  168.       } else {
  169.          if (var1.target.equals(this.play)) {
  170.             if (!this.getClip(var1)) {
  171.                ((Applet)this).showStatus("Playing " + this.clipname);
  172.                this.clip.play();
  173.             }
  174.          } else if (var1.target.equals(this.loop)) {
  175.             if (!this.getClip(var1)) {
  176.                ((Applet)this).showStatus("Looping " + this.clipname);
  177.                this.clip.loop();
  178.             }
  179.          } else if (var1.target.equals(this.stop)) {
  180.             this.pend = null;
  181.             if (this.clip != null) {
  182.                ((Applet)this).showStatus("Stopping " + this.clipname);
  183.                this.clip.stop();
  184.             }
  185.          } else if (var1.target.equals(this.load)) {
  186.             this.getClip((Event)null);
  187.          }
  188.  
  189.          return true;
  190.       }
  191.    }
  192.  
  193.    synchronized boolean getClip(Event var1) {
  194.       this.load.setState(true);
  195.       if (!this.loading) {
  196.          this.loading = true;
  197.          if (this.clip == null) {
  198.             ((Applet)this).showStatus("Loading " + this.clipname);
  199.             if (var1 != null) {
  200.                this.pend = var1;
  201.             }
  202.  
  203.             this.thrd = new Thread(this);
  204.             this.thrd.start();
  205.             return true;
  206.          }
  207.       }
  208.  
  209.       if (this.clip == null) {
  210.          if (var1 != null) {
  211.             this.pend = var1;
  212.          }
  213.  
  214.          ((Applet)this).showStatus("Still loading " + this.clipname);
  215.          return true;
  216.       } else {
  217.          return false;
  218.       }
  219.    }
  220.  
  221.    public void run() {
  222.       this.clip = ((Applet)this).getAudioClip(this.clipurl);
  223.       ((Applet)this).showStatus("Loaded " + this.clipname);
  224.       ((Container)this).remove(this.load);
  225.       ((Component)this).repaint();
  226.       if (this.pend != null) {
  227.          this.action(this.pend, this);
  228.       }
  229.  
  230.       this.pend = null;
  231.       this.thrd = null;
  232.    }
  233.  
  234.    public synchronized void stop() {
  235.       if (this.clip != null && !this.backplay) {
  236.          this.clip.stop();
  237.       }
  238.  
  239.       if (this.thrd != null && !this.backload) {
  240.          this.thrd.stop();
  241.          this.load.setState(false);
  242.          this.clip = null;
  243.          this.pend = null;
  244.          this.thrd = null;
  245.          this.loading = false;
  246.       }
  247.  
  248.    }
  249. }
  250.