/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* -Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* -Redistribution in binary form must reproduct the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
* IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed, licensed or intended for
* use in the design, construction, operation or maintenance of any nuclear
* facility.
*/
/*
* @(#)Animator.java 1.9 03/01/23
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
* An applet that plays a sequence of images, as a loop or a one-shot.
* Can have a soundtrack and/or sound effects tied to individual frames.
* See the <a href="http://java.sun.com/applets/applets/Animator/">Animator
* home page</a> for details and updates.
*
* @author Herb Jellinek
* @version 1.9, 01/23/03
*/
public class Animator extends Applet implements Runnable, MouseListener {
int appWidth = 0; // Animator width
int appHeight = 0; // Animator height
Thread engine = null; // Thread animating the images
boolean userPause = false; // True if thread currently paused by user
boolean loaded = false; // Can we paint yet?
boolean error = false; // Was there an initialization error?
Animation animation = null; // Animation this animator contains
String hrefTarget = null; // Frame target of reference URL if any
URL hrefURL = null; // URL link for information if any
static final String sourceLocation =
"http://java.sun.com/applets/applets/Animator/";
static final String userInstructions = "shift-click for errors, info";
static final int STARTUP_ID = 0;
static final int BACKGROUND_ID = 1;
static final int ANIMATION_ID = 2;
/**
* Applet info.
*/
public String getAppletInfo() {
return "Animator v1.10 (02/05/97), by Herb Jellinek";
}
/**
* Parameter info.
*/
public String[][] getParameterInfo() {
String[][] info = {
{"imagesource", "URL", "a directory"},
{"startup", "URL", "image displayed at start-up"},
{"backgroundcolor", "int", "background color (24-bit RGB number)"},
{"background", "URL", "image displayed as background"},
{"startimage", "int", "index of first image"},
{"endimage", "int", "index of last image"},
{"namepattern", "URL", "generates indexed names"},
{"images", "URLs", "list of image indices"},
{"href", "URL", "page to visit on mouse-click"},
{"target", "name", "frame to put that page in"},
{"pause", "int", "global pause, milliseconds"},
{"pauses", "ints", "individual pauses, milliseconds"},
{"repeat", "boolean", "repeat? true or false"},
{"positions", "coordinates", "path images will follow"},
{"soundsource", "URL", "audio directory"},
{"soundtrack", "URL", "background music"},
{"sounds", "URLs", "list of audio samples"},
};
return info;
}
/**
* Show a crude "About" box. Displays credits, errors (if any), and
* parameter values and documentation.
*/
void showDescription() {
DescriptionFrame description = new DescriptionFrame();
description.tell("\t\t"+getAppletInfo()+"\n");
description.tell("Updates, documentation at "+sourceLocation+"\n\n");
description.tell("Document base: "+getDocumentBase()+"\n");
description.tell("Code base: "+getCodeBase()+"\n\n");
Object errors[] = animation.tracker.getErrorsAny();
if (errors != null) {
description.tell("Applet image errors:\n");
for (int i = 0; i < errors.length; i++) {
if (errors[i] instanceof Image) {
AnimationFrame frame = (AnimationFrame)
animation.frames.get(i);
URL url = frame.imageLocation;
if (url != null) {
description.tell(" "+url+" not loaded\n");
}
}
}
description.tell("\n");
}
if (animation.frames == null || animation.frames.size() == 0)
description.tell("\n** No images loaded **\n\n");
description.tell("Applet parameters:\n");
description.tell(" width = "+getParameter("WIDTH")+"\n");
description.tell(" height = "+getParameter("HEIGHT")+"\n");
String params[][] = getParameterInfo();
for (int i = 0; i < params.length; i++) {
String name = params[i][0];
description.tell(" "+name+" = "+getParameter(name)+
"\t ["+params[i][2]+"]\n");
}
description.show();
}
/**
* Local version of getParameter for debugging purposes.
*/
public String getParam(String key) {
String result = getParameter(key);
return result;
}
/**
* Get parameters and parse them
*/
public void handleParams() {
try {
String param = getParam("IMAGESOURCE");
animation.imageSource = (param == null) ? getDocumentBase() :
new URL(getDocumentBase(), param + "/");
String href = getParam("HREF");
if (href != null) {
try {
hrefURL = new URL(getDocumentBase(), href);
} catch (MalformedURLException e) {
showParseError(e);
}
}
hrefTarget = getParam("TARGET");
if (hrefTarget == null)
hrefTarget = "_top";
param = getParam("PAUSE");
if (param != null)
animation.setGlobalPause(Integer.parseInt(param));
param = getParam("REPEAT");
animation.repeat = (param == null) ? true :
(param.equalsIgnoreCase("yes") ||
param.equalsIgnoreCase("true"));
int startImage = 1;
int endImage = 1;
param = getParam("ENDIMAGE");
if (param != null) {
endImage = Integer.parseInt(param);
param = getParam("STARTIMAGE");
if (param != null) {
startImage = Integer.parseInt(param);
}
param = getParam("NAMEPATTERN");
animation.prepareImageRange(startImage, endImage, param);
} else {
param = getParam("STARTIMAGE");
if (param != null) {
startImage = Integer.parseInt(param);
param = getParam("NAMEPATTERN");
animation.prepareImageRange(startImage, endImage, param);
} else {
param = getParam("IMAGES");
if (p