View Javadoc

1   // Copyright 2001-2006, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.awt.geom.Rectangle2D;
5   import java.io.IOException;
6   
7   /**
8    * DefineShape TAG.
9    * 
10   * @author Mark Donszelmann
11   * @author Charles Loomis
12   * @version $Id: DefineShape.java 9979 2006-11-27 22:51:07Z duns $
13   */
14  public class DefineShape extends DefinitionTag {
15  
16      protected int character;
17  
18      protected Rectangle2D bounds;
19  
20      protected FillStyleArray fillStyles;
21  
22      protected LineStyleArray lineStyles;
23  
24      protected SWFShape shape;
25  
26      public DefineShape(int id, Rectangle2D bounds, FillStyleArray fillStyles,
27              LineStyleArray lineStyles, SWFShape shape) {
28          this();
29          character = id;
30          this.bounds = bounds;
31          this.fillStyles = fillStyles;
32          this.lineStyles = lineStyles;
33          this.shape = shape;
34      }
35  
36      public DefineShape() {
37          super(2, 1);
38      }
39  
40      protected DefineShape(int tagID, int version) {
41          super(tagID, version);
42      }
43  
44      public SWFTag read(int tagID, SWFInputStream swf, int len)
45              throws IOException {
46          DefineShape tag = new DefineShape();
47          tag.read(tagID, swf, false);
48          return tag;
49      }
50  
51      protected void read(int tagID, SWFInputStream swf, boolean hasAlpha)
52              throws IOException {
53          character = swf.readUnsignedShort();
54          swf.getDictionary().put(character, this);
55          bounds = swf.readRect();
56  
57          fillStyles = new FillStyleArray(swf, false, hasAlpha);
58          lineStyles = new LineStyleArray(swf, false, hasAlpha, false);
59  
60          shape = new SWFShape(swf, fillStyles, lineStyles, false, hasAlpha, false);
61      }
62  
63      public void write(int tagID, SWFOutputStream swf) throws IOException {
64          write(swf, false);
65      }
66  
67      public void write(SWFOutputStream swf, boolean hasAlpha) throws IOException {
68          swf.writeUnsignedShort(character);
69          swf.writeRect(bounds);
70          
71          fillStyles.write(swf, false,  hasAlpha);
72          lineStyles.write(swf, false, hasAlpha, false);
73  
74          shape.write(swf, false, hasAlpha, false);
75      }
76  
77      public String toString() {
78          StringBuffer s = new StringBuffer();
79          s.append(super.toString() + "\n");
80          s.append("  character:  " + character + "\n");
81          s.append(fillStyles.toString());
82          s.append(lineStyles.toString());
83          s.append("  shape: \n");
84          s.append((shape != null) ? shape.toString() : "null");
85          return s.toString();
86      }
87  
88  }