home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
- import netscape.util.InconsistencyException;
-
- public abstract class DrawingSequence extends Image implements Target, Codable {
- DrawingSequenceOwner owner;
- String name;
- Timer animateTimer;
- int currentFrameNumber;
- int frameCount;
- int frameRate;
- int playbackMode;
- boolean animating;
- boolean resetOnStart;
- boolean resetOnStop;
- boolean bounceForward;
- public static final int FORWARD = 0;
- public static final int FORWARD_LOOP = 1;
- public static final int BACKWARD = 2;
- public static final int BACKWARD_LOOP = 3;
- public static final int BOUNCE = 4;
- static final int MIN_FRAME_RATE = 1;
- static final String OWNER_KEY = "owner";
- static final String NAME_KEY = "name";
- static final String CURRENTFRAME_KEY = "currentFrameNumber";
- static final String FRAMECOUNT_KEY = "frameCount";
- static final String FRAME_RATE_KEY = "frameRate";
- static final String PLAYBACKMODE_KEY = "playbackMode";
- static final String ANIMATING_KEY = "animating";
- static final String RESETONSTART_KEY = "resetOnStart";
- static final String RESETONSTOP_KEY = "resetOnStop";
- public static final String START = "start";
- public static final String STOP = "stop";
- public static final String NEXT_FRAME = "nextFrame";
-
- public DrawingSequence() {
- this((DrawingSequenceOwner)null);
- }
-
- public DrawingSequence(DrawingSequenceOwner var1) {
- this.bounceForward = true;
- this.owner = var1;
- this.frameRate = 1;
- this.playbackMode = 0;
- }
-
- public void setOwner(DrawingSequenceOwner var1) {
- this.owner = var1;
- }
-
- public DrawingSequenceOwner owner() {
- return this.owner;
- }
-
- public void setName(String var1) {
- this.name = var1;
- }
-
- public String name() {
- return this.name;
- }
-
- public void performCommand(String var1, Object var2) {
- if ("start".equals(var1)) {
- this.start();
- } else if ("stop".equals(var1)) {
- this.stop();
- } else if ("nextFrame".equals(var1)) {
- this.nextFrame();
- } else {
- throw new NoSuchMethodError("unknown command: " + var1);
- }
- }
-
- public void start() {
- if (this.resetOnStart) {
- this.reset();
- }
-
- this.animating = true;
- if (this.animateTimer == null) {
- if (this.owner != null) {
- this.owner.drawingSequenceFrameChanged(this);
- }
-
- this.animateTimer = new Timer(this, "nextFrame", this.frameRate);
- this.animateTimer.start();
- }
-
- }
-
- public boolean isAnimating() {
- return this.animating;
- }
-
- public void stop() {
- this.animating = false;
- if (this.animateTimer != null) {
- this.animateTimer.stop();
- this.animateTimer = null;
- }
-
- if (this.resetOnStop) {
- this.reset();
- }
-
- }
-
- public void reset() {
- if (this.playbackMode != 0 && this.playbackMode != 1 && this.playbackMode != 4) {
- this.currentFrameNumber = this.frameCount - 1;
- } else {
- this.currentFrameNumber = 0;
- }
- }
-
- public void setFrameCount(int var1) {
- if (var1 > 0) {
- this.frameCount = var1;
- } else {
- this.frameCount = 0;
- }
- }
-
- public int frameCount() {
- return this.frameCount;
- }
-
- public void setCurrentFrameNumber(int var1) {
- if (var1 < 0) {
- var1 = 0;
- } else if (var1 >= this.frameCount) {
- var1 = this.frameCount - 1;
- }
-
- this.currentFrameNumber = var1;
- }
-
- public int currentFrameNumber() {
- return this.currentFrameNumber;
- }
-
- public void setFrameRate(int var1) {
- if (var1 > 1) {
- this.frameRate = var1;
- } else {
- this.frameRate = 1;
- }
-
- if (this.animateTimer != null) {
- this.animateTimer.setDelay(this.frameRate);
- }
-
- }
-
- public int frameRate() {
- return this.frameRate;
- }
-
- public void setPlaybackMode(int var1) {
- if (var1 >= 0 && var1 <= 4) {
- this.playbackMode = var1;
- this.reset();
- }
- }
-
- public int playbackMode() {
- return this.playbackMode;
- }
-
- public void setResetOnStart(boolean var1) {
- this.resetOnStart = var1;
- }
-
- public boolean doesResetOnStart() {
- return this.resetOnStart;
- }
-
- public void setResetOnStop(boolean var1) {
- this.resetOnStop = var1;
- }
-
- public boolean doesResetOnStop() {
- return this.resetOnStop;
- }
-
- public boolean doesLoop() {
- return this.playbackMode == 1 || this.playbackMode == 3 || this.playbackMode == 4;
- }
-
- public boolean nextFrame() {
- boolean var1 = true;
- if (this.frameCount == 0) {
- this.stop();
- throw new InconsistencyException("Frame count is 0");
- } else {
- if (this.playbackMode != 0 && this.playbackMode != 1) {
- if (this.playbackMode == 4) {
- var1 = true;
- if (this.frameCount == 1) {
- this.currentFrameNumber = 0;
- } else if (this.bounceForward) {
- ++this.currentFrameNumber;
- if (this.currentFrameNumber >= this.frameCount) {
- this.bounceForward = false;
- this.currentFrameNumber -= 2;
- }
- } else if (!this.bounceForward) {
- --this.currentFrameNumber;
- if (this.currentFrameNumber < 0) {
- this.bounceForward = true;
- this.currentFrameNumber += 2;
- }
- }
- } else {
- --this.currentFrameNumber;
- if (this.currentFrameNumber < 0) {
- if (this.playbackMode != 3) {
- this.currentFrameNumber = 0;
- var1 = false;
- } else {
- this.currentFrameNumber = this.frameCount - 1;
- }
- }
- }
- } else {
- ++this.currentFrameNumber;
- if (this.currentFrameNumber >= this.frameCount) {
- if (this.playbackMode != 1) {
- this.currentFrameNumber = this.frameCount - 1;
- var1 = false;
- } else {
- this.currentFrameNumber = 0;
- }
- }
- }
-
- if (var1) {
- if (this.owner != null) {
- this.owner.drawingSequenceFrameChanged(this);
- }
-
- return true;
- } else {
- this.stop();
- if (this.owner != null) {
- this.owner.drawingSequenceCompleted(this);
- }
-
- return false;
- }
- }
- }
-
- public abstract int width();
-
- public abstract int height();
-
- public abstract void drawAt(Graphics var1, int var2, int var3);
-
- public void describeClassInfo(ClassInfo var1) {
- var1.addClass("netscape.application.DrawingSequence", 1);
- var1.addField("owner", (byte)18);
- var1.addField("name", (byte)16);
- var1.addField("currentFrameNumber", (byte)8);
- var1.addField("frameCount", (byte)8);
- var1.addField("frameRate", (byte)8);
- var1.addField("playbackMode", (byte)8);
- var1.addField("animating", (byte)0);
- var1.addField("resetOnStart", (byte)0);
- var1.addField("resetOnStop", (byte)0);
- }
-
- public void encode(Encoder var1) throws CodingException {
- var1.encodeObject("owner", (Codable)this.owner);
- var1.encodeString("name", this.name);
- var1.encodeInt("currentFrameNumber", this.currentFrameNumber);
- var1.encodeInt("frameCount", this.frameCount);
- var1.encodeInt("frameRate", this.frameRate);
- var1.encodeInt("playbackMode", this.playbackMode);
- var1.encodeBoolean("animating", this.animating);
- var1.encodeBoolean("resetOnStart", this.resetOnStart);
- var1.encodeBoolean("resetOnStop", this.resetOnStop);
- }
-
- public void decode(Decoder var1) throws CodingException {
- this.owner = (DrawingSequenceOwner)var1.decodeObject("owner");
- this.name = var1.decodeString("name");
- this.currentFrameNumber = var1.decodeInt("currentFrameNumber");
- this.frameCount = var1.decodeInt("frameCount");
- this.frameRate = var1.decodeInt("frameRate");
- this.playbackMode = var1.decodeInt("playbackMode");
- this.animating = var1.decodeBoolean("animating");
- this.resetOnStart = var1.decodeBoolean("resetOnStart");
- this.resetOnStop = var1.decodeBoolean("resetOnStop");
- }
-
- public void finishDecoding() throws CodingException {
- if (this.animating) {
- this.animating = false;
- this.start();
- }
-
- }
- }
-