| Code with Finding: |
class TextField {
protected PdfFormField getChoiceField(boolean isList) throws IOException, DocumentException {
options &= ~MULTILINE & ~COMB;
String uchoices[] = choices;
if (uchoices == null)
uchoices = new String[0];
int topChoice = getTopChoice();
if (text == null)
text = ""; //fixed by Kazuya Ujihara (ujihara.jp)
if (topChoice >= 0)
text = uchoices[topChoice];
PdfFormField field = null;
String mix[][] = null;
if (choiceExports == null) {
if (isList)
field = PdfFormField.createList(writer, uchoices, topChoice);
else
field = PdfFormField.createCombo(writer, (options & EDIT) != 0, uchoices, topChoice);
}
else {
mix = new String[uchoices.length][2];
for (int k = 0; k < mix.length; ++k)
mix[k][0] = mix[k][1] = uchoices[k];
int top = Math.min(uchoices.length, choiceExports.length);
for (int k = 0; k < top; ++k) {
if (choiceExports[k] != null)
mix[k][0] = choiceExports[k];
}
if (isList)
field = PdfFormField.createList(writer, mix, topChoice);
else
field = PdfFormField.createCombo(writer, (options & EDIT) != 0, mix, topChoice);
}
field.setWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
if (rotation != 0)
field.setMKRotation(rotation);
if (fieldName != null) {
field.setFieldName(fieldName);
if (uchoices.length > 0) {
if (mix != null) {
if (choiceSelections.size() < 2) {
field.setValueAsString(mix[topChoice][0]);
field.setDefaultValueAsString(mix[topChoice][0]);
} else {
writeMultipleValues( field, mix);
}
} else {
if (choiceSelections.size() < 2) {
field.setValueAsString(text);
field.setDefaultValueAsString(text);
} else {
writeMultipleValues( field, null );
}
}
}
if ((options & READ_ONLY) != 0)
field.setFieldFlags(PdfFormField.FF_READ_ONLY);
if ((options & REQUIRED) != 0)
field.setFieldFlags(PdfFormField.FF_REQUIRED);
if ((options & DO_NOT_SPELL_CHECK) != 0)
field.setFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
if ((options & MULTISELECT) != 0) {
field.setFieldFlags( PdfFormField.FF_MULTISELECT );
}
}
field.setBorderStyle(new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)));
PdfAppearance tp;
if (isList) {
tp = getListAppearance();
if (topFirst > 0)
field.put(PdfName.TI, new PdfNumber(topFirst));
}
else
tp = getAppearance();
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
PdfAppearance da = (PdfAppearance)tp.getDuplicate();
da.setFontAndSize(getRealFont(), fontSize);
if (textColor == null)
da.setGrayFill(0);
else
da.setColorFill(textColor);
field.setDefaultAppearanceString(da);
if (borderColor != null)
field.setMKBorderColor(borderColor);
if (backgroundColor != null)
field.setMKBackgroundColor(backgroundColor);
switch (visibility) {
case HIDDEN:
field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN);
break;
case VISIBLE_BUT_DOES_NOT_PRINT:
break;
case HIDDEN_BUT_PRINTABLE:
field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW);
break;
default:
field.setFlags(PdfAnnotation.FLAGS_PRINT);
break;
}
return field;
}
}
|