pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1620405 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form: PDChoice.java PDComboBox.java PDListBox.java
Date Mon, 25 Aug 2014 18:33:11 GMT
Author: lehmi
Date: Mon Aug 25 18:33:10 2014
New Revision: 1620405

URL: http://svn.apache.org/r1620405
Log:
PDFBOX-2261: added choice specific field flags, support multiple values for V

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java?rev=1620405&r1=1620404&r2=1620405&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
Mon Aug 25 18:33:10 2014
@@ -123,6 +123,109 @@ public abstract class PDChoice extends P
         }
     }
 
+    /**
+     * Determines if Sort is set.
+     * 
+     * @return true if the options are sorted.
+     */
+    public boolean isSort()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_SORT );
+    }
+
+    /**
+     * Set the Sort bit.
+     *
+     * @param sort The value for Sort.
+     */
+    public void setSort( boolean sort )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_SORT, sort );
+    }
+
+    /**
+     * Determines if MultiSelect is set.
+     * 
+     * @return true if multi select is allowed.
+     */
+    public boolean isMultiSelect()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_MULTI_SELECT );
+    }
+
+    /**
+     * Set the MultiSelect bit.
+     *
+     * @param multiSelect The value for MultiSelect.
+     */
+    public void setMultiSelect( boolean multiSelect )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_MULTI_SELECT, multiSelect );
+    }
+
+    /**
+     * Determines if DoNotSpellCheck is set.
+     * 
+     * @return true if spell checker is disabled.
+     */
+    public boolean isDoNotSpellCheck()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_DO_NOT_SPELL_CHECK );
+    }
+
+    /**
+     * Set the DoNotSpellCheck bit.
+     *
+     * @param doNotSpellCheck The value for DoNotSpellCheck.
+     */
+    public void setDoNotSpellCheck( boolean doNotSpellCheck )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_DO_NOT_SPELL_CHECK, doNotSpellCheck );
+    }
+
+    /**
+     * Determines if CommitOnSelChange is set.
+     * 
+     * @return true if value shall be committed as soon as a selection is made.
+     */
+    public boolean isCommitOnSelChange()
+    {
+        return getDictionary().getFlag( COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE );
+    }
+
+    /**
+     * Set the CommitOnSelChange bit.
+     *
+     * @param commitOnSelChange The value for CommitOnSelChange.
+     */
+    public void setCommitOnSelChange( boolean commitOnSelChange )
+    {
+        getDictionary().setFlag( COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE, commitOnSelChange
);
+    }
+
+    /**
+     * getValue gets the value of the "V" entry.
+     * 
+     * @return The value of this entry.
+     * 
+     */
+    @Override
+    public COSArray getValue()
+    {
+        COSBase value = getDictionary().getDictionaryObject( COSName.V);
+        if (value instanceof COSString)
+        {
+            COSArray array = new COSArray();
+            array.add(value);
+            return array;
+        }
+        else if (value instanceof COSArray)
+        {
+            return (COSArray)value;
+        }
+        return null;
+    }
+
     // returns the "Opt" index for the given string
     protected int getSelectedIndex(String optionValue)
     {

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=1620405&r1=1620404&r2=1620405&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
Mon Aug 25 18:33:10 2014
@@ -17,7 +17,6 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
@@ -43,29 +42,6 @@ public final class PDComboBox extends PD
     }
 
     /**
-     * getValue gets the value of the "V" entry.
-     * 
-     * @return The value of this entry.
-     * 
-     */
-    @Override
-    public COSArray getValue()
-    {
-        COSBase value = getDictionary().getDictionaryObject( COSName.V);
-        if (value instanceof COSString)
-        {
-            COSArray array = new COSArray();
-            array.add(value);
-            return array;
-        }
-        else if (value instanceof COSArray)
-        {
-            return (COSArray)value;
-        }
-        return null;
-    }
-
-    /**
      * setValue sets the entry "V" to the given value.
      * 
      * @param value the value
@@ -74,6 +50,7 @@ public final class PDComboBox extends PD
     @Override
     public void setValue(Object value)
     {
+        // TODO move to superclass PDCoice??
         if ((getFieldFlags() & FLAG_EDIT) != 0)
         {
             throw new IllegalArgumentException("The combo box isn't editable.");
@@ -82,6 +59,7 @@ public final class PDComboBox extends PD
         {
             if (value instanceof String)
             {
+                getDictionary().setString(COSName.V, (String)value);
                 int index = getSelectedIndex((String)value);
                 if (index == -1)
                 {
@@ -91,7 +69,17 @@ public final class PDComboBox extends PD
             }
             if (value instanceof String[])
             {
-                // TODO multiple values
+                if (!isMultiSelect())
+                {
+                    throw new IllegalArgumentException("The combo box does allow multiple
selection.");
+                }
+                String[] stringValues = (String[])value;
+                COSArray stringArray = new COSArray();
+                for (int i =0; i<stringValues.length;i++)
+                {
+                    stringArray.add(new COSString(stringValues[i]));
+                }
+                getDictionary().setItem(COSName.V, stringArray);
             }
         }
         else

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java?rev=1620405&r1=1620404&r2=1620405&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
Mon Aug 25 18:33:10 2014
@@ -17,7 +17,6 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
@@ -42,29 +41,6 @@ public final class PDListBox extends PDC
     }
 
     /**
-     * getValue gets the value of the "V" entry.
-     * 
-     * @return The value of this entry.
-     * 
-     */
-    @Override
-    public COSArray getValue()
-    {
-        COSBase value = getDictionary().getDictionaryObject(COSName.V);
-        if (value instanceof COSString)
-        {
-            COSArray array = new COSArray();
-            array.add(value);
-            return array;
-        }
-        else if (value instanceof COSArray)
-        {
-            return (COSArray) value;
-        }
-        return null;
-    }
-
-    /**
      * setValue sets the entry "V" to the given value.
      * 
      * @param value the value
@@ -73,25 +49,37 @@ public final class PDListBox extends PDC
     @Override
     public void setValue(Object value)
     {
+        // TODO move to superclass PDCoice??
         if ((getFieldFlags() & FLAG_EDIT) != 0)
         {
-            throw new IllegalArgumentException("The combo box isn't editable.");
+            throw new IllegalArgumentException("The list box isn't editable.");
         }
         if (value != null)
         {
             if (value instanceof String)
             {
+                getDictionary().setString(COSName.V, (String)value);
                 int index = getSelectedIndex((String) value);
                 if (index == -1)
                 {
                     throw new IllegalArgumentException(
-                            "The combo box does not contain the given value.");
+                            "The list box does not contain the given value.");
                 }
                 selectMultiple(index);
             }
             if (value instanceof String[])
             {
-                // TODO multiple values
+                if (!isMultiSelect())
+                {
+                    throw new IllegalArgumentException("The list box does allow multiple
selection.");
+                }
+                String[] stringValues = (String[])value;
+                COSArray stringArray = new COSArray();
+                for (int i =0; i<stringValues.length;i++)
+                {
+                    stringArray.add(new COSString(stringValues[i]));
+                }
+                getDictionary().setItem(COSName.V, stringArray);
             }
         }
         else



Mime
View raw message