1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import org.apache.poi.util.BitField; 22 import org.apache.poi.util.LittleEndian; 23 24 import java.util.Arrays ; 25 26 public class ListData 27 { 28 private int _lsid; 29 private int _tplc; 30 private short[] _rgistd; 31 private byte _info; 32 private static BitField _fSimpleList = new BitField(0x1); 33 private static BitField _fRestartHdn = new BitField(0x2); 34 private byte _reserved; 35 ListLevel[] _levels; 36 37 public ListData(int listID, boolean numbered) 38 { 39 _lsid = listID; 40 _rgistd = new short[9]; 41 42 for (int x = 0; x < 9; x++) 43 { 44 _rgistd[x] = StyleSheet.NIL_STYLE; 45 } 46 47 _levels = new ListLevel[9]; 48 49 for (int x = 0; x < _levels.length; x++) 50 { 51 _levels[x] = new ListLevel(x, numbered); 52 } 53 } 54 55 ListData(byte[] buf, int offset) 56 { 57 _lsid = LittleEndian.getInt(buf, offset); 58 offset += LittleEndian.INT_SIZE; 59 _tplc = LittleEndian.getInt(buf, offset); 60 offset += LittleEndian.INT_SIZE; 61 _rgistd = new short[9]; 62 for (int x = 0; x < 9; x++) 63 { 64 _rgistd[x] = LittleEndian.getShort(buf, offset); 65 offset += LittleEndian.SHORT_SIZE; 66 } 67 _info = buf[offset++]; 68 _reserved = buf[offset]; 69 if (_fSimpleList.getValue(_info) > 0) 70 { 71 _levels = new ListLevel[1]; 72 } 73 else 74 { 75 _levels = new ListLevel[9]; 76 } 77 78 } 79 80 public int getLsid() 81 { 82 return _lsid; 83 } 84 85 public int numLevels() 86 { 87 return _levels.length; 88 } 89 90 public void setLevel(int index, ListLevel level) 91 { 92 _levels[index] = level; 93 } 94 95 public ListLevel[] getLevels() 96 { 97 return _levels; 98 } 99 100 106 public ListLevel getLevel(int index) 107 { 108 return _levels[index - 1]; 109 } 110 111 public int getLevelStyle(int index) 112 { 113 return _rgistd[index]; 114 } 115 116 public void setLevelStyle(int index, int styleIndex) 117 { 118 _rgistd[index] = (short)styleIndex; 119 } 120 121 public boolean equals(Object obj) 122 { 123 if (obj == null) 124 { 125 return false; 126 } 127 128 ListData lst = (ListData)obj; 129 return lst._info == _info && Arrays.equals(lst._levels, _levels) && 130 lst._lsid == _lsid && lst._reserved == _reserved && lst._tplc == _tplc && 131 Arrays.equals(lst._rgistd, _rgistd); 132 } 133 134 int resetListID() 135 { 136 _lsid = (int)(Math.random() * (double)System.currentTimeMillis()); 137 return _lsid; 138 } 139 140 public byte[] toByteArray() 141 { 142 byte[] buf = new byte[28]; 143 int offset = 0; 144 LittleEndian.putInt(buf, _lsid); 145 offset += LittleEndian.INT_SIZE; 146 LittleEndian.putInt(buf, offset, _tplc); 147 offset += LittleEndian.INT_SIZE; 148 for (int x = 0; x < 9; x++) 149 { 150 LittleEndian.putShort(buf, offset, _rgistd[x]); 151 offset += LittleEndian.SHORT_SIZE; 152 } 153 buf[offset++] = _info; 154 buf[offset] = _reserved; 155 return buf; 156 } 157 } 158 | Popular Tags |