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.Iterator;
033:
034: /**
035: * The flags of a field in an acrobat form.
036: * <p>
037: * The flags are bits of an integer.<br>
038: * The following bits are defined (more may exist).
039: * </p>
040: * <ul>
041: * <li>0: default
042: * <li>1: Readonly
043: * <li>2: Required
044: * <li>3: NoExport
045: * <li>13: Multiline
046: * <li>14: Password
047: * <li>15: NoToggleToOff
048: * <li>16: Radio
049: * <li>17: Pushbutton
050: * <li>18: Combo
051: * <li>19: Edit
052: * <li>20: Sort
053: * <li>21: FileSelect
054: * <li>22: MulitSelect
055: * <li>23: DoNotSpellChec
056: * <li>24: DoNotScroll
057: * <li>25: Comb
058: * <li>26: RadiosInUnison
059: * <li>27: CommitOnSelChange
060: * <li>28: RichText
061: * </ul>
062: */
063: public class AcroFormFieldFlags extends AbstractBitFlags {
064: final public static int Bit_ReadOnly = 1; // Bit position 1
065:
066: final public static int Bit_Required = 1 << 1; // Bit position 2
067:
068: final public static int Bit_NoExport = 1 << 2; // Bit position 3
069:
070: final public static int Bit_Multiline = 1 << 12;
071:
072: final public static int Bit_Password = 1 << 13;
073:
074: final public static int Bit_NoToggleToOff = 1 << 14;
075:
076: final public static int Bit_Radio = 1 << 15;
077:
078: final public static int Bit_Pushbutton = 1 << 16;
079:
080: final public static int Bit_Combo = 1 << 17;
081:
082: final public static int Bit_Edit = 1 << 18;
083:
084: final public static int Bit_Sort = 1 << 19;
085:
086: final public static int Bit_FileSelect = 1 << 20;
087:
088: final public static int Bit_MultiSelect = 1 << 21;
089:
090: final public static int Bit_DoNotSpellCheck = 1 << 22;
091:
092: final public static int Bit_DoNotScroll = 1 << 23;
093:
094: final public static int Bit_Comb = 1 << 24;
095:
096: final public static int Bit_RadiosInUnison = 1 << 25;
097:
098: final public static int Bit_CommitOnSelChange = 1 << 26;
099:
100: final public static int Bit_RichText = 1 << 27;
101:
102: private PDAcroFormField field;
103:
104: public AcroFormFieldFlags(PDAcroFormField field) {
105: this .field = field;
106: }
107:
108: public void setCombo(boolean f) {
109: set(Bit_Combo, f);
110: }
111:
112: public boolean isCombo() {
113: return isSetAnd(Bit_Combo);
114: }
115:
116: public boolean isEdit() {
117: return isSetAnd(Bit_Edit);
118: }
119:
120: public void setEdit(boolean edit) {
121: set(Bit_Edit, edit);
122: }
123:
124: public boolean isCommitOnSelChange() {
125: return isSetAnd(Bit_CommitOnSelChange);
126: }
127:
128: public void setCommitOnSelChange(boolean f) {
129: set(Bit_CommitOnSelChange, f);
130: }
131:
132: public void setDoNotScroll(boolean f) {
133: set(Bit_DoNotScroll, f);
134: }
135:
136: public void setComb(boolean f) {
137: set(Bit_Comb, f);
138: }
139:
140: public boolean isDoNotScroll() {
141: return isSetAnd(Bit_DoNotScroll);
142: }
143:
144: public boolean isComb() {
145: return isSetAnd(Bit_Comb);
146: }
147:
148: public boolean isMultiSelect() {
149: return isSetAnd(Bit_MultiSelect);
150: }
151:
152: public void setMultiSelect(boolean multiSelect) {
153: set(Bit_MultiSelect, multiSelect);
154: }
155:
156: public void setMultiline(boolean f) {
157: set(Bit_Multiline, f);
158: }
159:
160: public boolean isMultiline() {
161: return isSetAnd(Bit_Multiline);
162: }
163:
164: public boolean isPassword() {
165: return isSetAnd(Bit_Password);
166: }
167:
168: public boolean isFileSelect() {
169: return isSetAnd(Bit_FileSelect);
170: }
171:
172: public void setNoExport(boolean f) {
173: set(Bit_NoExport, f);
174: }
175:
176: public boolean isNoExport() {
177: return isSetAnd(Bit_NoExport);
178: }
179:
180: public boolean isNoToggleOff() {
181: return isSetAnd(Bit_NoToggleToOff);
182: }
183:
184: public void setNoToggleToOff(boolean noToggleToOff) {
185: set(Bit_NoToggleToOff, noToggleToOff);
186: }
187:
188: public void setPushbutton(boolean f) {
189: set(Bit_Pushbutton, f);
190: }
191:
192: public boolean isPushbutton() {
193: return isSetAnd(Bit_Pushbutton);
194: }
195:
196: public void setPassword(boolean f) {
197: set(Bit_Password, f);
198: }
199:
200: public void setFileSelect(boolean f) {
201: set(Bit_FileSelect, f);
202: }
203:
204: public void setRadio(boolean f) {
205: set(Bit_Radio, f);
206: }
207:
208: public boolean isRadio() {
209: return isSetAnd(Bit_Radio);
210: }
211:
212: public boolean isRadiosInUnison() {
213: return isSetAnd(Bit_RadiosInUnison);
214: }
215:
216: public void setReadOnly(boolean f) {
217: set(Bit_ReadOnly, f);
218: }
219:
220: public void setRequired(boolean f) {
221: set(Bit_Required, f);
222: }
223:
224: public boolean isReadOnly() {
225: return isSetAnd(Bit_ReadOnly);
226: }
227:
228: public boolean isRequired() {
229: return isSetAnd(Bit_Required);
230: }
231:
232: public int getValue() {
233: return getField().basicGetFieldFlags();
234: }
235:
236: protected PDAcroFormField getField() {
237: return field;
238: }
239:
240: protected void setValue(int newFlags) {
241: getField().basicSetFieldFlags(newFlags);
242: }
243:
244: /*
245: * (non-Javadoc)
246: *
247: * @see de.intarsys.pdf.pd.AbstractBitFlags#set(int, boolean)
248: */
249: protected void set(int bitMask, boolean flag) {
250: super .set(bitMask, flag);
251: if (getField().getKids() != null) {
252: for (Iterator i = getField().getKids().iterator(); i
253: .hasNext();) {
254: PDAcroFormField kid = (PDAcroFormField) i.next();
255: kid.getFieldFlags().set(bitMask, flag);
256: }
257: }
258: }
259: }
|