home *** CD-ROM | disk | FTP | other *** search
Wrap
import java.applet.Applet; import java.applet.AudioClip; import java.awt.Button; import java.awt.Checkbox; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Event; import java.net.MalformedURLException; import java.net.URL; public class ClipControl extends Applet implements Runnable { int width = 260; int height = 40; String url = "http://www.cs.indiana.edu/hyplan/kinzler/fun/shr_sounds/index.html"; String[][] pinfo = new String[][]{{"clip", "URL", "audio clip"}, {"bgcolor", "color", "background color"}, {"fgcolor", "color", "foreground color"}, {"bgstatus", "string", "background status string"}, {"noplay", "boolean", "don't show play button [false]"}, {"noloop", "boolean", "don't show loop button [false]"}, {"nostop", "boolean", "don't show stop button [false]"}, {"noload", "boolean", "don't show load button [false]"}, {"boxplay", "boolean", "use a checkbox for play button [false]"}, {"boxloop", "boolean", "use a checkbox for loop button [false]"}, {"boxstop", "boolean", "use a checkbox for stop button [false]"}, {"playlabel", "string", "play button label [Play]"}, {"looplabel", "string", "loop button label [Loop]"}, {"stoplabel", "string", "stop button label [Stop]"}, {"loadlabel", "string", "load button label [Load]"}, {"nextlabel", "string", "next load button label [Reload]"}, {"nextload", "boolean", "keep load button for reloads [false]"}, {"oninit", "actions", "actions on applet initialization []"}, {"onstart", "actions", "actions on applet start []"}, {"onstop", "actions", "actions on applet stop [quitstop]"}, {"ondestroy", "actions", "actions on applet destruction [stop]"}}; String clipname; String status; String nextlabel; URL clipurl; boolean nextload = false; String oninit; String onstart; String onstop; String ondestroy; AudioClip clip; Component play; Component loop; Component stop; Component load; Event pend; Thread thrd; boolean looping = false; boolean loading = false; public String getAppletInfo() { return "ClipControl - an AudioClip control applet with play/loop/stop/load buttons\nSteve Kinzler, kinzler@cs.indiana.edu, May 96/Sep 96\n" + this.url + "\nVersion 2.0.2, see source code for license\n" + "Copyright (c) 1996 Stephen B Kinzler. All rights reserved.\n\n" + "color := hexadecimal number prefixed with '#'\n" + "action := load = reload the clip\n" + " play = play the clip, loading it first if needed\n" + " loop = loop the clip, loading it first if needed\n" + " quit = quit loading the clip\n" + " stop = stop the clip"; } public String[][] getParameterInfo() { return this.pinfo; } public synchronized void init() { Dimension var1 = ((Component)this).size(); if (var1.width > 0) { this.width = var1.width; } if (var1.height > 0) { this.height = var1.height; } ((Applet)this).resize(this.width, this.height); String var2 = ((Applet)this).getParameter("BGCOLOR"); if (var2 != null && var2.startsWith("#")) { int var3 = Integer.parseInt(var2.substring(1), 16); ((Component)this).setBackground(new Color(var3)); } var2 = ((Applet)this).getParameter("FGCOLOR"); if (var2 != null && var2.startsWith("#")) { int var12 = Integer.parseInt(var2.substring(1), 16); ((Component)this).setForeground(new Color(var12)); } var2 = ((Applet)this).getParameter("BGSTATUS"); this.status = var2 != null ? var2 : "ClipControl: click, type 'h' for home page or '?' for keys"; var2 = this.clipname = ((Applet)this).getParameter("CLIP"); try { this.clipurl = var2 != null ? new URL(((Applet)this).getDocumentBase(), var2) : null; } catch (MalformedURLException var4) { this.clipurl = null; } if (this.clipurl != null) { var2 = ((Applet)this).getParameter("NEXTLABEL"); this.nextlabel = var2 != null ? var2 : "Reload"; var2 = ((Applet)this).getParameter("NEXTLOAD"); this.nextload = var2 != null ? var2.equals("true") : false; this.play = this.makeButton(this.play, "PLAY", "Play"); this.loop = this.makeButton(this.loop, "LOOP", "Loop"); this.stop = this.makeButton(this.stop, "STOP", "Stop"); this.load = this.makeButton(this.load, "LOAD", "Load"); this.oninit = ((Applet)this).getParameter("ONINIT"); this.onstart = ((Applet)this).getParameter("ONSTART"); var2 = ((Applet)this).getParameter("ONSTOP"); this.onstop = var2 != null ? var2 : "quitstop"; var2 = ((Applet)this).getParameter("ONDESTROY"); this.ondestroy = var2 != null ? var2 : "stop"; this.doAction(this.oninit); } } synchronized Component makeButton(Component var1, String var2, String var3) { if (var1 != null) { ((Container)this).remove(var1); } String var4 = ((Applet)this).getParameter(var2 + "LABEL"); if (var4 == null) { var4 = var3; } if (var2.equalsIgnoreCase("LOAD")) { var1 = new Checkbox(this.clip == null ? var4 : this.nextlabel); this.setButton(var1, this.loading); String var9 = ((Applet)this).getParameter("NO" + var2); if ((var9 == null || !var9.equals("true")) && (this.nextload || this.clip == null)) { ((Container)this).add(var1); } return var1; } else { String var5 = ((Applet)this).getParameter("BOX" + var2); if (var5 != null && var5.equals("true")) { var1 = new Checkbox(var4); } else { var1 = new Button(var4); } this.setButton(var1, var2.equalsIgnoreCase("LOOP") ? this.looping : false); var5 = ((Applet)this).getParameter("NO" + var2); if (var5 == null || !var5.equals("true")) { ((Container)this).add(var1); } return var1; } } void setButton(Component var1, boolean var2) { if (var1 instanceof Checkbox) { ((Checkbox)var1).setState(var2); } } public void start() { this.doAction(this.onstart); } void doAction(String var1) { if (var1 != null) { String var2 = var1.toLowerCase(); if (var2.indexOf("load") >= 0) { this.quitLoad(); this.pressButton(this.load); } if (var2.indexOf("play") >= 0) { this.pressButton(this.play); } if (var2.indexOf("loop") >= 0) { if (this.loop instanceof Checkbox && this.looping) { this.pressButton(this.loop); } this.pressButton(this.loop); } if (var2.indexOf("quit") >= 0) { this.quitLoad(); } if (var2.indexOf("stop") >= 0) { this.pressButton(this.stop); } } } void pressButton(Component var1) { this.action(new Event(var1, 1001, this), this); } public boolean mouseEnter(Event var1, int var2, int var3) { ((Component)this).requestFocus(); ((Applet)this).showStatus(this.status); return true; } public boolean mouseExit(Event var1, int var2, int var3) { ((Applet)this).showStatus((String)null); return true; } public boolean keyDown(Event var1, int var2) { switch (var2) { case 63: default: ((Applet)this).showStatus("(h)ome (p)lay (l)oop (s)top (r)eload (q)uit loading"); break; case 72: case 104: this.toHome(); break; case 76: case 108: this.doAction("loop"); break; case 80: case 112: this.doAction("play"); break; case 81: case 113: this.doAction("quit"); break; case 82: case 114: this.doAction("load"); break; case 83: case 115: this.doAction("stop"); } return true; } void toHome() { try { ((Applet)this).getAppletContext().showDocument(new URL(this.url)); } catch (MalformedURLException var1) { ((Applet)this).showStatus("Ignoring Malformed Home URL"); } } public synchronized boolean action(Event var1, Object var2) { if (var1.target == null) { return true; } else { if (var1.target.equals(this.play)) { this.setButton(this.play, true); if (!this.getClip(var1)) { ((Applet)this).showStatus("Playing " + this.clipname); this.clip.play(); } this.setButton(this.play, false); } else if (var1.target.equals(this.loop)) { if (this.loop instanceof Checkbox && this.looping) { ((Applet)this).showStatus("Stopping " + this.clipname); this.clip.stop(); this.looping = false; this.setButton(this.loop, false); return true; } this.setButton(this.loop, true); if (!this.getClip(var1)) { this.looping = true; ((Applet)this).showStatus("Looping " + this.clipname); this.clip.loop(); } else { this.setButton(this.loop, false); } } else if (var1.target.equals(this.stop)) { this.setButton(this.stop, true); if (this.clip != null) { ((Applet)this).showStatus("Stopping " + this.clipname); this.clip.stop(); if (this.looping) { this.setButton(this.loop, false); } } this.pend = null; this.looping = false; this.setButton(this.stop, false); } else if (var1.target.equals(this.load)) { if (this.loading) { this.quitLoad(); } else { this.getClip((Event)null); } } return true; } } synchronized boolean getClip(Event var1) { if (var1 != null && this.clip != null) { return false; } else { if (var1 == null) { this.quitLoad(); } if (this.loading) { this.pend = var1; ((Applet)this).showStatus("Still loading " + this.clipname); return true; } else { this.loading = true; this.setButton(this.load, true); ((Applet)this).showStatus("Loading " + this.clipname); if (var1 != null) { this.pend = var1; } this.thrd = new Thread(this); this.thrd.start(); return true; } } } public void run() { AudioClip var1 = ((Applet)this).getAudioClip(this.clipurl); synchronized(this){} try { if (this.clip != null) { this.doAction("stop"); } this.clip = var1; Object var5 = null; this.loading = false; ((Applet)this).showStatus("Loaded " + this.clipname); if (!this.nextload) { ((Container)this).remove(this.load); } ((Checkbox)this.load).setLabel(this.nextlabel); this.setButton(this.load, false); if (this.pend != null) { this.action(this.pend, this); } this.pend = null; this.thrd = null; } catch (Throwable var4) { throw var4; } } synchronized void quitLoad() { if (this.thrd != null) { this.thrd.stop(); ((Applet)this).showStatus("Quit loading " + this.clipname); } this.loading = false; this.pend = null; this.thrd = null; this.setButton(this.load, false); } public void stop() { this.doAction(this.onstop); } public void destroy() { this.doAction(this.ondestroy); this.quitLoad(); } }