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 java.util.HashMap;
033: import java.util.Map;
034: import de.intarsys.pdf.cos.COSName;
035: import de.intarsys.pdf.cos.COSObject;
036:
037: /**
038: * An object defining the association of an event to an action for a PDF
039: * document object, for example a PDPage.
040: *
041: */
042: public class PDAdditionalActions extends PDObject {
043: /**
044: * The meta class implementation
045: */
046: static public class MetaClass extends PDObject.MetaClass {
047: protected MetaClass(Class instanceClass) {
048: super (instanceClass);
049: }
050: }
051:
052: static public final COSName CN_trigger_E = COSName.constant("E");
053:
054: static public final COSName CN_trigger_X = COSName.constant("X");
055:
056: static public final COSName CN_trigger_D = COSName.constant("D");
057:
058: static public final COSName CN_trigger_U = COSName.constant("U");
059:
060: static public final COSName CN_trigger_Fo = COSName.constant("Fo");
061:
062: static public final COSName CN_trigger_Bl = COSName.constant("Bl");
063:
064: static public final COSName CN_trigger_PO = COSName.constant("PO");
065:
066: static public final COSName CN_trigger_PC = COSName.constant("PC");
067:
068: static public final COSName CN_trigger_PV = COSName.constant("PV");
069:
070: static public final COSName CN_trigger_PI = COSName.constant("PI");
071:
072: static public final COSName CN_trigger_O = COSName.constant("O");
073:
074: static public final COSName CN_trigger_K = COSName.constant("K");
075:
076: static public final COSName CN_trigger_F = COSName.constant("F");
077:
078: static public final COSName CN_trigger_V = COSName.constant("V");
079:
080: static public final COSName CN_trigger_C = COSName.constant("C");
081:
082: static public final COSName CN_trigger_DC = COSName.constant("DC");
083:
084: /** WC is the same as DC - not specified, but used by acrobat */
085: static public final COSName CN_trigger_WC = COSName.constant("WC");
086:
087: static public final COSName CN_trigger_WS = COSName.constant("WS");
088:
089: static public final COSName CN_trigger_DS = COSName.constant("DS");
090:
091: static public final COSName CN_trigger_WP = COSName.constant("WP");
092:
093: static public final COSName CN_trigger_DP = COSName.constant("DP");
094:
095: static private Map reasonToName = new HashMap();
096:
097: static {
098: reasonToName.put(CN_trigger_K, "Keystroke");
099: reasonToName.put(CN_trigger_V, "Validate");
100: reasonToName.put(CN_trigger_Fo, "Focus");
101: reasonToName.put(CN_trigger_Bl, "Blur");
102: reasonToName.put(CN_trigger_F, "Format");
103: reasonToName.put(CN_trigger_C, "Calculate");
104: reasonToName.put(CN_trigger_U, "Mouse Up");
105: reasonToName.put(CN_trigger_D, "Mouse Down");
106: reasonToName.put(CN_trigger_E, "Mouse Enter");
107: reasonToName.put(CN_trigger_X, "Mouse Exit");
108: reasonToName.put(CN_trigger_WP, "WillPrint");
109: reasonToName.put(CN_trigger_DP, "DidPrint");
110: reasonToName.put(CN_trigger_WS, "WillSave");
111: reasonToName.put(CN_trigger_DS, "DidSave");
112: }
113:
114: static private Map reasonToType = new HashMap();
115:
116: static {
117: reasonToType.put(CN_trigger_K, "Field");
118: reasonToType.put(CN_trigger_V, "Field");
119: reasonToType.put(CN_trigger_Fo, "Field");
120: reasonToType.put(CN_trigger_Bl, "Field");
121: reasonToType.put(CN_trigger_F, "Field");
122: reasonToType.put(CN_trigger_C, "Field");
123: reasonToType.put(CN_trigger_U, "Field");
124: reasonToType.put(CN_trigger_D, "Field");
125: reasonToType.put(CN_trigger_E, "Field");
126: reasonToType.put(CN_trigger_X, "Field");
127: reasonToType.put(CN_trigger_WP, "Doc");
128: reasonToType.put(CN_trigger_DP, "Doc");
129: reasonToType.put(CN_trigger_WS, "Doc");
130: reasonToType.put(CN_trigger_DS, "Doc");
131: }
132:
133: static public final COSName CN_T_Mouse_Down = CN_trigger_D;
134:
135: /** The meta class instance */
136: static public final MetaClass META = new MetaClass(MetaClass.class
137: .getDeclaringClass());
138:
139: protected PDAdditionalActions(COSObject object) {
140: super (object);
141: }
142:
143: static public String getEventName(COSName reason) {
144: String result = (String) reasonToName.get(reason);
145: if (result == null) {
146: return "";
147: }
148: return result;
149: }
150:
151: static public String getEventType(COSName reason) {
152: String result = (String) reasonToType.get(reason);
153: if (result == null) {
154: return "";
155: }
156: return result;
157: }
158:
159: public PDAction getAction(COSName trigger) {
160: COSObject cosObject = cosGetField(trigger);
161: if (cosObject.isNull()) {
162: return null;
163: }
164: return (PDAction) PDAction.META.createFromCos(cosObject);
165: }
166:
167: public void addAction(COSName trigger, PDAction action) {
168: if ((trigger != null) && (action != null)) {
169: PDAction a = getAction(trigger);
170: if (a == null) {
171: cosSetField(trigger, action.cosGetDict());
172: } else {
173: a.addNext(action);
174: }
175: }
176: }
177:
178: public void setAction(COSName trigger, PDAction action) {
179: if (trigger == null) {
180: return;
181: }
182: setFieldObject(trigger, action);
183: }
184:
185: public void clearAction(COSName trigger) {
186: if (trigger != null) {
187: cosRemoveField(trigger);
188: }
189: }
190: }
|