1 19 20 package jxl.biff.drawing; 21 22 import common.Logger; 23 24 import java.util.Iterator ; 25 import java.util.ArrayList ; 26 27 31 class EscherContainer extends EscherRecord 32 { 33 36 private static Logger logger = Logger.getLogger(EscherContainer.class); 37 38 41 private boolean initialized; 42 43 44 47 private ArrayList children; 48 49 54 public EscherContainer(EscherRecordData erd) 55 { 56 super(erd); 57 initialized = false; 58 children = new ArrayList (); 59 } 60 61 66 protected EscherContainer(EscherRecordType type) 67 { 68 super(type); 69 setContainer(true); 70 children = new ArrayList (); 71 } 72 73 78 public EscherRecord[] getChildren() 79 { 80 if (!initialized) 81 { 82 initialize(); 83 } 84 85 Object [] ca = children.toArray(new EscherRecord[children.size()]); 86 87 return (EscherRecord[]) ca; 88 } 89 90 95 public void add(EscherRecord child) 96 { 97 children.add(child); 98 } 99 100 105 public void remove(EscherRecord child) 106 { 107 children.remove(child); 108 } 109 110 113 private void initialize() 114 { 115 int curpos = getPos() + HEADER_LENGTH; 116 int endpos = Math.min(getPos() + getLength(), getStreamLength()); 117 118 EscherRecord newRecord = null; 119 120 while (curpos < endpos) 121 { 122 EscherRecordData erd = new EscherRecordData(getEscherStream(), curpos); 123 124 EscherRecordType type = erd.getType(); 125 if (type == EscherRecordType.DGG) 126 { 127 newRecord = new Dgg(erd); 128 } 129 else if (type == EscherRecordType.DG) 130 { 131 newRecord = new Dg(erd); 132 } 133 else if (type == EscherRecordType.BSTORE_CONTAINER) 134 { 135 newRecord = new BStoreContainer(erd); 136 } 137 else if (type == EscherRecordType.SPGR_CONTAINER) 138 { 139 newRecord = new SpgrContainer(erd); 140 } 141 else if (type == EscherRecordType.SP_CONTAINER) 142 { 143 newRecord = new SpContainer(erd); 144 } 145 else if (type == EscherRecordType.SPGR) 146 { 147 newRecord = new Spgr(erd); 148 } 149 else if (type == EscherRecordType.SP) 150 { 151 newRecord = new Sp(erd); 152 } 153 else if (type == EscherRecordType.CLIENT_ANCHOR) 154 { 155 newRecord = new ClientAnchor(erd); 156 } 157 else if (type == EscherRecordType.CLIENT_DATA) 158 { 159 newRecord = new ClientData(erd); 160 } 161 else if (type == EscherRecordType.BSE) 162 { 163 newRecord = new BlipStoreEntry(erd); 164 } 165 else if (type == EscherRecordType.OPT) 166 { 167 newRecord = new Opt(erd); 168 } 169 else if (type == EscherRecordType.SPLIT_MENU_COLORS) 170 { 171 newRecord = new SplitMenuColors(erd); 172 } 173 else if (type == EscherRecordType.CLIENT_TEXT_BOX) 174 { 175 newRecord = new ClientTextBox(erd); 176 } 177 else 178 { 179 newRecord = new EscherAtom(erd); 180 } 181 182 children.add(newRecord); 183 curpos += newRecord.getLength(); 184 } 185 186 initialized = true; 187 } 188 189 192 byte[] getData() 193 { 194 byte[] data = new byte[0]; 195 for (Iterator i = children.iterator() ; i.hasNext() ; ) 196 { 197 EscherRecord er = (EscherRecord) i.next(); 198 byte[] childData = er.getData(); 199 200 if (childData != null) 201 { 202 byte[] newData = new byte[data.length + childData.length]; 203 System.arraycopy(data, 0, newData, 0, data.length); 204 System.arraycopy(childData, 0, newData, data.length, childData.length); 205 data = newData; 206 } 207 } 208 209 return setHeaderData(data); 210 } 211 } 212 | Popular Tags |