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.documents.interaction.Destination; 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.PdfLiteral; 36 import it.stefanochizzolini.clown.objects.PdfName; 37 import it.stefanochizzolini.clown.objects.PdfObjectWrapper; 38 import it.stefanochizzolini.clown.objects.PdfReference; 39 import it.stefanochizzolini.clown.util.NotImplementedException; 40 41 44 public class Bookmark 45 extends PdfObjectWrapper<PdfDictionary> 46 { 47 public Bookmark( 51 Document context, 52 String title, 53 Destination destination 54 ) 55 { 56 super( 57 context.getFile(), 58 new PdfDictionary( 59 new PdfName[] 60 { 61 PdfName.Title, 62 PdfName.Dest, 63 PdfName.Count 64 }, 65 new PdfDirectObject[] 66 { 67 new PdfLiteral(title), 68 (destination == null)? 69 null 70 : destination.getBaseObject(), 71 new PdfInteger(0) 72 } 73 ) 74 ); 75 } 76 77 Bookmark( 78 PdfDirectObject baseObject 79 ) 80 { 81 super( 82 baseObject, 83 null ); 85 } 86 88 public Bookmarks getBookmarks( 91 ) 92 {return new Bookmarks(getBaseObject());} 93 94 public Object clone( 95 Document context 96 ) 97 {throw new NotImplementedException();} 98 99 public boolean getOpen( 100 ) 101 { 102 PdfInteger countObject = (PdfInteger)getBaseDataObject().get(PdfName.Count); 103 return (countObject == null 104 || countObject.getValue() >= 0); 105 } 106 107 public void setOpen( 108 boolean value 109 ) 110 { 111 PdfInteger countObject = (PdfInteger)getBaseDataObject().get(PdfName.Count); 112 if(countObject == null) 113 return; 114 115 118 if(value) 119 countObject.setValue(Math.abs(countObject.getValue())); 120 else 121 countObject.setValue(-Math.abs(countObject.getValue())); 122 } 123 124 public Destination getDestination( 125 ) 126 { 127 return new Destination( 128 getBaseDataObject().get(PdfName.Dest), 129 ((PdfReference)getBaseObject()).getIndirectObject() 130 ); 131 } 132 133 public void setDestination( 134 Destination value 135 ) 136 { 137 getBaseDataObject().put(PdfName.Dest,value.getBaseObject()); 138 } 139 140 public Bookmark getNextSibling( 141 ) 142 { 143 PdfReference reference = (PdfReference)getBaseDataObject().get(PdfName.Next); 144 if(reference == null) 145 return null; 147 return new Bookmark(reference); 148 } 149 150 public void setNextSibling( 151 Bookmark value 152 ) 153 {throw new NotImplementedException();} 154 155 public Bookmark getParent( 156 ) 157 { 158 PdfReference reference = (PdfReference)getBaseDataObject().get(PdfName.Parent); 159 164 if(((PdfDictionary)File.resolve(reference)).containsKey(PdfName.Title)) return new Bookmark(reference); 166 else return null; } 169 170 public void setParent( 171 Bookmark value 172 ) 173 {throw new NotImplementedException();} 174 175 public Bookmark getPreviousSibling( 176 ) 177 { 178 PdfReference reference = (PdfReference)getBaseDataObject().get(PdfName.Prev); 179 if(reference == null) 180 return null; 182 return new Bookmark(reference); 183 } 184 185 public void setPreviousSibling( 186 Bookmark value 187 ) 188 {throw new NotImplementedException();} 189 190 public String getTitle( 191 ) 192 {return ((PdfLiteral)getBaseDataObject().get(PdfName.Title)).getValue();} 193 194 public void setTitle( 195 String value 196 ) 197 {((PdfLiteral)getBaseDataObject().get(PdfName.Title)).setValue(value);} 198 } | Popular Tags |