1 31 package org.pdfbox.pdmodel.interactive.form; 32 33 import java.io.IOException ; 34 import java.util.ArrayList ; 35 import java.util.List ; 36 37 import org.pdfbox.cos.COSArray; 38 import org.pdfbox.cos.COSDictionary; 39 import org.pdfbox.cos.COSName; 40 41 import org.pdfbox.pdmodel.common.COSArrayList; 42 import org.pdfbox.util.BitFlagHelper; 43 44 53 public class PDRadioCollection extends PDChoiceButton 54 { 55 58 public static final int FLAG_RADIOS_IN_UNISON = 1 << 25; 59 60 66 public PDRadioCollection( PDAcroForm theAcroForm, COSDictionary field) 67 { 68 super(theAcroForm,field); 69 } 70 71 80 public void setRadiosInUnison(boolean radiosInUnison) 81 { 82 BitFlagHelper.setFlag( getDictionary(), "Ff", FLAG_RADIOS_IN_UNISON, radiosInUnison ); 83 } 84 85 89 public boolean isRadiosInUnison() 90 { 91 return BitFlagHelper.getFlag( getDictionary(), "Ff", FLAG_RADIOS_IN_UNISON ); 92 } 93 94 103 public void setValue(String value) throws IOException 104 { 105 getDictionary().setString( "V", value ); 106 List kids = getKids(); 107 for (int i = 0; i < kids.size(); i++) 108 { 109 PDCheckbox btn = (PDCheckbox)kids.get(i); 110 if( btn.getOnValue().equals(value) ) 111 { 112 btn.check(); 113 } 114 else 115 { 116 btn.unCheck(); 117 } 118 } 119 } 120 121 128 public String getValue()throws IOException 129 { 130 String retval = null; 131 List kids = getKids(); 132 for (int i = 0; i < kids.size(); i++) 133 { 134 PDCheckbox btn = (PDCheckbox)kids.get(i); 135 if( btn.isChecked() ) 136 { 137 retval = btn.getOnValue(); 138 } 139 } 140 if( retval == null ) 141 { 142 retval = getDictionary().getNameAsString( "V" ); 143 } 144 return retval; 145 } 146 147 148 155 public List getKids() throws IOException 156 { 157 List retval = null; 158 COSArray kids = (COSArray)getDictionary().getDictionaryObject(COSName.KIDS); 159 if( kids != null ) 160 { 161 List kidsList = new ArrayList (); 162 for (int i = 0; i < kids.size(); i++) 163 { 164 kidsList.add( PDFieldFactory.createField( getAcroForm(), (COSDictionary)kids.getObject(i) ) ); 165 } 166 retval = new COSArrayList( kidsList, kids ); 167 } 168 return retval; 169 } 170 } | Popular Tags |