KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.ListIterator JavaDoc;
44
45 /**
46   Collection of bookmarks [PDF:1.6:8.2.2].
47 */

48 public class Bookmarks
49   extends PdfObjectWrapper<PdfDictionary>
50   implements List JavaDoc<Bookmark>
51 {
52   // <class>
53
// <dynamic>
54
// <constructors>
55
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   /**
77     <h3>Remarks</h3>
78     <p>For internal use only.</p>
79   */

80   public Bookmarks(
81     PdfDirectObject baseObject
82     )
83   {
84     super(
85       baseObject,
86       null // NO container (bookmark MUST be an indirect object [PDF:1.6:8.2.2]).
87
);
88   }
89   // </constructors>
90

91   // <interface>
92
// <public>
93
public Object JavaDoc clone(
94     Document context
95     )
96   {throw new NotImplementedException();}
97
98   // <List>
99
public void add(
100     int index,
101     Bookmark bookmark
102     )
103   {throw new NotImplementedException();}
104
105   public boolean addAll(
106     int index,
107     Collection JavaDoc<? 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       // Did we go past the collection range?
120
if(bookmarkObject == null)
121         throw new IndexOutOfBoundsException JavaDoc();
122
123       index--;
124     }
125
126     return new Bookmark(bookmarkObject);
127   }
128
129   public int indexOf(
130     Object JavaDoc bookmark
131     )
132   {throw new NotImplementedException();}
133
134   public int lastIndexOf(
135     Object JavaDoc bookmark
136     )
137   {return indexOf(bookmark);}
138
139   public ListIterator JavaDoc<Bookmark> listIterator(
140     )
141   {throw new NotImplementedException();}
142
143   public ListIterator JavaDoc<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 JavaDoc<Bookmark> subList(
160     int fromIndex,
161     int toIndex
162     )
163   {throw new NotImplementedException();}
164
165   // <Collection>
166
public boolean add(
167     Bookmark bookmark
168     )
169   {
170     /*
171       NOTE: Bookmarks imported from alien PDF files MUST be cloned
172       before being added.
173     */

174     bookmark.getBaseDataObject().put(PdfName.Parent,getBaseObject());
175
176     PdfInteger countObject = ensureCountObject();
177     // Is it the first bookmark?
178
if(countObject.getValue() == 0) // First bookmark.
179
{
180       getBaseDataObject().put(PdfName.First,bookmark.getBaseObject());
181       getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject());
182
183       ((IPdfNumber)countObject).translateNumberValue(+1);
184     }
185     else // Non-first bookmark.
186
{
187       PdfReference oldLastBookmarkReference = (PdfReference)getBaseDataObject().get(PdfName.Last);
188       getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject()); // Added bookmark is the last in the collection...
189
((PdfDictionary)File.resolve(oldLastBookmarkReference)).put(PdfName.Next,bookmark.getBaseObject()); // ...and the next of the previously-last bookmark.
190
bookmark.getBaseDataObject().put(PdfName.Prev,oldLastBookmarkReference);
191
192       /*
193         NOTE: The Count entry is a relative number (whose sign represents
194         the node open state).
195       */

196       ((IPdfNumber)countObject).translateNumberValue(Math.signum(countObject.getValue()));
197     }
198
199     return true;
200   }
201
202   public boolean addAll(
203     Collection JavaDoc<? 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 JavaDoc bookmark
213     )
214   {throw new NotImplementedException();}
215
216   public boolean containsAll(
217     Collection JavaDoc<?> bookmarks
218     )
219   {throw new NotImplementedException();}
220
221   public boolean equals(
222     Object JavaDoc 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 JavaDoc bookmark
236     )
237   {throw new NotImplementedException();}
238
239   public boolean removeAll(
240     Collection JavaDoc<?> bookmarks
241     )
242   {throw new NotImplementedException();}
243
244   public boolean retainAll(
245     Collection JavaDoc<?> bookmarks
246     )
247   {throw new NotImplementedException();}
248
249   public int size(
250     )
251   {
252     /*
253       NOTE: The Count entry may be absent [PDF:1.6:8.2.2].
254     */

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   // <Iterable>
272
public Iterator JavaDoc<Bookmark> iterator(
273     )
274   {throw new NotImplementedException();}
275   // </Iterable>
276
// </Collection>
277
// </List>
278
// </public>
279

280   // <protected>
281
/**
282     Gets the count object, forcing its creation if it doesn't exist.
283   */

284   protected PdfInteger ensureCountObject(
285     )
286   {
287     /*
288       NOTE: The Count entry may be absent [PDF:1.6:8.2.2].
289     */

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   // </protected>
297
// </interface>
298
// </dynamic>
299
// </class>
300
}
Popular Tags