KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > interaction > Destination


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;
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.PdfDirectObject;
33 import it.stefanochizzolini.clown.objects.PdfIndirectObject;
34 import it.stefanochizzolini.clown.objects.PdfName;
35 import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
36 import it.stefanochizzolini.clown.objects.PdfReal;
37 import it.stefanochizzolini.clown.util.NotImplementedException;
38
39 /**
40   [PDF:1.6:8.2.1] Interaction target, that is a particular view of a document,
41   consisting of the following items:
42   <ul>
43     <li>the page of the document to be displayed;</li>
44     <li>the location of the document window on that page;</li>
45     <li>the magnification (zoom) factor to use when displaying the page.</li>
46   </ul>
47 */

48 public class Destination
49   extends PdfObjectWrapper<PdfArray>
50 {
51   // <class>
52
// <dynamic>
53
// <constructors>
54
public Destination(
55     Page page,
56     DestinationModeEnum mode,
57     double[] viewParams
58     )
59   {
60     super(
61       page.getFile(),
62       new PdfArray()
63       );
64
65     PdfArray destinationObject = getBaseDataObject();
66
67     destinationObject.add(page.getBaseObject());
68
69     switch(mode)
70     {
71       case Fit:
72         destinationObject.add(PdfName.Fit);
73         break;
74       case FitBoundingBox:
75         destinationObject.add(PdfName.FitB);
76         break;
77       case FitBoundingBoxHorizontal:
78         destinationObject.add(PdfName.FitBH);
79         destinationObject.add(new PdfReal(viewParams[0]));
80         break;
81       case FitBoundingBoxVertical:
82         destinationObject.add(PdfName.FitBV);
83         destinationObject.add(new PdfReal(viewParams[0]));
84         break;
85       case FitHorizontal:
86         destinationObject.add(PdfName.FitH);
87         destinationObject.add(new PdfReal(viewParams[0]));
88         break;
89       case FitRectangle:
90         destinationObject.add(PdfName.FitR);
91         destinationObject.add(new PdfReal(viewParams[0]));
92         destinationObject.add(new PdfReal(viewParams[1]));
93         destinationObject.add(new PdfReal(viewParams[2]));
94         destinationObject.add(new PdfReal(viewParams[3]));
95         break;
96       case FitVertical:
97         destinationObject.add(PdfName.FitV);
98         destinationObject.add(new PdfReal(viewParams[0]));
99         break;
100       case XYZ:
101         destinationObject.add(PdfName.XYZ);
102         destinationObject.add(new PdfReal(viewParams[0]));
103         destinationObject.add(new PdfReal(viewParams[1]));
104         destinationObject.add(new PdfReal(viewParams[2]));
105         break;
106     }
107   }
108
109   /**
110     <h3>Remarks</h3>
111     <p>For internal use only.</p>
112   */

113   public Destination(
114     PdfDirectObject baseObject,
115     PdfIndirectObject container
116     )
117   {
118     super(
119       baseObject,
120       container
121       );
122   }
123   // </constructors>
124

125   // <interface>
126
// <public>
127
public Object JavaDoc clone(
128     Document context
129     )
130   {throw new NotImplementedException();}
131
132   public DestinationModeEnum getDestinationMode(
133     )
134   {
135     PdfName value = (PdfName)getBaseDataObject().get(1);
136
137     if(value.equals(PdfName.FitB))
138       return DestinationModeEnum.FitBoundingBox;
139     else if(value.equals(PdfName.FitBH))
140       return DestinationModeEnum.FitBoundingBoxHorizontal;
141     else if(value.equals(PdfName.FitBV))
142       return DestinationModeEnum.FitBoundingBoxVertical;
143     else if(value.equals(PdfName.FitH))
144       return DestinationModeEnum.FitHorizontal;
145     else if(value.equals(PdfName.FitR))
146       return DestinationModeEnum.FitRectangle;
147     else if(value.equals(PdfName.FitV))
148       return DestinationModeEnum.FitVertical;
149     else if(value.equals(PdfName.XYZ))
150       return DestinationModeEnum.XYZ;
151     else
152       return DestinationModeEnum.Fit;
153   }
154
155   public Page getPage(
156     )
157   {return new Page(getBaseDataObject().get(0));}
158   // </public>
159
// </interface>
160
// </dynamic>
161
// </class>
162
}
Popular Tags