pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1688685 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
Date Wed, 01 Jul 2015 16:38:18 GMT
Author: msahyoun
Date: Wed Jul  1 16:38:18 2015
New Revision: 1688685

URL: http://svn.apache.org/r1688685
Log:
PDFBOX-2849, PDFBOX-2841: get potential On values for radio buttons

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1688685&r1=1688684&r2=1688685&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Wed Jul  1 16:38:18 2015
@@ -17,12 +17,16 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
+
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry;
 
 /**
@@ -208,4 +212,46 @@ public final class PDRadioButton extends
     {
         dictionary.setName(COSName.DV, value);
     }
+    
+    
+    /**
+     * Get the List of values to set individual radio buttons to the on state.
+     * 
+     * <p>The On value could be an arbitrary string as long as it is within the limitations
of
+     * a PDF name object. The Off value shall always be 'Off'. If not set or not part of
the normal
+     * appearance keys 'Off' is the default</p>
+     *
+     * @returns the value setting the check box to the On state. 
+     *          If an empty string is returned there is no appearance definition.
+     * @throws IOException if the value could not be set
+     */
+    public List<String> getOnValues()
+    {
+        List<PDAnnotationWidget> widgets = this.getWidgets();
+        ArrayList<String> onValues = new ArrayList<String>();
+        
+        for (PDAnnotationWidget widget : widgets)
+        {
+            PDAppearanceDictionary apDictionary = widget.getAppearance();
+            
+            if (apDictionary != null) 
+            {
+                PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance();
+                if (normalAppearance != null)
+                {
+                    Set<COSName> entries = normalAppearance.getSubDictionary().keySet();
+                    for (COSName entry : entries)
+                    {
+                        if (COSName.Off.compareTo(entry) != 0)
+                        {
+                            onValues.add(entry.getName());
+                        }
+                    }
+                }
+            }
+        }
+        return onValues;
+    }
+    
+    
 }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java?rev=1688685&r1=1688684&r2=1688685&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java
Wed Jul  1 16:38:18 2015
@@ -128,6 +128,17 @@ public class PDButtonTest
     
     }
     
+    
+    @Test
+    public void testAcrobatradioButtonProperties() throws IOException
+    {
+        PDRadioButton radioButton = (PDRadioButton) acrobatAcroForm.getField("RadioButtonGroup");
+        assertEquals(radioButton.getOnValues().size(),2);
+        assertEquals(radioButton.getOnValues().get(0),"RadioButton01");
+        assertEquals(radioButton.getOnValues().get(1),"RadioButton02");
+    }
+    
+    
     @After
     public void tearDown() throws IOException
     {



Mime
View raw message