| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.awt.geom.AffineTransform; |
| 5 |
import java.io.IOException; |
| 6 |
import java.util.Vector; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class PlaceObject2 extends ControlTag { |
| 16 |
|
| 17 |
private boolean move; |
| 18 |
|
| 19 |
private int depth; |
| 20 |
|
| 21 |
private int character = -1; |
| 22 |
|
| 23 |
private AffineTransform matrix = null; |
| 24 |
|
| 25 |
private ColorXform cxform = null; |
| 26 |
|
| 27 |
private int ratio = -1; |
| 28 |
|
| 29 |
private String name = null; |
| 30 |
|
| 31 |
private int clipDepth = -1; |
| 32 |
|
| 33 |
private ClipEventFlags allEventFlags = null; |
| 34 |
|
| 35 |
private Vector<ClipActionRecord> clipActionRecords = null; |
| 36 |
|
| 37 |
public PlaceObject2(int id, int depth, AffineTransform matrix) { |
| 38 |
this(false, depth, id, matrix, null, 0, null, 0); |
| 39 |
} |
| 40 |
|
| 41 |
public PlaceObject2(int id, int depth, AffineTransform matrix, int clipDepth) { |
| 42 |
this(false, depth, id, matrix, null, 0, null, clipDepth); |
| 43 |
} |
| 44 |
|
| 45 |
public PlaceObject2(boolean move, int depth, int id, |
| 46 |
AffineTransform matrix, ColorXform cxform, int ratio, String name, |
| 47 |
int clipDepth) { |
| 48 |
this(); |
| 49 |
this.move = move; |
| 50 |
this.depth = depth; |
| 51 |
character = id; |
| 52 |
this.matrix = matrix; |
| 53 |
this.cxform = cxform; |
| 54 |
this.ratio = ratio; |
| 55 |
this.name = name; |
| 56 |
this.clipDepth = clipDepth; |
| 57 |
} |
| 58 |
|
| 59 |
public PlaceObject2() { |
| 60 |
super(26, 3); |
| 61 |
} |
| 62 |
|
| 63 |
public SWFTag read(int tagID, SWFInputStream swf, int len) |
| 64 |
throws IOException { |
| 65 |
|
| 66 |
PlaceObject2 tag = new PlaceObject2(); |
| 67 |
boolean hasClipActions = swf.readBitFlag(); |
| 68 |
boolean hasClipDepth = swf.readBitFlag(); |
| 69 |
boolean hasName = swf.readBitFlag(); |
| 70 |
boolean hasRatio = swf.readBitFlag(); |
| 71 |
boolean hasColorXform = swf.readBitFlag(); |
| 72 |
boolean hasMatrix = swf.readBitFlag(); |
| 73 |
boolean hasCharacter = swf.readBitFlag(); |
| 74 |
move = swf.readBitFlag(); |
| 75 |
|
| 76 |
tag.depth = swf.readUnsignedShort(); |
| 77 |
|
| 78 |
if (hasCharacter) |
| 79 |
tag.character = swf.readUnsignedShort(); |
| 80 |
if (hasMatrix) |
| 81 |
tag.matrix = swf.readMatrix(); |
| 82 |
if (hasColorXform) |
| 83 |
tag.cxform = new ColorXform(swf, true); |
| 84 |
if (hasRatio) |
| 85 |
tag.ratio = swf.readUnsignedShort(); |
| 86 |
if (hasName) |
| 87 |
tag.name = swf.readString(); |
| 88 |
if (hasClipDepth) |
| 89 |
tag.clipDepth = swf.readUnsignedShort(); |
| 90 |
if (hasClipActions) { |
| 91 |
swf.readUnsignedShort(); |
| 92 |
tag.allEventFlags = new ClipEventFlags(swf); |
| 93 |
|
| 94 |
tag.clipActionRecords = new Vector<ClipActionRecord>(); |
| 95 |
ClipActionRecord clipActionRecord = new ClipActionRecord(swf); |
| 96 |
while (clipActionRecord.isEndRecord()) { |
| 97 |
tag.clipActionRecords.add(clipActionRecord); |
| 98 |
clipActionRecord = new ClipActionRecord(swf); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
return tag; |
| 103 |
} |
| 104 |
|
| 105 |
public void write(int tagID, SWFOutputStream swf) throws IOException { |
| 106 |
swf.writeBitFlag(allEventFlags != null); |
| 107 |
swf.writeBitFlag(clipDepth > 0); |
| 108 |
swf.writeBitFlag(name != null); |
| 109 |
swf.writeBitFlag(ratio >= 0); |
| 110 |
swf.writeBitFlag(cxform != null); |
| 111 |
swf.writeBitFlag(matrix != null); |
| 112 |
swf.writeBitFlag(character >= 0); |
| 113 |
swf.writeBitFlag(move); |
| 114 |
|
| 115 |
swf.writeUnsignedShort(depth); |
| 116 |
|
| 117 |
if (character >= 0) |
| 118 |
swf.writeUnsignedShort(character); |
| 119 |
if (matrix != null) |
| 120 |
swf.writeMatrix(matrix); |
| 121 |
if (cxform != null) |
| 122 |
cxform.write(swf, true); |
| 123 |
if (ratio >= 0) |
| 124 |
swf.writeUnsignedShort(ratio); |
| 125 |
if (name != null) |
| 126 |
swf.writeString(name); |
| 127 |
if (clipDepth > 0) |
| 128 |
swf.writeUnsignedShort(clipDepth); |
| 129 |
if (allEventFlags != null) { |
| 130 |
swf.writeUnsignedShort(0); |
| 131 |
allEventFlags.write(swf); |
| 132 |
|
| 133 |
for (int i = 0; i < clipActionRecords.size(); i++) { |
| 134 |
ClipActionRecord clipActionRecord = clipActionRecords |
| 135 |
.get(i); |
| 136 |
clipActionRecord.write(swf); |
| 137 |
} |
| 138 |
swf.writeUnsignedInt(0); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
public String toString() { |
| 143 |
StringBuffer s = new StringBuffer(super.toString() + "\n"); |
| 144 |
if (move) |
| 145 |
s.append(" move\n"); |
| 146 |
s.append(" depth: " + depth + "\n"); |
| 147 |
if (character >= 0) |
| 148 |
s.append(" character: " + character + "\n"); |
| 149 |
if (matrix != null) |
| 150 |
s.append(" matrix: " + matrix + "\n"); |
| 151 |
if (cxform != null) |
| 152 |
s.append(" xform: " + cxform + "\n"); |
| 153 |
if (ratio >= 0) |
| 154 |
s.append(" ratio: " + ratio + "\n"); |
| 155 |
if (name != null) |
| 156 |
s.append(" name: " + name + "\n"); |
| 157 |
if (clipDepth > 0) |
| 158 |
s.append(" clipDepth: " + clipDepth + "\n"); |
| 159 |
if (allEventFlags != null) { |
| 160 |
s.append(" allEventFlags: " + allEventFlags + "\n"); |
| 161 |
for (int i = 0; i < clipActionRecords.size(); i++) { |
| 162 |
s.append(" " + clipActionRecords.get(i) + "\n"); |
| 163 |
} |
| 164 |
} |
| 165 |
return s.toString(); |
| 166 |
} |
| 167 |
} |