001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.pd;
031:
032: import de.intarsys.pdf.cos.COSArray;
033: import de.intarsys.pdf.cos.COSBasedObject;
034: import de.intarsys.pdf.cos.COSDictionary;
035: import de.intarsys.pdf.cos.COSName;
036: import de.intarsys.pdf.cos.COSObject;
037:
038: /**
039: * A document outline item. This is used to represent all tree elements in a PDF
040: * outline tree.
041: */
042: public class PDOutlineItem extends PDOutlineNode {
043: /**
044: * The meta class implementation
045: */
046: public static class MetaClass extends PDOutlineNode.MetaClass {
047: protected MetaClass(Class paramInstanceClass) {
048: super (paramInstanceClass);
049: }
050:
051: protected COSBasedObject doCreateCOSBasedObject(COSObject object) {
052: return new PDOutlineItem(object);
053: }
054:
055: protected COSBasedObject.MetaClass doDetermineClass(
056: COSObject object) {
057: // there are documents around that do not correctly contain
058: // a /Parent reference - so we can't really determine type but from
059: // client context
060: if (object instanceof COSDictionary) {
061: return PDOutlineItem.META;
062: }
063: return super .doDetermineClass(object);
064: }
065: }
066:
067: public static final COSName DK_A = COSName.constant("A"); //$NON-NLS-1$
068:
069: public static final COSName DK_C = COSName.constant("C"); //$NON-NLS-1$
070:
071: public static final COSName DK_Dest = COSName.constant("Dest"); //$NON-NLS-1$
072:
073: public static final COSName DK_F = COSName.constant("F"); //$NON-NLS-1$
074:
075: public static final COSName DK_Next = COSName.constant("Next"); //$NON-NLS-1$
076:
077: public static final COSName DK_Parent = COSName.constant("Parent"); //$NON-NLS-1$
078:
079: public static final COSName DK_Prev = COSName.constant("Prev"); //$NON-NLS-1$
080:
081: public static final COSName DK_SE = COSName.constant("SE"); //$NON-NLS-1$
082:
083: public static final COSName DK_Title = COSName.constant("Title"); //$NON-NLS-1$
084:
085: /** The meta class instance */
086: public static final MetaClass META = new MetaClass(MetaClass.class
087: .getDeclaringClass());
088:
089: protected PDOutlineItem(COSObject object) {
090: super (object);
091: }
092:
093: /**
094: * The flags as integer value.
095: *
096: * @return The flags as integer value.
097: */
098: public int basicGetFlags() {
099: return getFieldInt(DK_F, 0);
100: }
101:
102: /**
103: * Assign the flags from an integer value.
104: *
105: * @param value
106: * The new flags
107: */
108: public void basicSetFlags(int value) {
109: setFieldInt(DK_F, value);
110: }
111:
112: /**
113: * The color values to be used for this.
114: *
115: * @return The color values to be used for this.
116: */
117: public COSArray cosGetColor() {
118: return cosGetField(DK_C).asArray();
119: }
120:
121: /**
122: * The {@link PDAction} executed when the outline item is activated.
123: *
124: * @return The {@link PDAction} executed when the outline item is activated.
125: */
126: public PDAction getAction() {
127: return (PDAction) PDAction.META
128: .createFromCos(cosGetField(DK_A));
129: }
130:
131: /**
132: * The {@link PDDestination} to be displayed when the outline item is
133: * activated.
134: *
135: * @return The {@link PDDestination} to be displayed when the outline item
136: * is activated.
137: */
138: public PDDestination getDestination() {
139: return (PDDestination) PDDestination.META
140: .createFromCos(cosGetField(DK_Dest));
141: }
142:
143: /**
144: * The {@link OutlineItemFlags}.
145: *
146: * @return The {@link OutlineItemFlags}.
147: */
148: public OutlineItemFlags getFlags() {
149: return new OutlineItemFlags(this );
150: }
151:
152: /**
153: * The next {@link PDOutlineItem} within the items linked list.
154: *
155: * @return The next {@link PDOutlineItem} within the items linked list.
156: */
157: public PDOutlineItem getNext() {
158: return (PDOutlineItem) PDOutlineItem.META
159: .createFromCos(cosGetField(DK_Next));
160: }
161:
162: /**
163: * The parent item.
164: *
165: * @return The parent item.
166: */
167: public PDOutlineNode getParent() {
168: return (PDOutlineNode) PDOutlineNode.META
169: .createFromCos(cosGetField(DK_Parent));
170: }
171:
172: /**
173: * The previous {@link PDOutlineItem} within the items linked list.
174: *
175: * @return The previous {@link PDOutlineItem} within the items linked list.
176: */
177: public PDOutlineItem getPrev() {
178: return (PDOutlineItem) PDOutlineItem.META
179: .createFromCos(cosGetField(DK_Prev));
180: }
181:
182: /**
183: * The title to be displayed for this.
184: *
185: * @return The title to be displayed for this.
186: */
187: public String getTitle() {
188: return getFieldString(DK_Title, "");
189: }
190:
191: /**
192: * Assign the {@link PDAction} to be executed when the outline is activated.
193: *
194: * @param action
195: * The {@link PDAction} to be executed.
196: */
197: public void setAction(PDAction action) {
198: setFieldObject(DK_A, action);
199: }
200:
201: /**
202: * Assign the {@link PDDestination} to be displayed when the outline is
203: * activated.
204: *
205: * @param destination
206: * The {@link PDDestination} to be displayed.
207: */
208: public void setDestination(PDDestination destination) {
209: setFieldObject(DK_Dest, destination);
210: }
211:
212: protected void setNext(PDOutlineItem next) {
213: setFieldObject(DK_Next, next);
214: }
215:
216: protected void setParent(PDOutlineNode parent) {
217: setFieldObject(DK_Parent, parent);
218: }
219:
220: protected void setPrev(PDOutlineItem prev) {
221: setFieldObject(DK_Prev, prev);
222: }
223:
224: /**
225: * Assign the outline title
226: *
227: * @param title
228: * The new outline title.
229: */
230: public void setTitle(String title) {
231: setFieldString(DK_Title, title);
232: }
233: }
|