View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.awt.geom.AffineTransform;
5   import java.io.IOException;
6   
7   /**
8    * SWF Button Record
9    * 
10   * @author Mark Donszelmann
11   * @author Charles Loomis
12   * @version $Id: ButtonRecord.java 8584 2006-08-10 23:06:37Z duns $
13   */
14  public class ButtonRecord {
15  
16      public final static int UP = 0x01;
17  
18      public final static int OVER = 0x02;
19  
20      public final static int DOWN = 0x04;
21  
22      public final static int HIT = 0x08;
23  
24      private boolean hitTest;
25  
26      private boolean down;
27  
28      private boolean over;
29  
30      private boolean up;
31  
32      private int id;
33  
34      private int depth;
35  
36      private AffineTransform matrix;
37  
38      private ColorXform cxform;
39  
40      public ButtonRecord(boolean hitTest, boolean down, boolean over,
41              boolean up, int id, int depth, AffineTransform matrix,
42              ColorXform cxform) {
43          this.hitTest = hitTest;
44          this.down = down;
45          this.over = over;
46          this.up = up;
47          this.id = id;
48          this.depth = depth;
49          this.matrix = matrix;
50          this.cxform = cxform;
51      }
52  
53      public ButtonRecord(boolean hitTest, boolean down, boolean over,
54              boolean up, int id, int depth, AffineTransform matrix) {
55          this(hitTest, down, over, up, id, depth, matrix, null);
56      }
57  
58      public ButtonRecord(SWFInputStream input, boolean hasColorXform)
59              throws IOException {
60          /* int reserved = (int) */ input.readUBits(4);
61          hitTest = input.readBitFlag();
62          down = input.readBitFlag();
63          over = input.readBitFlag();
64          up = input.readBitFlag();
65  
66          if (isEndRecord())
67              return;
68  
69          id = input.readUnsignedShort();
70          depth = input.readUnsignedShort();
71          matrix = input.readMatrix();
72          if (hasColorXform) {
73              cxform = new ColorXform(input, true);
74          } else {
75              // NOTE: it may be just alignment, FREEHEP-535
76              input.readUnsignedByte();
77          }
78      }
79  
80      public void write(SWFOutputStream swf) throws IOException {
81          swf.writeUBits(0, 4);
82          swf.writeBitFlag(hitTest);
83          swf.writeBitFlag(down);
84          swf.writeBitFlag(over);
85          swf.writeBitFlag(up);
86          swf.writeUnsignedShort(id);
87          swf.writeUnsignedShort(depth);
88          swf.writeMatrix(matrix);
89          if (cxform != null) {
90              cxform.write(swf, true);
91          } else {
92              // NOTE: it may be just alignment, FREEHEP-535
93              swf.writeUnsignedByte(0);
94          }
95      }
96  
97      public boolean isEndRecord() {
98          return !(hitTest || down || over || up);
99      }
100 
101     public String toString() {
102         return "ButtonRecord char:" + id + " depth:" + depth + " " + matrix
103                 + " " + ((cxform != null) ? "" + cxform : "");
104     }
105 }