1 package com.lowagie.text.pdf.collection; 2 3 import com.lowagie.text.pdf.PdfBoolean; 4 import com.lowagie.text.pdf.PdfDate; 5 import com.lowagie.text.pdf.PdfDictionary; 6 import com.lowagie.text.pdf.PdfName; 7 import com.lowagie.text.pdf.PdfNumber; 8 import com.lowagie.text.pdf.PdfObject; 9 import com.lowagie.text.pdf.PdfString; 10 11 15 public class PdfCollectionField extends PdfDictionary { 16 17 public static final int TEXT = 0; 18 19 public static final int DATE = 1; 20 21 public static final int NUMBER = 2; 22 23 public static final int FILENAME = 3; 24 25 public static final int DESC = 4; 26 27 public static final int MODDATE = 5; 28 29 public static final int CREATIONDATE = 6; 30 31 public static final int SIZE = 7; 32 33 34 protected int type; 35 36 41 public PdfCollectionField(String name, int type) { 42 super(PdfName.COLLECTIONFIELD); 43 put(PdfName.N, new PdfString(name, PdfObject.TEXT_UNICODE)); 44 this.type = type; 45 switch(type) { 46 default: 47 put(PdfName.SUBTYPE, PdfName.S); 48 break; 49 case DATE: 50 put(PdfName.SUBTYPE, PdfName.D); 51 break; 52 case NUMBER: 53 put(PdfName.SUBTYPE, PdfName.N); 54 break; 55 case FILENAME: 56 put(PdfName.SUBTYPE, PdfName.F); 57 break; 58 case DESC: 59 put(PdfName.SUBTYPE, PdfName.DESC); 60 break; 61 case MODDATE: 62 put(PdfName.SUBTYPE, PdfName.MODDATE); 63 break; 64 case CREATIONDATE: 65 put(PdfName.SUBTYPE, PdfName.CREATIONDATE); 66 break; 67 case SIZE: 68 put(PdfName.SUBTYPE, PdfName.SIZE); 69 break; 70 } 71 } 72 73 77 public void setOrder(int i) { 78 put(PdfName.O, new PdfNumber(i)); 79 } 80 81 85 public void setVisible(boolean visible) { 86 put(PdfName.V, new PdfBoolean(visible)); 87 } 88 89 93 public void setEditable(boolean editable) { 94 put(PdfName.E, new PdfBoolean(editable)); 95 } 96 97 100 public boolean isCollectionItem() { 101 switch(type) { 102 case TEXT: 103 case DATE: 104 case NUMBER: 105 return true; 106 default: 107 return false; 108 } 109 } 110 111 115 public PdfObject getValue(String v) { 116 switch(type) { 117 case TEXT: 118 return new PdfString(v, PdfObject.TEXT_UNICODE); 119 case DATE: 120 return new PdfDate(PdfDate.decode(v)); 121 case NUMBER: 122 return new PdfNumber(v); 123 } 124 throw new IllegalArgumentException (v + " is not an acceptable value for the field " + get(PdfName.N).toString()); 125 } 126 } | Popular Tags |