You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2017/05/05 14:35:40 UTC

svn commit: r1794061 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java

Author: msahyoun
Date: Fri May  5 14:35:39 2017
New Revision: 1794061

URL: http://svn.apache.org/viewvc?rev=1794061&view=rev
Log:
PDFBOX-3753: set the radio button value by the index of the widget the /Opts entry refers to.

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1794061&r1=1794060&r2=1794061&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java Fri May  5 14:35:39 2017
@@ -310,25 +310,48 @@ public abstract class PDButton extends P
         List<PDAnnotationWidget> widgets = this.getWidgets();
         for (PDAnnotationWidget widget : widgets)
         {
-            PDAppearanceDictionary apDictionary = widget.getAppearance();
-            if (apDictionary != null) 
+        	onValues.add(getOnValueForWidget(widget));
+        }        
+        return onValues;
+    }
+    
+    /*
+     * Get the on value for an individual widget by it's index.
+     */
+    private String getOnValue(int index)
+    {
+        List<PDAnnotationWidget> widgets = this.getWidgets();
+        if (index < widgets.size())
+        {
+            return getOnValueForWidget(widgets.get(index));
+        }
+        return "";
+    }
+ 
+    /*
+     * Get the on value for an individual widget.
+     */
+    private String getOnValueForWidget(PDAnnotationWidget widget)
+    {
+        PDAppearanceDictionary apDictionary = widget.getAppearance();
+        if (apDictionary != null) 
+        {
+            PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance();
+            if (normalAppearance != null)
             {
-                PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance();
-                if (normalAppearance != null)
+                Set<COSName> entries = normalAppearance.getSubDictionary().keySet();
+                for (COSName entry : entries)
                 {
-                    Set<COSName> entries = normalAppearance.getSubDictionary().keySet();
-                    for (COSName entry : entries)
+                    if (COSName.Off.compareTo(entry) != 0)
                     {
-                        if (COSName.Off.compareTo(entry) != 0)
-                        {
-                            onValues.add(entry.getName());
-                        }
+                        return entry.getName();
                     }
                 }
             }
-        }        
-        return onValues;
-    }
+        }
+        return "";
+    }    
+    
     
     /**
      * Checks value.
@@ -389,8 +412,7 @@ public abstract class PDButton extends P
             // see PDFBOX-3682
             if (optionsIndex != -1)
             {
-                String[] onValues = getOnValues().toArray(new String[getOnValues().size()]);
-                updateByValue(onValues[optionsIndex]);
+                updateByValue(getOnValue(optionsIndex));
             }
         }
     }