View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.IOException;
5   import java.util.Vector;
6   
7   /**
8    * DefineSprite TAG.
9    * 
10   * @author Mark Donszelmann
11   * @author Charles Loomis
12   * @version $Id: DefineSprite.java 8584 2006-08-10 23:06:37Z duns $
13   */
14  public class DefineSprite extends DefinitionTag {
15  
16      private int character;
17  
18      private int frameCount;
19  
20      private Vector tags;
21  
22      public DefineSprite(int id, int frameCount, Vector tags) {
23          this();
24          character = id;
25          this.frameCount = frameCount;
26          this.tags = tags;
27      }
28  
29      public DefineSprite() {
30          super(39, 3);
31      }
32  
33      public SWFTag read(int tagID, SWFInputStream swf, int len)
34              throws IOException {
35  
36          DefineSprite tag = new DefineSprite();
37          tag.character = swf.readUnsignedShort();
38          swf.getDictionary().put(tag.character, tag);
39  
40          tag.frameCount = swf.readUnsignedShort();
41  
42          int version = swf.getVersion();
43          SWFInputStream sprite = new SWFInputStream(swf, new SWFSpriteTagSet(
44                  version), new SWFActionSet(version));
45  
46          tag.tags = new Vector();
47          SWFTag miniTag;
48          do {
49              miniTag = (SWFTag) sprite.readTag();
50              tag.tags.add(miniTag);
51          } while (!(miniTag instanceof End));
52  
53          return tag;
54      }
55  
56      public void write(int tagID, SWFOutputStream swf) throws IOException {
57          swf.writeUnsignedShort(character);
58          swf.writeUnsignedShort(frameCount);
59          for (int i = 0; i < tags.size(); i++) {
60              swf.writeTag((SWFTag) tags.get(i));
61          }
62      }
63  
64      public String toString() {
65          StringBuffer s = new StringBuffer();
66          s.append(super.toString() + "\n");
67          s.append("  character:  " + character + "\n");
68          s.append("  frameCount: " + frameCount + "\n");
69          s.append("  tags:       " + tags.size() + "\n");
70          return s.toString();
71      }
72  }