Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.interactive.form » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.pdfbox.pdmodel.interactive.form;
   18   
   19   import org.apache.pdfbox.cos.COSArray;
   20   import org.apache.pdfbox.cos.COSDictionary;
   21   import org.apache.pdfbox.cos.COSName;
   22   import org.apache.pdfbox.cos.COSString;
   23   
   24   import org.apache.pdfbox.pdmodel.common.COSArrayList;
   25   
   26   import java.util.ArrayList;
   27   import java.util.List;
   28   
   29   /**
   30    * This holds common functionality for check boxes and radio buttons.
   31    *
   32    * @author sug
   33    * @version $Revision: 1.4 $
   34    */
   35   public abstract class PDChoiceButton extends PDField
   36   {
   37   
   38       /**
   39        * @see PDField#PDField(PDAcroForm,org.apache.pdfbox.cos.COSDictionary)
   40        *
   41        * @param theAcroForm The acroForm for this field.
   42        * @param field The field for this button.
   43        */
   44       public PDChoiceButton( PDAcroForm theAcroForm, COSDictionary field)
   45       {
   46           super(theAcroForm, field);
   47       }
   48   
   49       /**
   50        * This will get the option values "Opt" entry of the pdf button.
   51        *
   52        * @return A list of java.lang.String values.
   53        */
   54       public List getOptions()
   55       {
   56           List retval = null;
   57           COSArray array = (COSArray)getDictionary().getDictionaryObject( COSName.getPDFName( "Opt" ) );
   58           if( array != null )
   59           {
   60               List strings = new ArrayList();
   61               for( int i=0; i<array.size(); i++ )
   62               {
   63                   strings.add( ((COSString)array.getObject( i )).getString() );
   64               }
   65               retval = new COSArrayList( strings, array );
   66           }
   67           return retval;
   68       }
   69   
   70       /**
   71        * This will will set the list of options for this button.
   72        *
   73        * @param options The list of options for the button.
   74        */
   75       public void setOptions( List options )
   76       {
   77           getDictionary().setItem(
   78               COSName.getPDFName( "Opt" ),
   79               COSArrayList.converterToCOSArray( options ) );
   80       }
   81   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.interactive.form » [javadoc | source]