1 19 20 package jxl.write.biff; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 import jxl.biff.Type; 26 import jxl.biff.WritableRecordData; 27 import jxl.biff.IntegerHelper; 28 29 33 class ExternalSheetRecord extends WritableRecordData 34 { 35 38 private byte[] data; 39 40 43 private ArrayList xtis; 44 45 48 private static class XTI 49 { 50 int supbookIndex; 51 int firstTab; 52 int lastTab; 53 54 XTI(int s, int f, int l) 55 { 56 supbookIndex = s; 57 firstTab = f; 58 lastTab = l; 59 } 60 61 void sheetInserted(int index) 62 { 63 if (firstTab >= index) 64 { 65 firstTab++; 66 } 67 68 if (lastTab >= index) 69 { 70 lastTab++; 71 } 72 } 73 74 void sheetRemoved(int index) 75 { 76 if (firstTab == index) 77 { 78 firstTab = 0; 79 } 80 81 if (lastTab == index) 82 { 83 lastTab = 0; 84 } 85 86 if (firstTab > index) 87 { 88 firstTab--; 89 } 90 91 if (lastTab > index) 92 { 93 lastTab--; 94 } 95 } 96 } 97 98 103 public ExternalSheetRecord(jxl.read.biff.ExternalSheetRecord esf) 104 { 105 super(Type.EXTERNSHEET); 106 107 xtis = new ArrayList (esf.getNumRecords()); 108 XTI xti = null; 109 for (int i = 0 ; i < esf.getNumRecords(); i++) 110 { 111 xti = new XTI(esf.getSupbookIndex(i), 112 esf.getFirstTabIndex(i), 113 esf.getLastTabIndex(i)); 114 xtis.add(xti); 115 } 116 } 117 118 121 public ExternalSheetRecord() 122 { 123 super(Type.EXTERNSHEET); 124 xtis = new ArrayList (); 125 } 126 127 133 int getIndex(int supbookind, int sheetind) 134 { 135 Iterator i = xtis.iterator(); 136 XTI xti = null; 137 boolean found = false; 138 int pos = 0; 139 while (i.hasNext() && !found) 140 { 141 xti = (XTI) i.next(); 142 143 if (xti.supbookIndex == supbookind && 144 xti.firstTab == sheetind) 145 { 146 found = true; 147 } 148 else 149 { 150 pos++; 151 } 152 } 153 154 if (!found) 155 { 156 xti = new XTI(supbookind, sheetind, sheetind); 157 xtis.add(xti); 158 pos = xtis.size() - 1; 159 } 160 161 return pos; 162 } 163 164 169 public byte[] getData() 170 { 171 byte[] data = new byte[2 + xtis.size() * 6]; 172 173 int pos = 0; 174 IntegerHelper.getTwoBytes(xtis.size(), data, 0); 175 pos += 2; 176 177 Iterator i = xtis.iterator(); 178 XTI xti = null; 179 while (i.hasNext()) 180 { 181 xti = (XTI) i.next(); 182 IntegerHelper.getTwoBytes(xti.supbookIndex, data, pos); 183 IntegerHelper.getTwoBytes(xti.firstTab, data, pos+2); 184 IntegerHelper.getTwoBytes(xti.lastTab, data, pos+4); 185 pos +=6 ; 186 } 187 188 return data; 189 } 190 191 197 public int getSupbookIndex(int index) 198 { 199 return ((XTI) xtis.get(index)).supbookIndex; 200 } 201 202 208 public int getFirstTabIndex(int index) 209 { 210 return ((XTI) xtis.get(index)).firstTab; 211 } 212 213 219 public int getLastTabIndex(int index) 220 { 221 return ((XTI) xtis.get(index)).lastTab; 222 } 223 224 228 void sheetInserted(int index) 229 { 230 XTI xti = null; 231 for (Iterator i = xtis.iterator(); i.hasNext() ; ) 232 { 233 xti = (XTI) i.next(); 234 xti.sheetInserted(index); 235 } 236 } 237 238 242 void sheetRemoved(int index) 243 { 244 XTI xti = null; 245 for (Iterator i = xtis.iterator(); i.hasNext() ; ) 246 { 247 xti = (XTI) i.next(); 248 xti.sheetRemoved(index); 249 } 250 } 251 252 } 253 | Popular Tags |