home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / DrawingSequence.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  6.3 KB  |  311 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8. import netscape.util.InconsistencyException;
  9.  
  10. public abstract class DrawingSequence extends Image implements Target, Codable {
  11.    DrawingSequenceOwner owner;
  12.    String name;
  13.    Timer animateTimer;
  14.    int currentFrameNumber;
  15.    int frameCount;
  16.    int frameRate;
  17.    int playbackMode;
  18.    boolean animating;
  19.    boolean resetOnStart;
  20.    boolean resetOnStop;
  21.    boolean bounceForward;
  22.    public static final int FORWARD = 0;
  23.    public static final int FORWARD_LOOP = 1;
  24.    public static final int BACKWARD = 2;
  25.    public static final int BACKWARD_LOOP = 3;
  26.    public static final int BOUNCE = 4;
  27.    static final int MIN_FRAME_RATE = 1;
  28.    static final String OWNER_KEY = "owner";
  29.    static final String NAME_KEY = "name";
  30.    static final String CURRENTFRAME_KEY = "currentFrameNumber";
  31.    static final String FRAMECOUNT_KEY = "frameCount";
  32.    static final String FRAME_RATE_KEY = "frameRate";
  33.    static final String PLAYBACKMODE_KEY = "playbackMode";
  34.    static final String ANIMATING_KEY = "animating";
  35.    static final String RESETONSTART_KEY = "resetOnStart";
  36.    static final String RESETONSTOP_KEY = "resetOnStop";
  37.    public static final String START = "start";
  38.    public static final String STOP = "stop";
  39.    public static final String NEXT_FRAME = "nextFrame";
  40.  
  41.    public DrawingSequence() {
  42.       this((DrawingSequenceOwner)null);
  43.    }
  44.  
  45.    public DrawingSequence(DrawingSequenceOwner var1) {
  46.       this.bounceForward = true;
  47.       this.owner = var1;
  48.       this.frameRate = 1;
  49.       this.playbackMode = 0;
  50.    }
  51.  
  52.    public void setOwner(DrawingSequenceOwner var1) {
  53.       this.owner = var1;
  54.    }
  55.  
  56.    public DrawingSequenceOwner owner() {
  57.       return this.owner;
  58.    }
  59.  
  60.    public void setName(String var1) {
  61.       this.name = var1;
  62.    }
  63.  
  64.    public String name() {
  65.       return this.name;
  66.    }
  67.  
  68.    public void performCommand(String var1, Object var2) {
  69.       if ("start".equals(var1)) {
  70.          this.start();
  71.       } else if ("stop".equals(var1)) {
  72.          this.stop();
  73.       } else if ("nextFrame".equals(var1)) {
  74.          this.nextFrame();
  75.       } else {
  76.          throw new NoSuchMethodError("unknown command: " + var1);
  77.       }
  78.    }
  79.  
  80.    public void start() {
  81.       if (this.resetOnStart) {
  82.          this.reset();
  83.       }
  84.  
  85.       this.animating = true;
  86.       if (this.animateTimer == null) {
  87.          if (this.owner != null) {
  88.             this.owner.drawingSequenceFrameChanged(this);
  89.          }
  90.  
  91.          this.animateTimer = new Timer(this, "nextFrame", this.frameRate);
  92.          this.animateTimer.start();
  93.       }
  94.  
  95.    }
  96.  
  97.    public boolean isAnimating() {
  98.       return this.animating;
  99.    }
  100.  
  101.    public void stop() {
  102.       this.animating = false;
  103.       if (this.animateTimer != null) {
  104.          this.animateTimer.stop();
  105.          this.animateTimer = null;
  106.       }
  107.  
  108.       if (this.resetOnStop) {
  109.          this.reset();
  110.       }
  111.  
  112.    }
  113.  
  114.    public void reset() {
  115.       if (this.playbackMode != 0 && this.playbackMode != 1 && this.playbackMode != 4) {
  116.          this.currentFrameNumber = this.frameCount - 1;
  117.       } else {
  118.          this.currentFrameNumber = 0;
  119.       }
  120.    }
  121.  
  122.    public void setFrameCount(int var1) {
  123.       if (var1 > 0) {
  124.          this.frameCount = var1;
  125.       } else {
  126.          this.frameCount = 0;
  127.       }
  128.    }
  129.  
  130.    public int frameCount() {
  131.       return this.frameCount;
  132.    }
  133.  
  134.    public void setCurrentFrameNumber(int var1) {
  135.       if (var1 < 0) {
  136.          var1 = 0;
  137.       } else if (var1 >= this.frameCount) {
  138.          var1 = this.frameCount - 1;
  139.       }
  140.  
  141.       this.currentFrameNumber = var1;
  142.    }
  143.  
  144.    public int currentFrameNumber() {
  145.       return this.currentFrameNumber;
  146.    }
  147.  
  148.    public void setFrameRate(int var1) {
  149.       if (var1 > 1) {
  150.          this.frameRate = var1;
  151.       } else {
  152.          this.frameRate = 1;
  153.       }
  154.  
  155.       if (this.animateTimer != null) {
  156.          this.animateTimer.setDelay(this.frameRate);
  157.       }
  158.  
  159.    }
  160.  
  161.    public int frameRate() {
  162.       return this.frameRate;
  163.    }
  164.  
  165.    public void setPlaybackMode(int var1) {
  166.       if (var1 >= 0 && var1 <= 4) {
  167.          this.playbackMode = var1;
  168.          this.reset();
  169.       }
  170.    }
  171.  
  172.    public int playbackMode() {
  173.       return this.playbackMode;
  174.    }
  175.  
  176.    public void setResetOnStart(boolean var1) {
  177.       this.resetOnStart = var1;
  178.    }
  179.  
  180.    public boolean doesResetOnStart() {
  181.       return this.resetOnStart;
  182.    }
  183.  
  184.    public void setResetOnStop(boolean var1) {
  185.       this.resetOnStop = var1;
  186.    }
  187.  
  188.    public boolean doesResetOnStop() {
  189.       return this.resetOnStop;
  190.    }
  191.  
  192.    public boolean doesLoop() {
  193.       return this.playbackMode == 1 || this.playbackMode == 3 || this.playbackMode == 4;
  194.    }
  195.  
  196.    public boolean nextFrame() {
  197.       boolean var1 = true;
  198.       if (this.frameCount == 0) {
  199.          this.stop();
  200.          throw new InconsistencyException("Frame count is 0");
  201.       } else {
  202.          if (this.playbackMode != 0 && this.playbackMode != 1) {
  203.             if (this.playbackMode == 4) {
  204.                var1 = true;
  205.                if (this.frameCount == 1) {
  206.                   this.currentFrameNumber = 0;
  207.                } else if (this.bounceForward) {
  208.                   ++this.currentFrameNumber;
  209.                   if (this.currentFrameNumber >= this.frameCount) {
  210.                      this.bounceForward = false;
  211.                      this.currentFrameNumber -= 2;
  212.                   }
  213.                } else if (!this.bounceForward) {
  214.                   --this.currentFrameNumber;
  215.                   if (this.currentFrameNumber < 0) {
  216.                      this.bounceForward = true;
  217.                      this.currentFrameNumber += 2;
  218.                   }
  219.                }
  220.             } else {
  221.                --this.currentFrameNumber;
  222.                if (this.currentFrameNumber < 0) {
  223.                   if (this.playbackMode != 3) {
  224.                      this.currentFrameNumber = 0;
  225.                      var1 = false;
  226.                   } else {
  227.                      this.currentFrameNumber = this.frameCount - 1;
  228.                   }
  229.                }
  230.             }
  231.          } else {
  232.             ++this.currentFrameNumber;
  233.             if (this.currentFrameNumber >= this.frameCount) {
  234.                if (this.playbackMode != 1) {
  235.                   this.currentFrameNumber = this.frameCount - 1;
  236.                   var1 = false;
  237.                } else {
  238.                   this.currentFrameNumber = 0;
  239.                }
  240.             }
  241.          }
  242.  
  243.          if (var1) {
  244.             if (this.owner != null) {
  245.                this.owner.drawingSequenceFrameChanged(this);
  246.             }
  247.  
  248.             return true;
  249.          } else {
  250.             this.stop();
  251.             if (this.owner != null) {
  252.                this.owner.drawingSequenceCompleted(this);
  253.             }
  254.  
  255.             return false;
  256.          }
  257.       }
  258.    }
  259.  
  260.    public abstract int width();
  261.  
  262.    public abstract int height();
  263.  
  264.    public abstract void drawAt(Graphics var1, int var2, int var3);
  265.  
  266.    public void describeClassInfo(ClassInfo var1) {
  267.       var1.addClass("netscape.application.DrawingSequence", 1);
  268.       var1.addField("owner", (byte)18);
  269.       var1.addField("name", (byte)16);
  270.       var1.addField("currentFrameNumber", (byte)8);
  271.       var1.addField("frameCount", (byte)8);
  272.       var1.addField("frameRate", (byte)8);
  273.       var1.addField("playbackMode", (byte)8);
  274.       var1.addField("animating", (byte)0);
  275.       var1.addField("resetOnStart", (byte)0);
  276.       var1.addField("resetOnStop", (byte)0);
  277.    }
  278.  
  279.    public void encode(Encoder var1) throws CodingException {
  280.       var1.encodeObject("owner", (Codable)this.owner);
  281.       var1.encodeString("name", this.name);
  282.       var1.encodeInt("currentFrameNumber", this.currentFrameNumber);
  283.       var1.encodeInt("frameCount", this.frameCount);
  284.       var1.encodeInt("frameRate", this.frameRate);
  285.       var1.encodeInt("playbackMode", this.playbackMode);
  286.       var1.encodeBoolean("animating", this.animating);
  287.       var1.encodeBoolean("resetOnStart", this.resetOnStart);
  288.       var1.encodeBoolean("resetOnStop", this.resetOnStop);
  289.    }
  290.  
  291.    public void decode(Decoder var1) throws CodingException {
  292.       this.owner = (DrawingSequenceOwner)var1.decodeObject("owner");
  293.       this.name = var1.decodeString("name");
  294.       this.currentFrameNumber = var1.decodeInt("currentFrameNumber");
  295.       this.frameCount = var1.decodeInt("frameCount");
  296.       this.frameRate = var1.decodeInt("frameRate");
  297.       this.playbackMode = var1.decodeInt("playbackMode");
  298.       this.animating = var1.decodeBoolean("animating");
  299.       this.resetOnStart = var1.decodeBoolean("resetOnStart");
  300.       this.resetOnStop = var1.decodeBoolean("resetOnStop");
  301.    }
  302.  
  303.    public void finishDecoding() throws CodingException {
  304.       if (this.animating) {
  305.          this.animating = false;
  306.          this.start();
  307.       }
  308.  
  309.    }
  310. }
  311.