You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/08/24 19:42:23 UTC
svn commit: r1620169 - in /pdfbox/trunk:
examples/src/main/java/org/apache/pdfbox/examples/fdf/
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/
pdfbox/src/test/java/org/apache/pdfbox/pdmodel/
Author: lehmi
Date: Sun Aug 24 17:42:22 2014
New Revision: 1620169
URL: http://svn.apache.org/r1620169
Log:
PDFBOX-2261: overhauled get/setValue
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
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/PDFieldTreeNode.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java Sun Aug 24 17:42:22 2014
@@ -99,7 +99,14 @@ public class PrintFields
}
else
{
- fieldValue = field.getValue();
+ if (field.getValue() != null)
+ {
+ fieldValue = field.getValue().toString();
+ }
+ else
+ {
+ fieldValue = "";
+ }
}
String outputString = sLevel + sParent + "." + partialName + " = " + fieldValue + ", type="
+ field.getClass().getName();
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java Sun Aug 24 17:42:22 2014
@@ -79,7 +79,7 @@ public final class PDAppearanceString
* @param field the field which you wish to control the appearance of
* @throws IOException If there is an error creating the appearance.
*/
- public PDAppearanceString(PDAcroForm theAcroForm, PDVariableText field) throws IOException
+ public PDAppearanceString(PDAcroForm theAcroForm, PDVariableText field)
{
acroForm = theAcroForm;
parent = field;
@@ -90,10 +90,7 @@ public final class PDAppearanceString
widgets = new ArrayList<COSObjectable>();
widgets.add( field.getWidget() );
}
-
defaultAppearance = getDefaultAppearance();
-
-
}
/**
@@ -199,7 +196,7 @@ public final class PDAppearanceString
/**
* This is the public method for setting the appearance stream.
*
- * @param apValue the String value which the apperance shoud represent
+ * @param apValue the String value which the appearance should represent
*
* @throws IOException If there is an error creating the stream.
*/
@@ -243,8 +240,8 @@ public final class PDAppearanceString
widget.setAppearance( appearance );
}
- Map normalAppearance = appearance.getNormalAppearance();
- PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
+ Map<String,PDAppearanceStream> normalAppearance = appearance.getNormalAppearance();
+ PDAppearanceStream appearanceStream = normalAppearance.get( "default" );
if( appearanceStream == null )
{
COSStream cosStream = acroForm.getDocument().getDocument().createCOSStream();
@@ -253,8 +250,8 @@ public final class PDAppearanceString
appearance.setNormalAppearance( appearanceStream );
}
- List tokens = getStreamTokens( appearanceStream );
- List daTokens = getStreamTokens( getDefaultAppearance() );
+ List<Object> tokens = getStreamTokens( appearanceStream );
+ List<Object> daTokens = getStreamTokens( getDefaultAppearance() );
PDFont pdFont = getFontAndUpdateResources( tokens, appearanceStream );
if (!containsMarkedContent( tokens ))
@@ -341,7 +338,7 @@ public final class PDAppearanceString
}
private void insertGeneratedAppearance( PDAnnotationWidget fieldWidget, OutputStream output,
- PDFont pdFont, List tokens, PDAppearanceStream appearanceStream ) throws IOException
+ PDFont pdFont, List<Object> tokens, PDAppearanceStream appearanceStream ) throws IOException
{
PrintWriter printWriter = new PrintWriter( output, true );
float fontSize = 0.0f;
@@ -409,7 +406,7 @@ public final class PDAppearanceString
printWriter.flush();
}
- private PDFont getFontAndUpdateResources( List tokens, PDAppearanceStream appearanceStream ) throws IOException
+ private PDFont getFontAndUpdateResources( List<Object> tokens, PDAppearanceStream appearanceStream ) throws IOException
{
PDFont retval = null;
PDResources streamResources = appearanceStream.getResources();
@@ -467,7 +464,7 @@ public final class PDAppearanceString
* w in an appearance stream represents the lineWidth.
* @return the linewidth
*/
- private float getLineWidth( List tokens )
+ private float getLineWidth( List<Object> tokens )
{
float retval = 1;
@@ -484,7 +481,7 @@ public final class PDAppearanceString
return retval;
}
- private PDRectangle getSmallestDrawnRectangle( PDRectangle boundingBox, List tokens )
+ private PDRectangle getSmallestDrawnRectangle( PDRectangle boundingBox, List<Object> tokens )
{
PDRectangle smallest = boundingBox;
for( int i=0; i<tokens.size(); i++ )
@@ -520,14 +517,13 @@ public final class PDAppearanceString
*
* @throws IOException If there is an error getting the font height.
*/
- private float calculateFontSize( PDFont pdFont, PDRectangle boundingBox, List tokens, List daTokens )
+ private float calculateFontSize( PDFont pdFont, PDRectangle boundingBox, List<Object> tokens, List<Object> daTokens )
throws IOException
{
float fontSize = 0;
if( daTokens != null )
{
//daString looks like "BMC /Helv 3.4 Tf EMC"
-
int fontIndex = daTokens.indexOf( Operator.getOperator("Tf") );
if(fontIndex != -1 )
{
@@ -576,7 +572,7 @@ public final class PDAppearanceString
*
* @throws IOException If there is an error calculating the text position.
*/
- private String getTextPosition( PDRectangle boundingBox, PDFont pdFont, float fontSize, List tokens )
+ private String getTextPosition( PDRectangle boundingBox, PDFont pdFont, float fontSize, List<Object> tokens )
throws IOException
{
float lineWidth = getLineWidth( tokens );
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java Sun Aug 24 17:42:22 2014
@@ -20,7 +20,6 @@ import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSString;
-
import org.apache.pdfbox.pdmodel.common.COSArrayList;
import java.util.ArrayList;
@@ -93,4 +92,19 @@ public abstract class PDButton extends P
{
getDictionary().setItem(COSName.OPT, COSArrayList.converterToCOSArray( options ) );
}
+
+ @Override
+ public Object getDefaultValue()
+ {
+ // Button fields don't support the "DV" entry.
+ return null;
+ }
+
+ @Override
+ public void setDefaultValue(Object value)
+ {
+ // Button fields don't support the "DV" entry.
+ throw new RuntimeException( "Button fields don't support the \"DV\" entry." );
+ }
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java Sun Aug 24 17:42:22 2014
@@ -20,8 +20,6 @@ import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
-import java.io.IOException;
-
/**
* A check box toggles between two states, on and off.
*
@@ -101,22 +99,6 @@ public final class PDCheckbox extends PD
}
/**
- * {@inheritDoc}
- */
- public void setValue(String newValue)
- {
- getDictionary().setName( COSName.V, newValue );
- if( newValue == null )
- {
- getDictionary().setItem( COSName.AS, COSName.OFF );
- }
- else
- {
- getDictionary().setName( COSName.AS, newValue );
- }
- }
-
- /**
* This will get the value of the radio button.
*
* @return The value of the radio button.
@@ -151,16 +133,29 @@ public final class PDCheckbox extends PD
return retval;
}
- /**
- * getValue gets the fields value to as a string.
- *
- * @return The string value of this field.
- *
- * @throws IOException If there is an error getting the value.
- */
- public String getValue() throws IOException
+ @Override
+ public COSName getValue()
{
- return getDictionary().getNameAsString( COSName.V );
+ return getDictionary().getCOSName( COSName.V );
}
+ @Override
+ public void setValue(Object value)
+ {
+ if (value == null)
+ {
+ getDictionary().removeItem(COSName.V);
+ getDictionary().setItem( COSName.AS, COSName.OFF );
+ }
+ else if (value instanceof COSName)
+ {
+ getDictionary().setItem(COSName.V, (COSName)value);
+ getDictionary().setItem( COSName.AS, (COSName)value);
+ }
+ else
+ {
+ throw new RuntimeException( "The value of a checkbox has to be a name object." );
+ }
+ }
+
}
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=1620169&r1=1620168&r2=1620169&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 Sun Aug 24 17:42:22 2014
@@ -31,6 +31,32 @@ import org.apache.pdfbox.cos.COSString;
*/
public abstract class PDChoice extends PDVariableText
{
+
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_COMBO = 1 << 17;
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_EDIT = 1 << 18;
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_SORT = 1 << 19;
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_MULTI_SELECT = 1 << 21;
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_DO_NOT_SPELL_CHECK = 1 << 22;
+ /**
+ * A Ff flag.
+ */
+ public static final int FLAG_COMMIT_ON_SEL_CHANGE = 1 << 26;
+
/**
* Constructor.
*
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=1620169&r1=1620168&r2=1620169&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 Sun Aug 24 17:42:22 2014
@@ -16,9 +16,11 @@
*/
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 java.io.IOException;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSString;
/**
* A combo box consisting of a drop-down list.
@@ -27,7 +29,6 @@ import java.io.IOException;
*/
public final class PDComboBox extends PDChoice
{
- private static final int FLAG_EDIT = 0x40000;
/**
* Constructor.
@@ -41,18 +42,59 @@ public final class PDComboBox extends PD
super(acroForm, field, parentNode);
}
+ /**
+ * getValue gets the value of the "V" entry.
+ *
+ * @return The value of this entry.
+ *
+ */
@Override
- public void setValue(String optionValue) throws IOException
+ public COSArray getValue()
{
- boolean isEditable = (getFieldFlags() & FLAG_EDIT) != 0;
- int index = getSelectedIndex(optionValue);
-
- if (index == -1 && !isEditable)
+ COSBase value = getDictionary().getDictionaryObject( COSName.V);
+ if (value instanceof COSString)
{
- throw new IllegalArgumentException("Combo box does not contain the given value");
+ COSArray array = new COSArray();
+ array.add(value);
+ return array;
}
+ else if (value instanceof COSArray)
+ {
+ return (COSArray)value;
+ }
+ return null;
+ }
- super.setValue(optionValue);
- selectMultiple(index);
+ /**
+ * setValue sets the entry "V" to the given value.
+ *
+ * @param value the value
+ *
+ */
+ @Override
+ public void setValue(Object value)
+ {
+ if ((getFieldFlags() & FLAG_EDIT) != 0)
+ {
+ throw new IllegalArgumentException("The combo box isn't editable.");
+ }
+ if (value != null)
+ {
+ if (value instanceof String)
+ {
+ int index = getSelectedIndex((String)value);
+ if (index == -1)
+ {
+ throw new IllegalArgumentException("The combo box does not contain the given value.");
+ }
+ selectMultiple(index);
+ }
+ // TODO multiple values
+ }
+ else
+ {
+ getDictionary().removeItem(COSName.V);
+ }
}
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java Sun Aug 24 17:42:22 2014
@@ -107,24 +107,37 @@ public abstract class PDFieldTreeNode im
*/
public abstract String getFieldType();
+ /**
+ * getValue gets the value of the "V" entry.
+ *
+ * @return The value of this entry.
+ *
+ */
+ public abstract Object getValue();
+
+ /**
+ * setValue sets the entry "V" to the given value.
+ *
+ * @param value the value
+ *
+ */
+ public abstract void setValue(Object value);
/**
- * setValue sets the fields value to a given string.
+ * getDefaultValue gets the value of the "DV" entry.
*
- * @param value the string value
+ * @return The value of this field.
*
- * @throws IOException If there is an error creating the appearance stream.
*/
- public abstract void setValue(String value) throws IOException;
+ public abstract Object getDefaultValue();
/**
- * getValue gets the fields value to as a string.
+ * setDefaultValue sets the entry "DV" to the given value.
*
- * @return The string value of this field.
+ * @param value the value
*
- * @throws IOException If there is an error getting the value.
*/
- public abstract String getValue() throws IOException;
+ public abstract void setDefaultValue(Object value);
/**
* sets the field to be read-only.
@@ -553,7 +566,7 @@ public abstract class PDFieldTreeNode im
*/
public String getFullyQualifiedName() throws IOException
{
- String parentName = parent.getFullyQualifiedName();
+ String parentName = getParent() != null ? getParent().getFullyQualifiedName() : null;
String finalName = getPartialName();
if (parentName != null)
{
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=1620169&r1=1620168&r2=1620169&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 Sun Aug 24 17:42:22 2014
@@ -17,10 +17,10 @@
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 java.io.IOException;
+import org.apache.pdfbox.cos.COSString;
/**
* A scrollable list box.
@@ -41,24 +41,59 @@ public final class PDListBox extends PDC
super(acroForm, field, parentNode);
}
+ /**
+ * getValue gets the value of the "V" entry.
+ *
+ * @return The value of this entry.
+ *
+ */
@Override
- public void setValue(String optionValue) throws IOException
+ public COSArray getValue()
{
- COSArray options = (COSArray)getDictionary().getDictionaryObject(COSName.OPT);
- if(options.size() == 0)
+ COSBase value = getDictionary().getDictionaryObject( COSName.V);
+ if (value instanceof COSString)
{
- throw new IllegalArgumentException("List box does not contain the given value");
+ COSArray array = new COSArray();
+ array.add(value);
+ return array;
}
+ else if (value instanceof COSArray)
+ {
+ return (COSArray)value;
+ }
+ return null;
+ }
- int index = getSelectedIndex(optionValue);
- if (index == -1)
+ /**
+ * setValue sets the entry "V" to the given value.
+ *
+ * @param value the value
+ *
+ */
+ @Override
+ public void setValue(Object value)
+ {
+ if ((getFieldFlags() & FLAG_EDIT) != 0)
+ {
+ throw new IllegalArgumentException("The combo box isn't editable.");
+ }
+ if (value != null)
{
- throw new IllegalArgumentException("List box does not contain the given value");
+ if (value instanceof String)
+ {
+ int index = getSelectedIndex((String)value);
+ if (index == -1)
+ {
+ throw new IllegalArgumentException("The combo box does not contain the given value.");
+ }
+ selectMultiple(index);
+ }
+ // TODO multiple values
}
else
{
- super.setValue(optionValue);
- selectMultiple(index);
+ getDictionary().removeItem(COSName.V);
}
}
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java Sun Aug 24 17:42:22 2014
@@ -16,8 +16,6 @@
*/
package org.apache.pdfbox.pdmodel.interactive.form;
-import java.io.IOException;
-
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
@@ -78,16 +76,31 @@ public class PDNonTerminalField extends
}
@Override
- public void setValue(String value) throws IOException
+ public Object getValue()
{
- // non terminal fields don't have a value
+ // Nonterminal fields don't support the "V" entry.
+ return null;
}
-
+
+ @Override
+ public void setValue(Object value)
+ {
+ // Nonterminal fields don't support the "V" entry.
+ throw new RuntimeException( "Nonterminal fields don't support the \"V\" entry." );
+ }
+
@Override
- public String getValue() throws IOException
+ public Object getDefaultValue()
{
- // non terminal fields don't have a value
+ // Nonterminal fields don't support the "DV" entry.
return null;
}
-
+
+ @Override
+ public void setDefaultValue(Object value)
+ {
+ // Nonterminal fields don't support the "DV" entry.
+ throw new RuntimeException( "Nonterminal fields don't support the \"DV\" entry." );
+ }
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java Sun Aug 24 17:42:22 2014
@@ -17,10 +17,6 @@
package org.apache.pdfbox.pdmodel.interactive.form;
import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSString;
-
-import java.io.IOException;
/**
* A pushbutton is a purely interactive control that responds immediately to user
@@ -43,29 +39,18 @@ public class PDPushButton extends PDButt
super(theAcroForm, field, parentNode);
}
- /**
- * @see PDField#setValue(java.lang.String)
- *
- * @param value The new value for the field.
- *
- * @throws IOException If there is an error creating the appearance stream.
- */
- public void setValue(String value) throws IOException
+ @Override
+ public Object getValue()
{
- COSString fieldValue = new COSString(value);
- getDictionary().setItem( COSName.getPDFName( "V" ), fieldValue );
- getDictionary().setItem( COSName.getPDFName( "DV" ), fieldValue );
+ // PushButton fields don't support the "V" entry.
+ return null;
}
- /**
- * getValue gets the fields value to as a string.
- *
- * @return The string value of this field.
- *
- * @throws IOException If there is an error getting the value.
- */
- public String getValue() throws IOException
+ @Override
+ public void setValue(Object value)
{
- return getDictionary().getString( "V" );
+ // PushButton fields don't support the "V" entry.
+ throw new RuntimeException( "PushButton fields don't support the \"V\" entry." );
}
+
}
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=1620169&r1=1620168&r2=1620169&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 Sun Aug 24 17:42:22 2014
@@ -16,7 +16,6 @@
*/
package org.apache.pdfbox.pdmodel.interactive.form;
-import java.io.IOException;
import java.util.List;
import org.apache.pdfbox.cos.COSDictionary;
@@ -45,16 +44,15 @@ public final class PDRadioButton extends
/**
* From the PDF Spec <br/>
- * If set, a group of radio buttons within a radio button field that
- * use the same value for the on state will turn on and off in unison; that is if
- * one is checked, they are all checked. If clear, the buttons are mutually exclusive
- * (the same behavior as HTML radio buttons).
+ * If set, a group of radio buttons within a radio button field that use the same value for the on state will turn
+ * on and off in unison; that is if one is checked, they are all checked. If clear, the buttons are mutually
+ * exclusive (the same behavior as HTML radio buttons).
*
* @param radiosInUnison The new flag for radiosInUnison.
*/
public void setRadiosInUnison(boolean radiosInUnison)
{
- getDictionary().setFlag( COSName.FF, FLAG_RADIOS_IN_UNISON, radiosInUnison );
+ getDictionary().setFlag(COSName.FF, FLAG_RADIOS_IN_UNISON, radiosInUnison);
}
/**
@@ -63,68 +61,46 @@ public final class PDRadioButton extends
*/
public boolean isRadiosInUnison()
{
- return getDictionary().getFlag( COSName.FF, FLAG_RADIOS_IN_UNISON );
+ return getDictionary().getFlag(COSName.FF, FLAG_RADIOS_IN_UNISON);
}
- /**
- * This setValue method iterates the collection of radiobuttons
- * and checks or unchecks each radiobutton according to the
- * given value.
- * If the value is not represented by any of the radiobuttons,
- * then none will be checked.
- *
- * {@inheritDoc}
- */
@Override
- public void setValue(String value) throws IOException
+ public COSName getValue()
{
- getDictionary().setString( COSName.V, value );
- List<COSObjectable> kids = getKids();
- for (COSObjectable kid : kids)
- {
- if ( kid instanceof PDCheckbox )
- {
- PDCheckbox btn = (PDCheckbox)kid;
- if( btn.getOnValue().equals(value) )
- {
- btn.check();
- }
- else
- {
- btn.unCheck();
- }
- }
- }
+ return getDictionary().getCOSName(COSName.V);
}
- /**
- * getValue gets the fields value to as a string.
- *
- * @return The string value of this field.
- *
- * @throws IOException If there is an error getting the value.
- */
@Override
- public String getValue() throws IOException
+ public void setValue(Object value)
{
- String retval = null;
- List<COSObjectable> kids = getKids();
- for (COSObjectable kid : kids)
+ if (value == null)
+ {
+ getDictionary().removeItem(COSName.V);
+ }
+ else if (value instanceof COSName)
{
- if ( kid instanceof PDCheckbox )
+ getDictionary().setItem(COSName.V, (COSName) value);
+ List<COSObjectable> kids = getKids();
+ for (COSObjectable kid : kids)
{
- PDCheckbox btn = (PDCheckbox)kid;
- if( btn.isChecked() )
+ if (kid instanceof PDCheckbox)
{
- retval = btn.getOnValue();
+ PDCheckbox btn = (PDCheckbox) kid;
+ if (btn.getOnValue().equals(value))
+ {
+ btn.check();
+ }
+ else
+ {
+ btn.unCheck();
+ }
}
}
}
- if( retval == null )
+ else
{
- retval = getDictionary().getNameAsString( COSName.V );
+ throw new RuntimeException("The value of a redio button has to be a name object.");
}
- return retval;
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java Sun Aug 24 17:42:22 2014
@@ -95,54 +95,52 @@ public class PDSignatureField extends PD
}
/**
- * @see PDField#setValue(java.lang.String)
- *
- * @param value The new value for the field.
+ * Return a string rep of this object.
*
- * @throws IOException If there is an error creating the appearance stream.
- * @deprecated use setSignature(PDSignatureField) instead
+ * @return A string rep of this object.
*/
@Override
- @Deprecated
- public void setValue(String value) throws IOException
+ public String toString()
{
- throw new RuntimeException( "Can't set signature as String, use setSignature(PDSignatureField) instead" );
+ return "PDSignatureField";
}
-
+
/**
- * @see PDField#setValue(java.lang.String)
- *
- * @return The string value of this field.
- *
- * @throws IOException If there is an error creating the appearance stream.
- * @deprecated use getSignature() instead
+ * Add a signature dictionary to the signature field.
+ *
+ * @param value is the PDSignatureField
*/
- @Override
- @Deprecated
- public String getValue() throws IOException
+ public void setSignature(PDSignature value)
{
- throw new RuntimeException( "Can't get signature as String, use getSignature() instead." );
+ setValue(value);
}
-
+
/**
- * Return a string rep of this object.
- *
- * @return A string rep of this object.
+ * Get the signature dictionary.
+ *
+ * @return the signature dictionary
+ *
*/
- @Override
- public String toString()
+ public PDSignature getSignature()
{
- return "PDSignatureField";
+ return getValue();
}
-
+
/**
* Add a signature dictionary to the signature field.
*
* @param value is the PDSignatureField
*/
- public void setSignature(PDSignature value)
+ public void setValue(Object value)
{
- getDictionary().setItem(COSName.V, value);
+ if (value == null)
+ {
+ getDictionary().removeItem(COSName.V);
+ }
+ else if (value instanceof PDSignature)
+ {
+ getDictionary().setItem(COSName.V, (PDSignature)value);
+ }
}
/**
@@ -151,7 +149,7 @@ public class PDSignatureField extends PD
* @return the signature dictionary
*
*/
- public PDSignature getSignature()
+ public PDSignature getValue()
{
COSBase dictionary = getDictionary().getDictionaryObject(COSName.V);
if (dictionary == null)
@@ -193,4 +191,19 @@ public class PDSignatureField extends PD
getDictionary().setItem(COSName.SV, sv.getCOSObject());
}
}
+
+ @Override
+ public Object getDefaultValue()
+ {
+ // Signature fields don't support the "DV" entry.
+ return null;
+ }
+
+ @Override
+ public void setDefaultValue(Object value)
+ {
+ // Signature fields don't support the "DV" entry.
+ throw new RuntimeException( "Signature fields don't support the \"DV\" entry." );
+ }
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java Sun Aug 24 17:42:22 2014
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdmodel.intera
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSString;
/**
* A text field is a box or space for text fill-in data typically entered from a keyboard.
@@ -27,7 +28,6 @@ import org.apache.pdfbox.cos.COSName;
*/
public final class PDTextField extends PDVariableText
{
-
/**
* @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)(PDAcroForm,COSDictionary)
*
@@ -70,4 +70,43 @@ public final class PDTextField extends P
getDictionary().setInt(COSName.MAX_LEN, maxLen);
}
+ /**
+ * setValue sets the entry "V" to the given value.
+ *
+ * @param value the value
+ *
+ */
+ @Override
+ public void setValue(Object value)
+ {
+ if (value != null)
+ {
+ if (value instanceof String)
+ {
+ String stringValue = (String)value;
+ COSString fieldValue = new COSString(stringValue);
+ getDictionary().setItem( COSName.V, fieldValue );
+ }
+ // TODO stream instead of string
+ // TODO creation of appearance stream
+ }
+ else
+ {
+ getDictionary().removeItem(COSName.V);
+ }
+ }
+
+ /**
+ * getValue gets the value of the "V" entry.
+ *
+ * @return The value of this entry.
+ *
+ */
+ @Override
+ public Object getValue()
+ {
+ return getDictionary().getItem(COSName.V );
+ }
+
+
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java Sun Aug 24 17:42:22 2014
@@ -21,8 +21,6 @@ import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.cos.COSString;
-import java.io.IOException;
-
/**
* Base class for fields which use "Variable Text".
* These fields construct an appearance stream dynamically at viewing time.
@@ -66,9 +64,6 @@ public abstract class PDVariableText ext
*/
private COSString da;
- private PDAppearanceString appearance;
-
-
/**
* A Q value.
*/
@@ -108,41 +103,6 @@ public abstract class PDVariableText ext
}
/**
- * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#setValue(java.lang.String)
- *
- * @param value The new value for this text field.
- *
- * @throws IOException If there is an error calculating the appearance stream.
- */
- public void setValue(String value) throws IOException
- {
- COSString fieldValue = new COSString(value);
- getDictionary().setItem( COSName.V, fieldValue );
-
- //hmm, not sure what the case where the DV gets set to the field
- //value, for now leave blank until we can come up with a case
- //where it needs to be in there
- //getDictionary().setItem( COSName.getPDFName( "DV" ), fieldValue );
- if(appearance == null)
- {
- this.appearance = new PDAppearanceString( getAcroForm(), this );
- }
- appearance.setAppearanceValue(value);
- }
-
- /**
- * getValue gets the fields value to as a string.
- *
- * @return The string value of this field.
- *
- * @throws IOException If there is an error getting the value.
- */
- public String getValue() throws IOException
- {
- return getDictionary().getString( COSName.V );
- }
-
- /**
* @return true if the field is multiline
*/
public boolean isMultiline()
@@ -305,4 +265,19 @@ public abstract class PDVariableText ext
{
getDictionary().setInt( COSName.Q, q );
}
+
+ @Override
+ public Object getDefaultValue()
+ {
+ // Text fields don't support the "DV" entry.
+ return null;
+ }
+
+ @Override
+ public void setDefaultValue(Object value)
+ {
+ // Text fields don't support the "DV" entry.
+ throw new RuntimeException( "Text fields don't support the \"DV\" entry." );
+ }
+
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java?rev=1620169&r1=1620168&r2=1620169&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java Sun Aug 24 17:42:22 2014
@@ -183,7 +183,7 @@ public class TestFDF extends TestCase
PDRadioButton feld3 = (PDRadioButton)form.getField( "Feld.3" );
feld3.setValue("RB1");
- assertEquals( "RB1", feld3.getValue() );
+ assertEquals( "RB1", feld3.getValue().getName() );
}
finally
{