View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.EOFException;
5   import java.io.IOException;
6   
7   /**
8    * DefineButtonSound TAG.
9    * 
10   * @author Mark Donszelmann
11   * @author Charles Loomis
12   * @version $Id: DefineButtonSound.java 8584 2006-08-10 23:06:37Z duns $
13   */
14  public class DefineButtonSound extends DefinitionTag {
15  
16      private int character;
17  
18      private int[] soundID;
19  
20      private SoundInfo[] info;
21  
22      public DefineButtonSound(int id, int[] soundID, SoundInfo[] info) {
23          this();
24          character = id;
25          this.soundID = soundID;
26          this.info = info;
27      }
28  
29      public DefineButtonSound() {
30          super(17, 2);
31      }
32  
33      public SWFTag read(int tagID, SWFInputStream swf, int len)
34              throws IOException {
35  
36          DefineButtonSound tag = new DefineButtonSound();
37          tag.character = swf.readUnsignedShort();
38          swf.getDictionary().put(tag.character, tag);
39          tag.soundID = new int[4];
40          tag.info = new SoundInfo[4];
41          try {
42              for (int i = 0; i < 4; i++) {
43                  tag.soundID[i] = swf.readUnsignedShort();
44                  tag.info[i] = new SoundInfo(swf);
45              }
46          } catch (EOFException e) { /* seems not always 4 are filled */
47          }
48          return tag;
49      }
50  
51      public void write(int tagID, SWFOutputStream swf) throws IOException {
52  
53          swf.writeUnsignedShort(character);
54          for (int i = 0; i < 4; i++) {
55              swf.writeUnsignedShort(soundID[i]);
56              if (info[i] != null)
57                  info[i].write(swf);
58              else
59                  swf.writeUnsignedByte(0);
60          }
61      }
62  
63      public String toString() {
64          StringBuffer s = new StringBuffer();
65          s.append(super.toString() + "\n");
66          s.append("  character:  " + character + "\n");
67          for (int i = 0; i < soundID.length; i++) {
68              s.append("  ");
69              s.append(soundID[i]);
70              s.append(": ");
71              s.append(info[i]);
72              s.append("\n");
73          }
74          return s.toString();
75      }
76  }