1 50 51 package com.lowagie.text.pdf; 52 53 import java.io.IOException ; 54 import java.io.OutputStream ; 55 import java.util.ArrayList ; 56 import java.util.Iterator ; 57 import java.util.ListIterator ; 58 59 70 71 public class PdfArray extends PdfObject { 72 73 75 76 protected ArrayList arrayList; 77 78 80 83 84 public PdfArray() { 85 super(ARRAY); 86 arrayList = new ArrayList (); 87 } 88 89 94 95 public PdfArray(PdfObject object) { 96 super(ARRAY); 97 arrayList = new ArrayList (); 98 arrayList.add(object); 99 } 100 101 public PdfArray(float values[]) { 102 super(ARRAY); 103 arrayList = new ArrayList (); 104 add(values); 105 } 106 107 public PdfArray(int values[]) { 108 super(ARRAY); 109 arrayList = new ArrayList (); 110 add(values); 111 } 112 113 118 119 public PdfArray(PdfArray array) { 120 super(ARRAY); 121 arrayList = new ArrayList (array.getArrayList()); 122 } 123 124 126 129 130 public void toPdf(PdfWriter writer, OutputStream os) throws IOException { 131 os.write('['); 132 133 Iterator i = arrayList.iterator(); 134 PdfObject object; 135 int type = 0; 136 if (i.hasNext()) { 137 object = (PdfObject) i.next(); 138 if (object == null) 139 object = PdfNull.PDFNULL; 140 object.toPdf(writer, os); 141 } 142 while (i.hasNext()) { 143 object = (PdfObject) i.next(); 144 if (object == null) 145 object = PdfNull.PDFNULL; 146 type = object.type(); 147 if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING) 148 os.write(' '); 149 object.toPdf(writer, os); 150 } 151 os.write(']'); 152 } 153 154 156 161 162 public ArrayList getArrayList() { 163 return arrayList; 164 } 165 166 171 172 public int size() { 173 return arrayList.size(); 174 } 175 176 182 183 public boolean add(PdfObject object) { 184 return arrayList.add(object); 185 } 186 187 public boolean add(float values[]) { 188 for (int k = 0; k < values.length; ++k) 189 arrayList.add(new PdfNumber(values[k])); 190 return true; 191 } 192 193 public boolean add(int values[]) { 194 for (int k = 0; k < values.length; ++k) 195 arrayList.add(new PdfNumber(values[k])); 196 return true; 197 } 198 199 206 207 public void addFirst(PdfObject object) { 208 arrayList.add(0, object); 209 } 210 211 217 218 public boolean contains(PdfObject object) { 219 return arrayList.contains(object); 220 } 221 222 public ListIterator listIterator() { 223 return arrayList.listIterator(); 224 } 225 226 public String toString() { 227 return arrayList.toString(); 228 } 229 230 public PdfObject getPdfObject( int idx ) { 231 return (PdfObject)arrayList.get(idx); 232 } 233 234 public PdfObject getDirectObject( int idx ) { 235 return PdfReader.getPdfObject(getPdfObject(idx)); 236 } 237 238 public PdfDictionary getAsDict(int idx) { 240 PdfDictionary dict = null; 241 PdfObject orig = getDirectObject(idx); 242 if (orig != null && orig.isDictionary()) 243 dict = (PdfDictionary) orig; 244 return dict; 245 } 246 247 public PdfArray getAsArray(int idx) { 248 PdfArray array = null; 249 PdfObject orig = getDirectObject(idx); 250 if (orig != null && orig.isArray()) 251 array = (PdfArray) orig; 252 return array; 253 } 254 255 public PdfStream getAsStream(int idx) { 256 PdfStream stream = null; 257 PdfObject orig = getDirectObject(idx); 258 if (orig != null && orig.isStream()) 259 stream = (PdfStream) orig; 260 return stream; 261 } 262 263 public PdfString getAsString(int idx) { 264 PdfString string = null; 265 PdfObject orig = getDirectObject(idx); 266 if (orig != null && orig.isString()) 267 string = (PdfString) orig; 268 return string; 269 } 270 271 public PdfNumber getAsNumber(int idx) { 272 PdfNumber number = null; 273 PdfObject orig = getDirectObject(idx); 274 if (orig != null && orig.isNumber()) 275 number = (PdfNumber) orig; 276 return number; 277 } 278 279 public PdfName getAsName(int idx) { 280 PdfName name = null; 281 PdfObject orig = getDirectObject(idx); 282 if (orig != null && orig.isName()) 283 name = (PdfName) orig; 284 return name; 285 } 286 287 public PdfBoolean getAsBoolean(int idx) { 288 PdfBoolean bool = null; 289 PdfObject orig = getDirectObject(idx); 290 if (orig != null && orig.isBoolean()) 291 bool = (PdfBoolean) orig; 292 return bool; 293 } 294 295 public PdfIndirectReference getAsIndirectObject(int idx) { 296 PdfIndirectReference ref = null; 297 PdfObject orig = getPdfObject(idx); if (orig != null && orig.isIndirect()) 299 ref = (PdfIndirectReference) orig; 300 return ref; 301 } 302 } | Popular Tags |