| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.awt.Color; |
| 5 |
import java.awt.geom.Rectangle2D; |
| 6 |
import java.io.IOException; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class DefineEditText extends DefinitionTag { |
| 16 |
|
| 17 |
private int character; |
| 18 |
|
| 19 |
private Rectangle2D bounds; |
| 20 |
|
| 21 |
private boolean disableEditting; |
| 22 |
|
| 23 |
private boolean password; |
| 24 |
|
| 25 |
private boolean multiLine; |
| 26 |
|
| 27 |
private boolean wordWrap; |
| 28 |
|
| 29 |
private boolean drawBox; |
| 30 |
|
| 31 |
private boolean disableSelection; |
| 32 |
|
| 33 |
private int fontID; |
| 34 |
|
| 35 |
private int height; |
| 36 |
|
| 37 |
private Color color; |
| 38 |
|
| 39 |
private int maxLength = -1; |
| 40 |
|
| 41 |
private int alignment; |
| 42 |
|
| 43 |
private int leftMargin; |
| 44 |
|
| 45 |
private int rightMargin; |
| 46 |
|
| 47 |
private int indent; |
| 48 |
|
| 49 |
private int lineSpace; |
| 50 |
|
| 51 |
private String variable; |
| 52 |
|
| 53 |
private String initialText; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public DefineEditText() { |
| 58 |
super(37, 4); |
| 59 |
} |
| 60 |
|
| 61 |
public SWFTag read(int tagID, SWFInputStream swf, int len) |
| 62 |
throws IOException { |
| 63 |
|
| 64 |
DefineEditText tag = new DefineEditText(); |
| 65 |
tag.character = swf.readUnsignedShort(); |
| 66 |
swf.getDictionary().put(tag.character, tag); |
| 67 |
tag.bounds = swf.readRect(); |
| 68 |
|
| 69 |
int flags = swf.readUnsignedShort(); |
| 70 |
boolean hasLength = ((flags & 0x0002) > 0); |
| 71 |
tag.disableEditting = ((flags & 0x0008) > 0); |
| 72 |
tag.password = ((flags & 0x0010) > 0); |
| 73 |
tag.multiLine = ((flags & 0x0020) > 0); |
| 74 |
tag.wordWrap = ((flags & 0x0040) > 0); |
| 75 |
boolean hasText = ((flags & 0x0080) > 0); |
| 76 |
tag.drawBox = ((flags & 0x0800) > 0); |
| 77 |
tag.disableSelection = ((flags & 0x1000) > 0); |
| 78 |
|
| 79 |
tag.fontID = swf.readUnsignedShort(); |
| 80 |
tag.height = swf.readUnsignedShort(); |
| 81 |
tag.color = swf.readColor(true); |
| 82 |
if (hasLength) |
| 83 |
tag.maxLength = swf.readUnsignedShort(); |
| 84 |
tag.alignment = swf.readUnsignedByte(); |
| 85 |
tag.leftMargin = swf.readUnsignedShort(); |
| 86 |
tag.rightMargin = swf.readUnsignedShort(); |
| 87 |
tag.indent = swf.readUnsignedShort(); |
| 88 |
tag.lineSpace = swf.readUnsignedShort(); |
| 89 |
tag.variable = swf.readString(); |
| 90 |
if (hasText) |
| 91 |
tag.initialText = swf.readString(); |
| 92 |
|
| 93 |
return tag; |
| 94 |
} |
| 95 |
|
| 96 |
public void write(int tagID, SWFOutputStream swf) throws IOException { |
| 97 |
swf.writeUnsignedShort(character); |
| 98 |
swf.writeRect(bounds); |
| 99 |
int flags = 0; |
| 100 |
if (maxLength >= 0) |
| 101 |
flags |= 0x0002; |
| 102 |
if (disableEditting) |
| 103 |
flags |= 0x0008; |
| 104 |
if (password) |
| 105 |
flags |= 0x0010; |
| 106 |
if (multiLine) |
| 107 |
flags |= 0x0020; |
| 108 |
if (wordWrap) |
| 109 |
flags |= 0x0040; |
| 110 |
if (initialText != null) |
| 111 |
flags |= 0x0080; |
| 112 |
if (drawBox) |
| 113 |
flags |= 0x0800; |
| 114 |
if (disableSelection) |
| 115 |
flags |= 0x1000; |
| 116 |
swf.writeUnsignedShort(flags); |
| 117 |
|
| 118 |
swf.writeUnsignedShort(fontID); |
| 119 |
swf.writeUnsignedShort(height); |
| 120 |
swf.writeColor(color, true); |
| 121 |
if (maxLength >= 0) |
| 122 |
swf.writeUnsignedShort(maxLength); |
| 123 |
swf.writeUnsignedByte(alignment); |
| 124 |
swf.writeUnsignedShort(leftMargin); |
| 125 |
swf.writeUnsignedShort(rightMargin); |
| 126 |
swf.writeUnsignedShort(indent); |
| 127 |
swf.writeUnsignedShort(lineSpace); |
| 128 |
swf.writeString(variable); |
| 129 |
if (initialText != null) |
| 130 |
swf.writeString(initialText); |
| 131 |
} |
| 132 |
|
| 133 |
public String toString() { |
| 134 |
|
| 135 |
StringBuffer s = new StringBuffer(); |
| 136 |
s.append(super.toString() + "\n"); |
| 137 |
s.append(" character: " + character + "\n"); |
| 138 |
s.append(" ...\n"); |
| 139 |
return s.toString(); |
| 140 |
} |
| 141 |
|
| 142 |
} |