You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/07/07 22:57:19 UTC
svn commit: r1689740 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Author: tilman
Date: Tue Jul 7 20:57:18 2015
New Revision: 1689740
URL: http://svn.apache.org/r1689740
Log:
PDFBOX-2841: improve error message, remove double code
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.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=1689740&r1=1689739&r2=1689740&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 Tue Jul 7 20:57:18 2015
@@ -169,32 +169,26 @@ public final class PDRadioButton extends
*
* @param value Name of radio button to select
* @throws IOException if the value could not be set
+ * @throws IllegalArgumentException if the value is not a valid option.
*/
public void setValue(String value) throws IOException
{
- List<String> onValues = getOnValues();
- if (COSName.Off.getName().compareTo(value) != 0 && !onValues.contains(value))
- {
- throw new IllegalArgumentException(value + " is not a valid option for the radio button " + getFullyQualifiedName());
- }
- else
+ checkValue(value);
+ dictionary.setName(COSName.V, value);
+ // update the appearance state (AS)
+ for (PDAnnotationWidget widget : getWidgets())
{
- dictionary.setName(COSName.V, value);
- // update the appearance state (AS)
- for (PDAnnotationWidget widget : getWidgets())
+ PDAppearanceEntry appearanceEntry = widget.getAppearance().getNormalAppearance();
+ if (((COSDictionary) appearanceEntry.getCOSObject()).containsKey(value))
{
- PDAppearanceEntry appearanceEntry = widget.getAppearance().getNormalAppearance();
- if (((COSDictionary)appearanceEntry.getCOSObject()).containsKey(value))
- {
- widget.getCOSObject().setName(COSName.AS, value);
- }
- else
- {
- widget.getCOSObject().setItem(COSName.AS, COSName.Off);
- }
+ widget.getCOSObject().setName(COSName.AS, value);
+ }
+ else
+ {
+ widget.getCOSObject().setItem(COSName.AS, COSName.Off);
}
- applyChange();
}
+ applyChange();
}
/**
@@ -202,19 +196,30 @@ public final class PDRadioButton extends
*
* @param value Name of radio button to select
* @throws IOException if the value could not be set
+ * @throws IllegalArgumentException if the value is not a valid option.
*/
public void setDefaultValue(String value) throws IOException
{
+ checkValue(value);
+ dictionary.setName(COSName.DV, value);
+ }
+
+ /**
+ * Checks value.
+ *
+ * @param value Name of radio button to select
+ * @throws IllegalArgumentException if the value is not a valid option.
+ */
+ private void checkValue(String value) throws IllegalArgumentException
+ {
List<String> onValues = getOnValues();
if (COSName.Off.getName().compareTo(value) != 0 && !onValues.contains(value))
{
- throw new IllegalArgumentException(value + " is not a valid option for the radio button " + getFullyQualifiedName());
+ throw new IllegalArgumentException("value '" + value
+ + "' is not a valid option for the radio button " + getFullyQualifiedName()
+ + ", valid values are: " + onValues + " and " + COSName.Off.getName());
}
- else
- {
- dictionary.setName(COSName.DV, value);
- }
- }
+ }
/**
* Get the List of values to set individual radio buttons to the on state.