1 26 27 package it.stefanochizzolini.clown.documents.contents; 28 29 import it.stefanochizzolini.clown.documents.Document; 30 import it.stefanochizzolini.clown.documents.Page; 31 import it.stefanochizzolini.clown.objects.PdfArray; 32 import it.stefanochizzolini.clown.objects.PdfDataObject; 33 import it.stefanochizzolini.clown.objects.PdfDirectObject; 34 import it.stefanochizzolini.clown.objects.PdfName; 35 import it.stefanochizzolini.clown.objects.PdfObjectWrapper; 36 import it.stefanochizzolini.clown.objects.PdfReference; 37 import it.stefanochizzolini.clown.objects.PdfStream; 38 import it.stefanochizzolini.clown.util.NotImplementedException; 39 40 import java.util.Collection ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 import java.util.ListIterator ; 44 45 48 public class ContentStreams 49 extends PdfObjectWrapper<PdfDataObject> 50 implements List <ContentStream> 51 { 52 private Page parentPage; 56 58 63 public ContentStreams( 64 PdfDirectObject baseObject, 65 Page parentPage 66 ) 67 { 68 super( 69 baseObject, 70 ((PdfReference)parentPage.getBaseObject()).getIndirectObject() 71 ); 72 this.parentPage = parentPage; 73 } 74 76 public Object clone( 79 Document context 80 ) 81 {throw new NotImplementedException();} 82 83 public Page getParentPage( 84 ) 85 {return parentPage;} 86 87 public void add( 89 int index, 90 ContentStream content 91 ) 92 { 93 ensureArray().add(index,content.getBaseObject()); 95 content.setStreamContext(parentPage); 97 } 98 99 public boolean addAll( 100 int index, 101 Collection <? extends ContentStream> contents 102 ) 103 {throw new NotImplementedException();} 104 105 public ContentStream get( 106 int index 107 ) 108 { 109 PdfDirectObject content; 110 PdfDataObject contents = getBaseDataObject(); 111 if(contents instanceof PdfStream) 112 { 113 if(index == 0) 114 content = getBaseObject(); 115 else 116 throw new IndexOutOfBoundsException (); 117 } 118 else 119 { 120 content = ((PdfArray)contents).get(index); 121 } 122 123 return new ContentStream( 124 content, 125 parentPage 126 ); 127 } 128 129 public int indexOf( 130 Object content 131 ) 132 { 133 137 PdfDataObject baseDataObject = getBaseDataObject(); 138 if(baseDataObject instanceof PdfStream) { 141 if(baseDataObject.equals(((ContentStream)content).getBaseDataObject())) 142 return 0; 143 else 144 return -1; 145 } 146 else { 148 return ((PdfArray)baseDataObject).indexOf(((ContentStream)content).getBaseObject()); 149 } 150 } 151 152 public int lastIndexOf( 153 Object content 154 ) 155 { 156 159 return indexOf(content); 160 } 161 162 public ListIterator <ContentStream> listIterator( 163 ) 164 {throw new NotImplementedException();} 165 166 public ListIterator <ContentStream> listIterator( 167 int index 168 ) 169 {throw new NotImplementedException();} 170 171 public ContentStream remove( 172 int index 173 ) 174 { 175 return new ContentStream( 176 ensureArray().remove(index), 177 parentPage 178 ); 179 } 180 181 public ContentStream set( 182 int index, 183 ContentStream content 184 ) 185 {throw new NotImplementedException();} 186 187 public List <ContentStream> subList( 188 int fromIndex, 189 int toIndex 190 ) 191 {throw new NotImplementedException();} 192 193 public boolean add( 195 ContentStream content 196 ) 197 { 198 ensureArray().add(content.getBaseObject()); 199 200 content.setStreamContext(parentPage); 202 203 return true; 204 } 205 206 public boolean addAll( 207 Collection <? extends ContentStream> contents 208 ) 209 {throw new NotImplementedException();} 210 211 public void clear( 212 ) 213 { 214 ensureArray().clear(); 215 } 216 217 public boolean contains( 218 Object content 219 ) 220 { 221 225 PdfDataObject baseDataObject = getBaseDataObject(); 226 if(baseDataObject instanceof PdfStream) { 229 return baseDataObject.equals(((ContentStream)content).getBaseDataObject()); 230 } 231 else { 233 return ((PdfArray)baseDataObject).contains(((ContentStream)content).getBaseObject()); 234 } 235 } 236 237 public boolean containsAll( 238 Collection <?> contents 239 ) 240 {throw new NotImplementedException();} 241 242 public boolean equals( 243 Object object 244 ) 245 {throw new NotImplementedException();} 246 247 public int hashCode( 248 ) 249 {throw new NotImplementedException();} 250 251 public boolean isEmpty( 252 ) 253 {return (size() == 0);} 254 255 public boolean remove( 256 Object content 257 ) 258 {return ensureArray().remove(((ContentStream)content).getBaseObject());} 259 260 public boolean removeAll( 261 Collection <?> contents 262 ) 263 {throw new NotImplementedException();} 264 265 public boolean retainAll( 266 Collection <?> contents 267 ) 268 {throw new NotImplementedException();} 269 270 public int size( 271 ) 272 { 273 277 PdfDataObject baseDataObject = getBaseDataObject(); 278 if(baseDataObject instanceof PdfStream) return 1; 280 else return ((PdfArray)baseDataObject).size(); 282 } 283 284 public ContentStream[] toArray( 285 ) 286 {throw new NotImplementedException();} 287 288 public <ContentStream> ContentStream[] toArray( 289 ContentStream[] contents 290 ) 291 {throw new NotImplementedException();} 292 293 public Iterator <ContentStream> iterator( 295 ) 296 {throw new NotImplementedException();} 297 302 306 protected PdfArray ensureArray( 307 ) 308 { 309 PdfDataObject baseDataObject = getBaseDataObject(); 310 if(baseDataObject instanceof PdfStream) 312 { 313 317 baseDataObject = new PdfArray(new PdfDirectObject[]{getBaseObject()}); 318 setBaseDataObject(baseDataObject); setBaseObject((PdfDirectObject)baseDataObject); 319 parentPage.getBaseDataObject().put(PdfName.Contents,getBaseObject()); 321 setContainer(((PdfReference)parentPage.getBaseObject()).getIndirectObject()); 323 } 324 325 return (PdfArray)baseDataObject; 326 } 327 } | Popular Tags |