1 26 27 package it.stefanochizzolini.clown.documents.interaction.navigation.document; 28 29 import it.stefanochizzolini.clown.documents.Document; 30 import it.stefanochizzolini.clown.files.File; 31 import it.stefanochizzolini.clown.objects.IPdfNumber; 32 import it.stefanochizzolini.clown.objects.PdfDictionary; 33 import it.stefanochizzolini.clown.objects.PdfDirectObject; 34 import it.stefanochizzolini.clown.objects.PdfInteger; 35 import it.stefanochizzolini.clown.objects.PdfName; 36 import it.stefanochizzolini.clown.objects.PdfObjectWrapper; 37 import it.stefanochizzolini.clown.objects.PdfReference; 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 Bookmarks 49 extends PdfObjectWrapper<PdfDictionary> 50 implements List <Bookmark> 51 { 52 public Bookmarks( 56 Document context 57 ) 58 { 59 super( 60 context.getFile(), 61 new PdfDictionary( 62 new PdfName[] 63 { 64 PdfName.Type, 65 PdfName.Count 66 }, 67 new PdfDirectObject[] 68 { 69 PdfName.Outlines, 70 new PdfInteger(0) 71 } 72 ) 73 ); 74 } 75 76 80 public Bookmarks( 81 PdfDirectObject baseObject 82 ) 83 { 84 super( 85 baseObject, 86 null ); 88 } 89 91 public Object clone( 94 Document context 95 ) 96 {throw new NotImplementedException();} 97 98 public void add( 100 int index, 101 Bookmark bookmark 102 ) 103 {throw new NotImplementedException();} 104 105 public boolean addAll( 106 int index, 107 Collection <? extends Bookmark> bookmarks 108 ) 109 {throw new NotImplementedException();} 110 111 public Bookmark get( 112 int index 113 ) 114 { 115 PdfReference bookmarkObject = (PdfReference)getBaseDataObject().get(PdfName.First); 116 while(index > 0) 117 { 118 bookmarkObject = (PdfReference)((PdfDictionary)File.resolve(bookmarkObject)).get(PdfName.Next); 119 if(bookmarkObject == null) 121 throw new IndexOutOfBoundsException (); 122 123 index--; 124 } 125 126 return new Bookmark(bookmarkObject); 127 } 128 129 public int indexOf( 130 Object bookmark 131 ) 132 {throw new NotImplementedException();} 133 134 public int lastIndexOf( 135 Object bookmark 136 ) 137 {return indexOf(bookmark);} 138 139 public ListIterator <Bookmark> listIterator( 140 ) 141 {throw new NotImplementedException();} 142 143 public ListIterator <Bookmark> listIterator( 144 int index 145 ) 146 {throw new NotImplementedException();} 147 148 public Bookmark remove( 149 int index 150 ) 151 {throw new NotImplementedException();} 152 153 public Bookmark set( 154 int index, 155 Bookmark bookmark 156 ) 157 {throw new NotImplementedException();} 158 159 public List <Bookmark> subList( 160 int fromIndex, 161 int toIndex 162 ) 163 {throw new NotImplementedException();} 164 165 public boolean add( 167 Bookmark bookmark 168 ) 169 { 170 174 bookmark.getBaseDataObject().put(PdfName.Parent,getBaseObject()); 175 176 PdfInteger countObject = ensureCountObject(); 177 if(countObject.getValue() == 0) { 180 getBaseDataObject().put(PdfName.First,bookmark.getBaseObject()); 181 getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject()); 182 183 ((IPdfNumber)countObject).translateNumberValue(+1); 184 } 185 else { 187 PdfReference oldLastBookmarkReference = (PdfReference)getBaseDataObject().get(PdfName.Last); 188 getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject()); ((PdfDictionary)File.resolve(oldLastBookmarkReference)).put(PdfName.Next,bookmark.getBaseObject()); bookmark.getBaseDataObject().put(PdfName.Prev,oldLastBookmarkReference); 191 192 196 ((IPdfNumber)countObject).translateNumberValue(Math.signum(countObject.getValue())); 197 } 198 199 return true; 200 } 201 202 public boolean addAll( 203 Collection <? extends Bookmark> bookmarks 204 ) 205 {throw new NotImplementedException();} 206 207 public void clear( 208 ) 209 {throw new NotImplementedException();} 210 211 public boolean contains( 212 Object bookmark 213 ) 214 {throw new NotImplementedException();} 215 216 public boolean containsAll( 217 Collection <?> bookmarks 218 ) 219 {throw new NotImplementedException();} 220 221 public boolean equals( 222 Object object 223 ) 224 {throw new NotImplementedException();} 225 226 public int hashCode( 227 ) 228 {throw new NotImplementedException();} 229 230 public boolean isEmpty( 231 ) 232 {throw new NotImplementedException();} 233 234 public boolean remove( 235 Object bookmark 236 ) 237 {throw new NotImplementedException();} 238 239 public boolean removeAll( 240 Collection <?> bookmarks 241 ) 242 {throw new NotImplementedException();} 243 244 public boolean retainAll( 245 Collection <?> bookmarks 246 ) 247 {throw new NotImplementedException();} 248 249 public int size( 250 ) 251 { 252 255 PdfInteger countObject = (PdfInteger)getBaseDataObject().get(PdfName.Count); 256 if(countObject == null) 257 return 0; 258 else 259 return countObject.getValue(); 260 } 261 262 public Bookmark[] toArray( 263 ) 264 {throw new NotImplementedException();} 265 266 public <Bookmark> Bookmark[] toArray( 267 Bookmark[] bookmarks 268 ) 269 {throw new NotImplementedException();} 270 271 public Iterator <Bookmark> iterator( 273 ) 274 {throw new NotImplementedException();} 275 280 284 protected PdfInteger ensureCountObject( 285 ) 286 { 287 290 PdfInteger countObject = (PdfInteger)getBaseDataObject().get(PdfName.Count); 291 if(countObject == null) 292 getBaseDataObject().put(PdfName.Count,countObject = new PdfInteger(0)); 293 294 return countObject; 295 } 296 } | Popular Tags |