home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.2 KB | 146 lines |
-
- /*
- * AnimatedImageButtonApplet.java
- *
- * Copyright (C) 1996 Shaun Terry. All Rights Reserved.
- */
-
- package spt.applets;
-
- import java.awt.Image;
- import java.awt.Event;
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.applet.*;
-
- import spt.gui.ImagePanel;
- import spt.gui.AnimatedImageButton;
- import spt.applets.ImageButtonApplet;
-
-
- /**
- * A button applet that can display an animation.<p>
- * <strong>Parameters</strong>
- * <pre>
- * ANIMATEONENTER bool Animate only on mouse enter (TRUE) or always (FALSE) (optional)
- * INFINITELOOP bool Run the image indefinitely or once only? (optional)
- * INTERFRAMEPAUSE int Interval between frames, in milliseconds (optional)
- * INTERCYCLEPAUSE int Interval between cycles, in milliseconds (optional)
- * FILEPREFIX String Files are of the form {prefix}XX.{extension} where XX = startnum..endnum (required)
- * FILEEXTENSION String (see above) (required)
- * FILESTARTNUM int (see above) (required)
- * FILEENDNUM int (see above) (required)
- * IMGSOURCEDIR URL The directory where the image files are (required)
- * TEXT String A button label (optional)
- *
- * </pre>
- * Plus ImageButtonApplet and StdApplet parameters.
- *
- * @see spt.applets.StdApplet
- * @see spt.applets.ImageButtonApplet
- * @see spt.gui.AnimatedImageButton
- * @author Shaun Terry
- */
-
- public class AnimatedImageButtonApplet extends ImageButtonApplet {
-
- AnimatedImageButton imgButton;
-
- public void init() {
- stdAppletInit();
-
- String imgsrcdir=null;
- imgsrcdir = paramParser.getParameter("IMGSOURCEDIR");
-
- if (imgsrcdir == null) {
- System.err.println("Param(IMGSOURCEDIR): Must be specified");
- return;
- }
-
- String prefix, ext;
- int startNum=1, endNum=(-1);
- int interframepause=(-1), intercyclepause=(-1);
-
- Integer ii=null;
- if ((ii = paramParser.getInteger("FILEENDNUM")) == null) {
- System.err.println("Param(FILEENDNUM): Must be specified");
- return;
- }
- else endNum = ii.intValue();
-
- prefix = paramParser.getParameter("FILEPREFIX", "T");
- ext = paramParser.getParameter("FILEEXTENSION", "gif");
-
- ii = paramParser.getInteger("FILESTARTNUM", 1);
- startNum = ii.intValue();
-
- if ((ii = paramParser.getInteger("INTERFRAMEPAUSE")) != null) {
- interframepause = ii.intValue();
- }
-
- if ((ii = paramParser.getInteger("INTERCYCLEPAUSE")) != null) {
- intercyclepause = ii.intValue();
- }
-
- Image ip[] = new Image[endNum-startNum+1];
-
- try {
- for (int i=startNum; i <= endNum; ++i) {
- URL f = new URL(getCodeBase(), imgsrcdir + "/" + prefix + i + "." + ext);
- ip[i-startNum] = ImagePanel.loadImage(this, f);
- }
- } catch (MalformedURLException f) {
- System.err.println(f);
- return;
- }
-
- paramParser.applyFontParam();
-
- String text = paramParser.getParameter("TEXT");
-
- imgButton = new AnimatedImageButton(text);
- for (int i=0; i < endNum-startNum+1; ++i) {
- if (i == 0 && intercyclepause >= 0)
- imgButton.addImage(ip[i], intercyclepause);
- else if (interframepause >= 0) imgButton.addImage(ip[i], interframepause);
- else imgButton.addImage(ip[i]);
- }
-
-
- if (paramParser.getBoolean("INFINITELOOP", true).booleanValue()) {
- imgButton.setRepeat(true);
- }
- else imgButton.setRepeat(false);
-
- super.imgButton = imgButton;
-
- super.setParams();
-
- if (paramParser.getBoolean("ANIMATEONENTER", true).booleanValue()) {
- imgButton.setAnimateOnEnter(true);
- }
- else imgButton.setAnimateOnEnter(false);
-
- imgButton.startAnimation();
- add(imgButton);
- }
-
- /** Parameters */
- public String[][] getParameterInfo() {
- String[][] info = {
- { "ANIMATEONENTER", "boolean", "Animate only on mouse enter (TRUE) or always (FALSE)" },
- { "INFINITELOOP", "boolean", "Run the image indefinitely or once only?" },
- { "INTERFRAMEPAUSE","int", "Interval between frames, in milliseconds" },
- { "INTERCYCLEPAUSE","int", "Interval between cycles, in milliseconds" },
- { "FILEPREFIX", "String", "Files are of the form {prefix}XX.{extension} where XX = startnum..endnum" },
- { "FILEEXTENSION", "String", "(see above)" },
- { "FILESTARTNUM", "int", "(see above)" },
- { "FILEENDNUM", "int", "(see above)" },
- { "IMGSOURCEDIR", "URL", "The directory where the image files are" },
- { "TEXT", "String", "A button label" },
- };
-
- return mergeParameters(super.getParameterInfo(), info);
- }
- }
-