KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > interaction > navigation > document > Bookmark


1 /*
2   Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright © 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

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 /**
42   Outline item.
43 */

44 public class Bookmark
45   extends PdfObjectWrapper<PdfDictionary>
46 {
47   // <class>
48
// <dynamic>
49
// <constructors>
50
public Bookmark(
51     Document context,
52     String JavaDoc 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 // NO container (bookmark MUST be an indirect object [PDF:1.6:8.2.2]).
84
);
85   }
86   // </constructors>
87

88   // <interface>
89
// <public>
90
public Bookmarks getBookmarks(
91     )
92   {return new Bookmarks(getBaseObject());}
93
94   public Object JavaDoc 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     /*
116     NOTE: Non-negative Count entry means open, negative Count entry means closed [PDF:1.6:8.2.2].
117     */

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; // This bookmark is the last one, no next sibling available.
146

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     // Is its parent a bookmark?
160
/*
161       NOTE: the Title entry can be used as a flag to distinguish bookmark
162       (outline item) dictionaries from outline (root) dictionaries.
163     */

164     if(((PdfDictionary)File.resolve(reference)).containsKey(PdfName.Title)) // Bookmark.
165
return new Bookmark(reference);
166     else // Outline root.
167
return null; // NO parent bookmark.
168
}
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; // This bookmark is the first one, no previous sibling available.
181

182     return new Bookmark(reference);
183   }
184
185   public void setPreviousSibling(
186     Bookmark value
187     )
188   {throw new NotImplementedException();}
189
190   public String JavaDoc getTitle(
191     )
192   {return ((PdfLiteral)getBaseDataObject().get(PdfName.Title)).getValue();}
193
194   public void setTitle(
195     String JavaDoc value
196     )
197   {((PdfLiteral)getBaseDataObject().get(PdfName.Title)).setValue(value);}
198   // </public>
199
// </interface>
200
// </dynamic>
201
// </class>
202
}
Popular Tags