View Javadoc

1   // Copyright 2003, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.IOException;
5   import java.util.Vector;
6   
7   /**
8    * SWF Clip Action Record
9    * 
10   * @author Mark Donszelmann
11   * @author Charles Loomis
12   * @version $Id: ClipActionRecord.java 8584 2006-08-10 23:06:37Z duns $
13   */
14  public class ClipActionRecord {
15  
16      private ClipEventFlags eventFlags;
17  
18      private long actionRecordSize;
19  
20      private int keyCode;
21  
22      private Vector actions;
23  
24      /**
25       * Read a ClipActionRecord from the stream.
26       */
27      public ClipActionRecord(SWFInputStream swf) throws IOException {
28  
29          eventFlags = new ClipEventFlags(swf);
30          if (eventFlags.isEndFlag())
31              return;
32  
33          actionRecordSize = swf.readUnsignedInt();
34          // FIXME is actually a long (unsigned int)
35          swf.pushBuffer((int) (actionRecordSize - 4));
36          if (eventFlags.isKeyPress())
37              keyCode = swf.readUnsignedByte();
38  
39          while (swf.getLength() > 0) {
40              actions.add(swf.readAction());
41          }
42          byte[] rest = swf.popBuffer();
43          if (rest != null) {
44              System.err.println("Corrupted ClipActionRecord, " + rest.length
45                      + " bytes leftoever.");
46          }
47      }
48  
49      public void write(SWFOutputStream swf) throws IOException {
50          eventFlags.write(swf);
51          // FIXME, should do PushBuffer and calculate this size...
52          swf.writeUnsignedInt(actionRecordSize);
53          if (eventFlags.isKeyPress())
54              swf.writeUnsignedByte(keyCode);
55  
56          for (int i = 0; i < actions.size(); i++) {
57              SWFAction a = (SWFAction) actions.get(i);
58              swf.writeAction(a);
59          }
60      }
61  
62      public boolean isEndRecord() {
63          return eventFlags.isEndFlag();
64      }
65  
66      public String toString() {
67          return "ClipActionRecord " + actions.size();
68      }
69  }