001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.model;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.apache.poi.hssf.record.Record;
025:
026: public class WorkbookRecordList {
027: private List records = new ArrayList();
028:
029: private int protpos = 0; // holds the position of the protect record.
030: private int bspos = 0; // holds the position of the last bound sheet.
031: private int tabpos = 0; // holds the position of the tabid record
032: private int fontpos = 0; // hold the position of the last font record
033: private int xfpos = 0; // hold the position of the last extended font record
034: private int backuppos = 0; // holds the position of the backup record.
035: private int namepos = 0; // holds the position of last name record
036: private int supbookpos = 0; // holds the position of sup book
037: private int externsheetPos = 0;// holds the position of the extern sheet
038: private int palettepos = -1; // hold the position of the palette, if applicable
039:
040: public void setRecords(List records) {
041: this .records = records;
042: }
043:
044: public int size() {
045: return records.size();
046: }
047:
048: public Record get(int i) {
049: return (Record) records.get(i);
050: }
051:
052: public void add(int pos, Record r) {
053: records.add(pos, r);
054: if (getProtpos() >= pos)
055: setProtpos(protpos + 1);
056: if (getBspos() >= pos)
057: setBspos(bspos + 1);
058: if (getTabpos() >= pos)
059: setTabpos(tabpos + 1);
060: if (getFontpos() >= pos)
061: setFontpos(fontpos + 1);
062: if (getXfpos() >= pos)
063: setXfpos(xfpos + 1);
064: if (getBackuppos() >= pos)
065: setBackuppos(backuppos + 1);
066: if (getNamepos() >= pos)
067: setNamepos(namepos + 1);
068: if (getSupbookpos() >= pos)
069: setSupbookpos(supbookpos + 1);
070: if ((getPalettepos() != -1) && (getPalettepos() >= pos))
071: setPalettepos(palettepos + 1);
072: if (getExternsheetPos() >= pos)
073: setExternsheetPos(getExternsheetPos() + 1);
074: }
075:
076: public List getRecords() {
077: return records;
078: }
079:
080: public Iterator iterator() {
081: return records.iterator();
082: }
083:
084: public void remove(Object record) {
085: int i = records.indexOf(record);
086: this .remove(i);
087: }
088:
089: public void remove(int pos) {
090: records.remove(pos);
091: if (getProtpos() >= pos)
092: setProtpos(protpos - 1);
093: if (getBspos() >= pos)
094: setBspos(bspos - 1);
095: if (getTabpos() >= pos)
096: setTabpos(tabpos - 1);
097: if (getFontpos() >= pos)
098: setFontpos(fontpos - 1);
099: if (getXfpos() >= pos)
100: setXfpos(xfpos - 1);
101: if (getBackuppos() >= pos)
102: setBackuppos(backuppos - 1);
103: if (getNamepos() >= pos)
104: setNamepos(getNamepos() - 1);
105: if (getSupbookpos() >= pos)
106: setSupbookpos(getSupbookpos() - 1);
107: if ((getPalettepos() != -1) && (getPalettepos() >= pos))
108: setPalettepos(palettepos - 1);
109: if (getExternsheetPos() >= pos)
110: setExternsheetPos(getExternsheetPos() - 1);
111: }
112:
113: public int getProtpos() {
114: return protpos;
115: }
116:
117: public void setProtpos(int protpos) {
118: this .protpos = protpos;
119: }
120:
121: public int getBspos() {
122: return bspos;
123: }
124:
125: public void setBspos(int bspos) {
126: this .bspos = bspos;
127: }
128:
129: public int getTabpos() {
130: return tabpos;
131: }
132:
133: public void setTabpos(int tabpos) {
134: this .tabpos = tabpos;
135: }
136:
137: public int getFontpos() {
138: return fontpos;
139: }
140:
141: public void setFontpos(int fontpos) {
142: this .fontpos = fontpos;
143: }
144:
145: public int getXfpos() {
146: return xfpos;
147: }
148:
149: public void setXfpos(int xfpos) {
150: this .xfpos = xfpos;
151: }
152:
153: public int getBackuppos() {
154: return backuppos;
155: }
156:
157: public void setBackuppos(int backuppos) {
158: this .backuppos = backuppos;
159: }
160:
161: public int getPalettepos() {
162: return palettepos;
163: }
164:
165: public void setPalettepos(int palettepos) {
166: this .palettepos = palettepos;
167: }
168:
169: /**
170: * Returns the namepos.
171: * @return int
172: */
173: public int getNamepos() {
174: return namepos;
175: }
176:
177: /**
178: * Returns the supbookpos.
179: * @return int
180: */
181: public int getSupbookpos() {
182: return supbookpos;
183: }
184:
185: /**
186: * Sets the namepos.
187: * @param namepos The namepos to set
188: */
189: public void setNamepos(int namepos) {
190: this .namepos = namepos;
191: }
192:
193: /**
194: * Sets the supbookpos.
195: * @param supbookpos The supbookpos to set
196: */
197: public void setSupbookpos(int supbookpos) {
198: this .supbookpos = supbookpos;
199: }
200:
201: /**
202: * Returns the externsheetPos.
203: * @return int
204: */
205: public int getExternsheetPos() {
206: return externsheetPos;
207: }
208:
209: /**
210: * Sets the externsheetPos.
211: * @param externsheetPos The externsheetPos to set
212: */
213: public void setExternsheetPos(int externsheetPos) {
214: this.externsheetPos = externsheetPos;
215: }
216:
217: }
|