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.COSBasedObject;
033: import de.intarsys.pdf.cos.COSName;
034: import de.intarsys.pdf.cos.COSObject;
035: import de.intarsys.pdf.cos.COSStream;
036:
037: /**
038: * More details on the appearance of an annotation.
039: *
040: */
041: public class PDAppearanceCharacteristics extends PDObject {
042: /**
043: * The meta class implementation
044: */
045: static public class MetaClass extends PDObject.MetaClass {
046: protected MetaClass(Class instanceClass) {
047: super (instanceClass);
048: }
049:
050: protected COSBasedObject doCreateCOSBasedObject(COSObject object) {
051: return new PDAppearanceCharacteristics(object);
052: }
053:
054: protected boolean isIndirect() {
055: return false;
056: }
057: }
058:
059: static public final COSName DK_AC = COSName.constant("AC"); //$NON-NLS-1$
060:
061: static public final COSName DK_BC = COSName.constant("BC"); //$NON-NLS-1$
062:
063: static public final COSName DK_BG = COSName.constant("BG"); //$NON-NLS-1$
064:
065: static public final COSName DK_CA = COSName.constant("CA"); //$NON-NLS-1$
066:
067: static public final COSName DK_I = COSName.constant("I"); //$NON-NLS-1$
068:
069: static public final COSName DK_IF = COSName.constant("IF"); //$NON-NLS-1$
070:
071: static public final COSName DK_IX = COSName.constant("IX"); //$NON-NLS-1$
072:
073: static public final COSName DK_R = COSName.constant("R"); //$NON-NLS-1$
074:
075: static public final COSName DK_RC = COSName.constant("RC"); //$NON-NLS-1$
076:
077: static public final COSName DK_RI = COSName.constant("RI"); //$NON-NLS-1$
078:
079: static public final int TP_CAPTION_ONLY = 0;
080:
081: static public final int TP_ICON_ONLY = 1;
082:
083: static public final int TP_CAPTION_BELOW_ICON = 2;
084:
085: static public final int TP_CAPTION_ABOVE_ICON = 3;
086:
087: static public final int TP_CAPTION_RIGHT_OF_ICON = 4;
088:
089: static public final int TP_CAPTION_LEFT_OF_ICON = 5;
090:
091: static public final int TP_CAPTION_OVERLAIS_ICON = 6;
092:
093: /**
094: * The name for the caption entry.
095: * <p>
096: * The name could have following values (not complete):
097: * </p>
098: * <ul>
099: * <li>0: No icon, caption only
100: * <li>1: No caption; icon only
101: * <li>2: Caption below the icon
102: * <li>3: Caption above the icon
103: * <li>4: Caption to the right of the icon
104: * <li>5: Caption to the left of the icon
105: * <li>6: Caption overlaid directly on the icon
106: * </ul>
107: */
108: static public final COSName DK_TP = COSName.constant("TP"); //$NON-NLS-1$
109:
110: /** The meta class instance */
111: static public final MetaClass META = new MetaClass(MetaClass.class
112: .getDeclaringClass());
113:
114: protected PDAppearanceCharacteristics(COSObject object) {
115: super (object);
116: }
117:
118: public float[] getBackgroundColor() {
119: return getFieldFixedArray(DK_BG, null);
120: }
121:
122: public float[] getBorderColor() {
123: return getFieldFixedArray(DK_BC, null);
124: }
125:
126: public String getDownCaption() {
127: return getFieldString(DK_AC, null);
128: }
129:
130: public COSStream cosGetDownIcon() {
131: return cosGetField(DK_IX).asStream();
132: }
133:
134: public PDIconFit getIconFit() {
135: COSObject cosObject = cosGetField(DK_IF);
136: if (cosObject.isNull()) {
137: return null;
138: }
139: return (PDIconFit) PDIconFit.META.createFromCos(cosObject);
140: }
141:
142: public String getNormalCaption() {
143: return getFieldString(DK_CA, null);
144: }
145:
146: public COSStream cosGetNormalIcon() {
147: return cosGetField(DK_I).asStream();
148: }
149:
150: public int getTextPosition() {
151: return getFieldInt(DK_TP, TP_CAPTION_ONLY);
152: }
153:
154: public String getRolloverCaption() {
155: return getFieldString(DK_RC, null);
156: }
157:
158: public COSStream cosGetRolloverIcon() {
159: return cosGetField(DK_RI).asStream();
160: }
161:
162: public int getRotation() {
163: return getFieldInt(DK_R, 0);
164: }
165:
166: public void setBackgroundColor(float[] newBackgroundColor) {
167: setFieldFixedArray(DK_BG, newBackgroundColor);
168: }
169:
170: public void setBorderColor(float[] newBorderColor) {
171: setFieldFixedArray(DK_BC, newBorderColor);
172: }
173:
174: public void setDownCaption(String newDownCaption) {
175: setFieldString(DK_AC, newDownCaption);
176: }
177:
178: public COSStream cosSetDownIcon(COSStream newDownIcon) {
179: return cosSetField(DK_IX, newDownIcon).asStream();
180: }
181:
182: public void setIconFit(PDIconFit newIconFit) {
183: setFieldObject(DK_IF, newIconFit);
184: }
185:
186: public void setNormalCaption(String newNormalCaption) {
187: setFieldString(DK_CA, newNormalCaption);
188: }
189:
190: public COSStream cosSetNormalIcon(COSStream newNormalIcon) {
191: return cosSetField(DK_I, newNormalIcon).asStream();
192: }
193:
194: public void setTextPosition(int newPositionTextIcon) {
195: if (newPositionTextIcon != TP_CAPTION_ONLY) { // default
196: setFieldInt(DK_TP, newPositionTextIcon);
197: } else {
198: cosRemoveField(DK_TP);
199: }
200: }
201:
202: public void setRolloverCaption(String newRolloverCaption) {
203: setFieldString(DK_RC, newRolloverCaption);
204: }
205:
206: public COSStream cosSetRolloverIcon(COSStream newRolloverIcon) {
207: return cosSetField(DK_RI, newRolloverIcon).asStream();
208: }
209:
210: public void setRotation(int newRotation) {
211: if (newRotation != 0) {
212: setFieldInt(DK_R, newRotation);
213: } else {
214: cosRemoveField(DK_R);
215: }
216: }
217: }
|