001: /*
002: Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.documents.interaction;
028:
029: import it.stefanochizzolini.clown.documents.Document;
030: import it.stefanochizzolini.clown.files.File;
031: import it.stefanochizzolini.clown.objects.PdfAtomicObject;
032: import it.stefanochizzolini.clown.objects.PdfBoolean;
033: import it.stefanochizzolini.clown.objects.PdfDictionary;
034: import it.stefanochizzolini.clown.objects.PdfDirectObject;
035: import it.stefanochizzolini.clown.objects.PdfIndirectObject;
036: import it.stefanochizzolini.clown.objects.PdfName;
037: import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
038: import it.stefanochizzolini.clown.util.NotImplementedException;
039:
040: /**
041: Viewer preferences [PDF:1.6:8.1].
042: */
043: public class ViewerPreferences extends PdfObjectWrapper<PdfDictionary> {
044: // <class>
045: // <dynamic>
046: // <constructors>
047: public ViewerPreferences(Document context) {
048: super (context.getFile(), new PdfDictionary());
049: }
050:
051: /**
052: <h3>Remarks</h3>
053: <p>For internal use only.</p>
054: */
055: public ViewerPreferences(PdfDirectObject baseObject,
056: PdfIndirectObject container) {
057: super (baseObject, container);
058: }
059:
060: // </constructors>
061:
062: // <interface>
063: // <public>
064: @Override
065: public ViewerPreferences clone(Document context) {
066: throw new NotImplementedException();
067: }
068:
069: public boolean getDisplayDocTitle() {
070: return this
071: .<Boolean, PdfBoolean> getEntry(PdfName.DisplayDocTitle);
072: }
073:
074: public boolean getHideMenubar() {
075: return this .<Boolean, PdfBoolean> getEntry(PdfName.HideMenubar);
076: }
077:
078: public boolean getHideToolbar() {
079: return this .<Boolean, PdfBoolean> getEntry(PdfName.HideToolbar);
080: }
081:
082: public boolean getHideWindowUI() {
083: return this
084: .<Boolean, PdfBoolean> getEntry(PdfName.HideWindowUI);
085: }
086:
087: public boolean getFitWindow() {
088: return this .<Boolean, PdfBoolean> getEntry(PdfName.FitWindow);
089: }
090:
091: public boolean getCenterWindow() {
092: return this
093: .<Boolean, PdfBoolean> getEntry(PdfName.CenterWindow);
094: }
095:
096: public void setDisplayDocTitle(boolean value) {
097: this .<Boolean, PdfBoolean> setEntry(PdfName.DisplayDocTitle,
098: value, PdfBoolean.class);
099: }
100:
101: public void setHideMenubar(boolean value) {
102: this .<Boolean, PdfBoolean> setEntry(PdfName.HideMenubar, value,
103: PdfBoolean.class);
104: }
105:
106: public void setHideToolbar(boolean value) {
107: this .<Boolean, PdfBoolean> setEntry(PdfName.HideToolbar, value,
108: PdfBoolean.class);
109: }
110:
111: public void setHideWindowUI(boolean value) {
112: this .<Boolean, PdfBoolean> setEntry(PdfName.HideWindowUI,
113: value, PdfBoolean.class);
114: }
115:
116: public void setFitWindow(boolean value) {
117: this .<Boolean, PdfBoolean> setEntry(PdfName.FitWindow, value,
118: PdfBoolean.class);
119: }
120:
121: public void setCenterWindow(boolean value) {
122: this .<Boolean, PdfBoolean> setEntry(PdfName.CenterWindow,
123: value, PdfBoolean.class);
124: }
125:
126: // </public>
127:
128: // <protected>
129: protected <T, TPdf extends PdfAtomicObject<T>> T getEntry(
130: PdfName key) {
131: TPdf entry = (TPdf) File.resolve(getBaseDataObject().get(key));
132: if (entry == null)
133: return null;
134:
135: return (T) entry.getValue();
136: }
137:
138: protected <T, TPdf extends PdfAtomicObject<T>> void setEntry(
139: PdfName key, T value, Class<TPdf> entryType // This Class<TPdf> parameter is an ugly workaround to the horrific generics type erasure that precludes full reflection over parameterized types.
140: ) {
141: TPdf entry = (TPdf) File.resolve(getBaseDataObject().get(key));
142: if (entry == null) {
143: try {
144: getBaseDataObject().put(key,
145: entry = entryType.newInstance());
146: } catch (Exception e) {
147: throw new RuntimeException(e);
148: }
149: }
150:
151: entry.setValue(value);
152: }
153: // </protected>
154: // </interface>
155: // </dynamic>
156: // </class>
157: }
|