home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / dek17tau / classes / spt / applets / animatedimagebuttonapplet.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.2 KB  |  146 lines

  1.  
  2. /*
  3.  * AnimatedImageButtonApplet.java
  4.  *
  5.  * Copyright (C) 1996 Shaun Terry. All Rights Reserved.
  6.  */
  7.  
  8. package spt.applets;
  9.  
  10. import java.awt.Image;
  11. import java.awt.Event;
  12. import java.net.URL;
  13. import java.net.MalformedURLException;
  14. import java.applet.*;
  15.  
  16. import spt.gui.ImagePanel;
  17. import spt.gui.AnimatedImageButton;
  18. import spt.applets.ImageButtonApplet;
  19.  
  20.  
  21. /**
  22.  * A button applet that can display an animation.<p>
  23.  * <strong>Parameters</strong>
  24.  * <pre>
  25.  * ANIMATEONENTER        bool    Animate only on mouse enter (TRUE) or always (FALSE) (optional)
  26.  * INFINITELOOP        bool    Run the image indefinitely or once only? (optional)
  27.  * INTERFRAMEPAUSE        int    Interval between frames, in milliseconds (optional)
  28.  * INTERCYCLEPAUSE        int    Interval between cycles, in milliseconds (optional)
  29.  * FILEPREFIX        String    Files are of the form {prefix}XX.{extension} where XX = startnum..endnum (required)
  30.  * FILEEXTENSION        String    (see above) (required)
  31.  * FILESTARTNUM        int    (see above) (required)
  32.  * FILEENDNUM        int    (see above) (required)
  33.  * IMGSOURCEDIR        URL    The directory where the image files are (required)
  34.  * TEXT            String    A button label (optional)
  35.  *
  36.  * </pre>
  37.  * Plus ImageButtonApplet and StdApplet parameters.
  38.  *
  39.  * @see spt.applets.StdApplet
  40.  * @see spt.applets.ImageButtonApplet
  41.  * @see spt.gui.AnimatedImageButton
  42.  * @author Shaun Terry
  43.  */
  44.  
  45. public class AnimatedImageButtonApplet extends ImageButtonApplet {
  46.  
  47.     AnimatedImageButton imgButton;
  48.  
  49.     public void init() {
  50.         stdAppletInit();
  51.  
  52.         String imgsrcdir=null;
  53.         imgsrcdir = paramParser.getParameter("IMGSOURCEDIR");
  54.  
  55.         if (imgsrcdir == null) {
  56.             System.err.println("Param(IMGSOURCEDIR): Must be specified");
  57.             return;
  58.         }
  59.  
  60.         String prefix, ext;
  61.         int startNum=1, endNum=(-1);
  62.         int interframepause=(-1), intercyclepause=(-1);
  63.  
  64.         Integer ii=null;
  65.         if ((ii = paramParser.getInteger("FILEENDNUM")) == null) {
  66.             System.err.println("Param(FILEENDNUM): Must be specified");
  67.             return;
  68.         }
  69.         else endNum = ii.intValue();
  70.  
  71.         prefix = paramParser.getParameter("FILEPREFIX", "T");
  72.         ext = paramParser.getParameter("FILEEXTENSION", "gif");
  73.  
  74.         ii = paramParser.getInteger("FILESTARTNUM", 1);
  75.         startNum = ii.intValue();
  76.  
  77.         if ((ii = paramParser.getInteger("INTERFRAMEPAUSE")) != null) {
  78.             interframepause = ii.intValue();
  79.         }
  80.  
  81.         if ((ii = paramParser.getInteger("INTERCYCLEPAUSE")) != null) {
  82.             intercyclepause = ii.intValue();
  83.         }
  84.  
  85.         Image ip[] = new Image[endNum-startNum+1];
  86.  
  87.         try {
  88.             for (int i=startNum; i <= endNum; ++i) {
  89.                 URL f = new URL(getCodeBase(), imgsrcdir + "/" + prefix + i + "." + ext);
  90.                 ip[i-startNum] = ImagePanel.loadImage(this, f);
  91.             }
  92.         } catch (MalformedURLException f) {
  93.             System.err.println(f);
  94.             return;
  95.         }
  96.  
  97.         paramParser.applyFontParam();
  98.  
  99.         String text = paramParser.getParameter("TEXT");
  100.  
  101.         imgButton = new AnimatedImageButton(text);
  102.         for (int i=0; i < endNum-startNum+1; ++i) {
  103.             if (i == 0 && intercyclepause >= 0)
  104.                         imgButton.addImage(ip[i], intercyclepause);
  105.             else if (interframepause >= 0) imgButton.addImage(ip[i], interframepause);
  106.             else imgButton.addImage(ip[i]);
  107.         }
  108.  
  109.  
  110.         if (paramParser.getBoolean("INFINITELOOP", true).booleanValue()) {
  111.             imgButton.setRepeat(true);
  112.         }
  113.         else imgButton.setRepeat(false);
  114.  
  115.         super.imgButton = imgButton;
  116.  
  117.         super.setParams();
  118.  
  119.         if (paramParser.getBoolean("ANIMATEONENTER", true).booleanValue()) {
  120.             imgButton.setAnimateOnEnter(true);
  121.         }
  122.         else imgButton.setAnimateOnEnter(false);
  123.  
  124.         imgButton.startAnimation();
  125.         add(imgButton);
  126.     }
  127.  
  128.     /** Parameters */
  129.     public String[][] getParameterInfo() {
  130.         String[][] info = {
  131.             { "ANIMATEONENTER",    "boolean",     "Animate only on mouse enter (TRUE) or always (FALSE)" },
  132.             { "INFINITELOOP",    "boolean",     "Run the image indefinitely or once only?" },
  133.             { "INTERFRAMEPAUSE","int",         "Interval between frames, in milliseconds" },
  134.             { "INTERCYCLEPAUSE","int",         "Interval between cycles, in milliseconds" },
  135.             { "FILEPREFIX",        "String",     "Files are of the form {prefix}XX.{extension} where XX = startnum..endnum" },
  136.             { "FILEEXTENSION",    "String",     "(see above)" },
  137.             { "FILESTARTNUM",    "int",         "(see above)" },
  138.             { "FILEENDNUM",        "int",         "(see above)" },
  139.             { "IMGSOURCEDIR",    "URL",         "The directory where the image files are" },
  140.             { "TEXT",            "String",     "A button label" },
  141.         };
  142.  
  143.         return mergeParameters(super.getParameterInfo(), info);
  144.     }
  145. }
  146.