| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.io.IOException; |
| 5 |
import java.util.Vector; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class DefineButton2 extends DefinitionTag { |
| 15 |
|
| 16 |
private int character; |
| 17 |
|
| 18 |
private boolean trackAsMenu; |
| 19 |
|
| 20 |
private Vector<ButtonRecord> buttons; |
| 21 |
|
| 22 |
private Vector<ButtonCondAction> conditions; |
| 23 |
|
| 24 |
public DefineButton2(int id, boolean trackAsMenu, Vector<ButtonRecord> buttons, |
| 25 |
Vector<ButtonCondAction> conditions) { |
| 26 |
this(); |
| 27 |
character = id; |
| 28 |
this.trackAsMenu = trackAsMenu; |
| 29 |
this.buttons = buttons; |
| 30 |
this.conditions = conditions; |
| 31 |
} |
| 32 |
|
| 33 |
public DefineButton2() { |
| 34 |
super(34, 3); |
| 35 |
} |
| 36 |
|
| 37 |
public SWFTag read(int tagID, SWFInputStream swf, int len) |
| 38 |
throws IOException { |
| 39 |
|
| 40 |
System.out.println(len); |
| 41 |
|
| 42 |
DefineButton2 tag = new DefineButton2(); |
| 43 |
tag.character = swf.readUnsignedShort(); |
| 44 |
swf.getDictionary().put(tag.character, tag); |
| 45 |
swf.readUBits(7); |
| 46 |
trackAsMenu = swf.readBitFlag(); |
| 47 |
|
| 48 |
|
| 49 |
int offset = swf.readUnsignedShort(); |
| 50 |
|
| 51 |
tag.buttons = new Vector<ButtonRecord>(); |
| 52 |
ButtonRecord record = new ButtonRecord(swf, true); |
| 53 |
while (!record.isEndRecord()) { |
| 54 |
tag.buttons.add(record); |
| 55 |
record = new ButtonRecord(swf, true); |
| 56 |
} |
| 57 |
|
| 58 |
tag.conditions = new Vector<ButtonCondAction>(); |
| 59 |
if (offset != 0) { |
| 60 |
int actionOffset; |
| 61 |
do { |
| 62 |
actionOffset = swf.readUnsignedShort(); |
| 63 |
System.err.println("AO " + actionOffset); |
| 64 |
tag.conditions.add(new ButtonCondAction(swf)); |
| 65 |
} while (actionOffset != 0); |
| 66 |
} |
| 67 |
return tag; |
| 68 |
} |
| 69 |
|
| 70 |
public void write(int tagID, SWFOutputStream swf) throws IOException { |
| 71 |
|
| 72 |
swf.writeUnsignedShort(character); |
| 73 |
swf.writeUBits(0, 7); |
| 74 |
swf.writeBitFlag(trackAsMenu); |
| 75 |
|
| 76 |
swf.pushBuffer(); |
| 77 |
for (int i = 0; i < buttons.size(); i++) { |
| 78 |
ButtonRecord b = buttons.get(i); |
| 79 |
b.write(swf); |
| 80 |
} |
| 81 |
swf.writeUnsignedByte(0); |
| 82 |
int offset = swf.popBuffer(); |
| 83 |
swf.writeUnsignedShort(offset); |
| 84 |
swf.append(); |
| 85 |
|
| 86 |
for (int i = 0; i < conditions.size(); i++) { |
| 87 |
swf.pushBuffer(); |
| 88 |
ButtonCondAction c = conditions.get(i); |
| 89 |
c.write(swf); |
| 90 |
int actionOffset = swf.popBuffer(); |
| 91 |
swf.writeUnsignedShort((i == conditions.size() - 1) ? 0 |
| 92 |
: actionOffset); |
| 93 |
swf.append(); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
public String toString() { |
| 98 |
StringBuffer s = new StringBuffer(); |
| 99 |
s.append(super.toString() + "\n"); |
| 100 |
s.append(" character: " + character + "\n"); |
| 101 |
s.append(" menu: " + trackAsMenu + "\n"); |
| 102 |
for (int i = 0; i < buttons.size(); i++) { |
| 103 |
s.append(" " + buttons.get(i) + "\n"); |
| 104 |
} |
| 105 |
for (int i = 0; i < conditions.size(); i++) { |
| 106 |
s.append(" " + conditions.get(i) + "\n"); |
| 107 |
} |
| 108 |
return s.toString(); |
| 109 |
} |
| 110 |
|
| 111 |
} |