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 2015/01/17 18:05:53 UTC

svn commit: r1652643 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java

Author: msahyoun
Date: Sat Jan 17 17:05:53 2015
New Revision: 1652643

URL: http://svn.apache.org/r1652643
Log:
PDFBOX-2516 correct handling of Edit field flag

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java?rev=1652643&r1=1652642&r2=1652643&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java Sat Jan 17 17:05:53 2015
@@ -16,8 +16,6 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.form;
 
-import java.util.List;
-
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 
@@ -66,32 +64,33 @@ public final class PDComboBox extends PD
     }
 
     /**
-     * setValue sets the entry "V" to the given value.
+     * Sets the field value - the 'V' key.
      * 
      * @param value the value
-     * 
      */
+    @Override
     public void setValue(String value)
     {
-        if ((getFieldFlags() & FLAG_EDIT) != 0)
+        if (value != null)
         {
-            throw new IllegalArgumentException("The combo box isn't editable.");
+            // check if the options contain the value to be set is
+            // only necessary if the edit flag has not been set.
+            // If the edit flag has been set the field allows a custom value.
+            if (!isEdit() && getOptions().indexOf((String) value) == -1)
+            {
+                throw new IllegalArgumentException("The list box does not contain the given value.");
+            }
+            else
+            {
+                getDictionary().setString(COSName.V, (String)value);
+                // remove I key for single valued choice field
+                setSelectedOptionsIndex(null);
+            }
         }
-        super.setValue(value);
-    }
-
-    /**
-     * setValue sets the entry "V" to the given value.
-     * 
-     * @param values the value
-     * 
-     */
-    public void setValue(List<String> values)
-    {
-        if ((getFieldFlags() & FLAG_EDIT) != 0)
+        else
         {
-            throw new IllegalArgumentException("The combo box isn't editable.");
+            getDictionary().removeItem(COSName.V);
         }
-        super.setValue(values);
-    }    
+        // TODO create/update appearance
+    }
 }