RadioCheckField.java

1
/*
2
 * Copyright 2005 by Paulo Soares.
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version 1.1
5
 * (the "License"); you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7
 *
8
 * Software distributed under the License is distributed on an "AS IS" basis,
9
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10
 * for the specific language governing rights and limitations under the License.
11
 *
12
 * The Original Code is 'iText, a free JAVA-PDF library'.
13
 *
14
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
15
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
16
 * All Rights Reserved.
17
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
18
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
19
 *
20
 * Contributor(s): all the names of the contributors are added in the source code
21
 * where applicable.
22
 *
23
 * Alternatively, the contents of this file may be used under the terms of the
24
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
25
 * provisions of LGPL are applicable instead of those above.  If you wish to
26
 * allow use of your version of this file only under the terms of the LGPL
27
 * License and not to allow others to use your version of this file under
28
 * the MPL, indicate your decision by deleting the provisions above and
29
 * replace them with the notice and other provisions required by the LGPL.
30
 * If you do not delete the provisions above, a recipient may use your version
31
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
32
 *
33
 * This library is free software; you can redistribute it and/or modify it
34
 * under the terms of the MPL as stated above or under the terms of the GNU
35
 * Library General Public License as published by the Free Software Foundation;
36
 * either version 2 of the License, or any later version.
37
 *
38
 * This library is distributed in the hope that it will be useful, but WITHOUT
39
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
40
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
41
 * details.
42
 *
43
 * If you didn't download this code from the following link, you should check if
44
 * you aren't using an obsolete version:
45
 * http://www.lowagie.com/iText/
46
 */
47
package com.lowagie.text.pdf;
48
49
import java.io.IOException;
50
51
import com.lowagie.text.DocumentException;
52
53
import com.lowagie.text.Rectangle;
54
import com.lowagie.text.ExceptionConverter;
55
56
/**
57
 * Creates a radio or a check field.
58
 * <p>
59
 * Example usage:
60
 * <p>
61
 * <PRE>
62
 * Document document = new Document(PageSize.A4, 50, 50, 50, 50);
63
 * PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
64
 * document.open();
65
 * PdfContentByte cb = writer.getDirectContent();
66
 * RadioCheckField bt = new RadioCheckField(writer, new Rectangle(100, 100, 200, 200), "radio", "v1");
67
 * bt.setCheckType(RadioCheckField.TYPE_CIRCLE);
68
 * bt.setBackgroundColor(Color.cyan);
69
 * bt.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
70
 * bt.setBorderColor(Color.red);
71
 * bt.setTextColor(Color.yellow);
72
 * bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
73
 * bt.setChecked(false);
74
 * PdfFormField f1 = bt.getRadioField();
75
 * bt.setOnValue("v2");
76
 * bt.setChecked(true);
77
 * bt.setBox(new Rectangle(100, 300, 200, 400));
78
 * PdfFormField f2 = bt.getRadioField();
79
 * bt.setChecked(false);
80
 * PdfFormField top = bt.getRadioGroup(true, false);
81
 * bt.setOnValue("v3");
82
 * bt.setBox(new Rectangle(100, 500, 200, 600));
83
 * PdfFormField f3 = bt.getRadioField();
84
 * top.addKid(f1);
85
 * top.addKid(f2);
86
 * top.addKid(f3);
87
 * writer.addAnnotation(top);
88
 * bt = new RadioCheckField(writer, new Rectangle(300, 300, 400, 400), "check1", "Yes");
89
 * bt.setCheckType(RadioCheckField.TYPE_CHECK);
90
 * bt.setBorderWidth(BaseField.BORDER_WIDTH_THIN);
91
 * bt.setBorderColor(Color.black);
92
 * bt.setBackgroundColor(Color.white);
93
 * PdfFormField ck = bt.getCheckField();
94
 * writer.addAnnotation(ck);
95
 * document.close();
96
 * </PRE>
97
 * @author Paulo Soares (psoares@consiste.pt)
98
 */
99
public class RadioCheckField extends BaseField {
100
101
    /** A field with the symbol check */
102
    public static final int TYPE_CHECK = 1;
103
    /** A field with the symbol circle */
104
    public static final int TYPE_CIRCLE = 2;
105
    /** A field with the symbol cross */
106
    public static final int TYPE_CROSS = 3;
107
    /** A field with the symbol diamond */
108
    public static final int TYPE_DIAMOND = 4;
109
    /** A field with the symbol square */
110
    public static final int TYPE_SQUARE = 5;
111
    /** A field with the symbol star */
112
    public static final int TYPE_STAR = 6;
113
114
    private static String[] typeChars = {"4", "l", "8", "u", "n", "H"};
115
    
116
    /**
117
     * Holds value of property checkType.
118
     */
119
    private int checkType;
120
    
121
    /**
122
     * Holds value of property onValue.
123
     */
124
    private String onValue;
125
    
126
    /**
127
     * Holds value of property checked.
128
     */
129
    private boolean checked;
130
    
131
    /**
132
     * Creates a new instance of RadioCheckField
133
     * @param writer the document <CODE>PdfWriter</CODE>
134
     * @param box the field location and dimensions
135
     * @param fieldName the field name. It must not be <CODE>null</CODE>
136
     * @param onValue the value when the field is checked
137
     */
138
    public RadioCheckField(PdfWriter writer, Rectangle box, String fieldName, String onValue) {
139
        super(writer, box, fieldName);
140 1 1. : removed call to com/lowagie/text/pdf/RadioCheckField::setOnValue → NO_COVERAGE
        setOnValue(onValue);
141 1 1. : removed call to com/lowagie/text/pdf/RadioCheckField::setCheckType → NO_COVERAGE
        setCheckType(TYPE_CHECK);
142
    }
143
    
144
    /**
145
     * Getter for property checkType.
146
     * @return Value of property checkType.
147
     */
148
    public int getCheckType() {
149
        return this.checkType;
150
    }
151
    
152
    /**
153
     * Sets the checked symbol. It can be
154
     * <CODE>TYPE_CHECK</CODE>,
155
     * <CODE>TYPE_CIRCLE</CODE>,
156
     * <CODE>TYPE_CROSS</CODE>,
157
     * <CODE>TYPE_DIAMOND</CODE>,
158
     * <CODE>TYPE_SQUARE</CODE> and
159
     * <CODE>TYPE_STAR</CODE>.
160
     * @param checkType the checked symbol
161
     */
162
    public void setCheckType(int checkType) {
163 4 1. setCheckType : changed conditional boundary → NO_COVERAGE
2. setCheckType : changed conditional boundary → NO_COVERAGE
3. setCheckType : negated conditional → NO_COVERAGE
4. setCheckType : negated conditional → NO_COVERAGE
        if (checkType < TYPE_CHECK || checkType > TYPE_STAR)
164
            checkType = TYPE_CHECK;
165
        this.checkType = checkType;
166 2 1. setCheckType : Replaced integer subtraction with addition → NO_COVERAGE
2. setCheckType : removed call to com/lowagie/text/pdf/RadioCheckField::setText → NO_COVERAGE
        setText(typeChars[checkType - 1]);
167
        try {
168 1 1. setCheckType : removed call to com/lowagie/text/pdf/RadioCheckField::setFont → NO_COVERAGE
            setFont(BaseFont.createFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, false));
169
        }
170
        catch (Exception e) {
171
            throw new ExceptionConverter(e);
172
        }
173
    }
174
    
175
    /**
176
     * Getter for property onValue.
177
     * @return Value of property onValue.
178
     */
179
    public String getOnValue() {
180
        return this.onValue;
181
    }
182
    
183
    /**
184
     * Sets the value when the field is checked.
185
     * @param onValue the value when the field is checked
186
     */
187
    public void setOnValue(String onValue) {
188
        this.onValue = onValue;
189
    }
190
    
191
    /**
192
     * Getter for property checked.
193
     * @return Value of property checked.
194
     */
195
    public boolean isChecked() {
196
        return this.checked;
197
    }
198
    
199
    /**
200
     * Sets the state of the field to checked or unchecked.
201
     * @param checked the state of the field, <CODE>true</CODE> for checked
202
     * and <CODE>false</CODE> for unchecked
203
     */
204
    public void setChecked(boolean checked) {
205
        this.checked = checked;
206
    }
207
    
208
    /**
209
     * Gets the field appearance.
210
     * @param isRadio <CODE>true</CODE> for a radio field and <CODE>false</CODE>
211
     * for a check field
212
     * @param on <CODE>true</CODE> for the checked state, <CODE>false</CODE>
213
     * otherwise
214
     * @throws IOException on error
215
     * @throws DocumentException on error
216
     * @return the appearance
217
     */    
218
    public PdfAppearance getAppearance(boolean isRadio, boolean on) throws IOException, DocumentException {
219 2 1. getAppearance : negated conditional → NO_COVERAGE
2. getAppearance : negated conditional → NO_COVERAGE
        if (isRadio && checkType == TYPE_CIRCLE)
220 1 1. getAppearance : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
            return getAppearanceRadioCircle(on);
221
        PdfAppearance app = getBorderAppearance();
222 1 1. getAppearance : negated conditional → NO_COVERAGE
        if (!on)
223 1 1. getAppearance : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
            return app;
224
        BaseFont ufont = getRealFont();
225 2 1. getAppearance : negated conditional → NO_COVERAGE
2. getAppearance : negated conditional → NO_COVERAGE
        boolean borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
226 2 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
        float h = box.getHeight() - borderWidth * 2;
227
        float bw2 = borderWidth;
228 1 1. getAppearance : negated conditional → NO_COVERAGE
        if (borderExtra) {
229 2 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
            h -= borderWidth * 2;
230 1 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
            bw2 *= 2;
231
        }
232 2 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
2. getAppearance : negated conditional → NO_COVERAGE
        float offsetX = (borderExtra ? 2 * borderWidth : borderWidth);
233
        offsetX = Math.max(offsetX, 1);
234
        float offX = Math.min(bw2, offsetX);
235 2 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
        float wt = box.getWidth() - 2 * offX;
236 2 1. getAppearance : Replaced float multiplication with division → NO_COVERAGE
2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
        float ht = box.getHeight() - 2 * offX;
237
        float fsize = fontSize;
238 1 1. getAppearance : negated conditional → NO_COVERAGE
        if (fsize == 0) {
239
            float bw = ufont.getWidthPoint(text, 1);
240 1 1. getAppearance : negated conditional → NO_COVERAGE
            if (bw == 0)
241
                fsize = 12;
242
            else
243 1 1. getAppearance : Replaced float division with multiplication → NO_COVERAGE
                fsize = wt / bw;
244 1 1. getAppearance : Replaced float division with multiplication → NO_COVERAGE
            float nfsize = h / (ufont.getFontDescriptor(BaseFont.ASCENT, 1));
245
            fsize = Math.min(fsize, nfsize);
246
        }
247 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::saveState → NO_COVERAGE
        app.saveState();
248 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::rectangle → NO_COVERAGE
        app.rectangle(offX, offX, wt, ht);
249 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::clip → NO_COVERAGE
        app.clip();
250 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::newPath → NO_COVERAGE
        app.newPath();
251 1 1. getAppearance : negated conditional → NO_COVERAGE
        if (textColor == null)
252 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::resetGrayFill → NO_COVERAGE
            app.resetGrayFill();
253
        else
254 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE
            app.setColorFill(textColor);
255 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::beginText → NO_COVERAGE
        app.beginText();
256 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::setFontAndSize → NO_COVERAGE
        app.setFontAndSize(ufont, fsize);
257 3 1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
2. getAppearance : Replaced float division with multiplication → NO_COVERAGE
3. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::setTextMatrix → NO_COVERAGE
        app.setTextMatrix((box.getWidth() - ufont.getWidthPoint(text, fsize)) / 2, 
258 2 1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE
2. getAppearance : Replaced float division with multiplication → NO_COVERAGE
            (box.getHeight() - ufont.getAscentPoint(text, fsize)) / 2);
259 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::showText → NO_COVERAGE
        app.showText(text);
260 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::endText → NO_COVERAGE
        app.endText();
261 1 1. getAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::restoreState → NO_COVERAGE
        app.restoreState();
262 1 1. getAppearance : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return app;
263
    }
264
265
    /**
266
     * Gets the special field appearance for the radio circle.
267
     * @param on <CODE>true</CODE> for the checked state, <CODE>false</CODE>
268
     * otherwise
269
     * @return the appearance
270
     */    
271
    public PdfAppearance getAppearanceRadioCircle(boolean on) {
272
        PdfAppearance app = PdfAppearance.createAppearance(writer, box.getWidth(), box.getHeight());
273
        switch (rotation) {
274
            case 90:
275 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE
                app.setMatrix(0, 1, -1, 0, box.getHeight(), 0);
276
                break;
277
            case 180:
278 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE
                app.setMatrix(-1, 0, 0, -1, box.getWidth(), box.getHeight());
279
                break;
280
            case 270:
281 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE
                app.setMatrix(0, -1, 1, 0, 0, box.getWidth());
282
                break;
283
        }
284
        Rectangle box = new Rectangle(app.getBoundingBox());
285 1 1. getAppearanceRadioCircle : Replaced float division with multiplication → NO_COVERAGE
        float cx = box.getWidth() / 2;
286 1 1. getAppearanceRadioCircle : Replaced float division with multiplication → NO_COVERAGE
        float cy = box.getHeight() / 2;
287 2 1. getAppearanceRadioCircle : Replaced float subtraction with addition → NO_COVERAGE
2. getAppearanceRadioCircle : Replaced float division with multiplication → NO_COVERAGE
        float r = (Math.min(box.getWidth(), box.getHeight()) - borderWidth) / 2;
288 2 1. getAppearanceRadioCircle : changed conditional boundary → NO_COVERAGE
2. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
        if (r <= 0)
289 1 1. getAppearanceRadioCircle : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearanceRadioCircle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
            return app;
290 1 1. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
        if (backgroundColor != null) {
291 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE
            app.setColorFill(backgroundColor);
292 3 1. getAppearanceRadioCircle : Replaced float division with multiplication → NO_COVERAGE
2. getAppearanceRadioCircle : Replaced float addition with subtraction → NO_COVERAGE
3. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE
            app.circle(cx, cy, r + borderWidth / 2);
293 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::fill → NO_COVERAGE
            app.fill();
294
        }
295 3 1. getAppearanceRadioCircle : changed conditional boundary → NO_COVERAGE
2. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
3. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
        if (borderWidth > 0 && borderColor != null) {
296 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setLineWidth → NO_COVERAGE
            app.setLineWidth(borderWidth);
297 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setColorStroke → NO_COVERAGE
            app.setColorStroke(borderColor);
298 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE
            app.circle(cx, cy, r);
299 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::stroke → NO_COVERAGE
            app.stroke();
300
        }
301 1 1. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
        if (on) {
302 1 1. getAppearanceRadioCircle : negated conditional → NO_COVERAGE
            if (textColor == null)
303 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::resetGrayFill → NO_COVERAGE
                app.resetGrayFill();
304
            else
305 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE
                app.setColorFill(textColor);
306 2 1. getAppearanceRadioCircle : Replaced float division with multiplication → NO_COVERAGE
2. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE
            app.circle(cx, cy, r / 2);
307 1 1. getAppearanceRadioCircle : removed call to com/lowagie/text/pdf/PdfAppearance::fill → NO_COVERAGE
            app.fill();
308
        }
309 1 1. getAppearanceRadioCircle : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearanceRadioCircle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return app;
310
    }
311
    
312
    /**
313
     * Gets a radio group. It's composed of the field specific keys, without the widget
314
     * ones. This field is to be used as a field aggregator with {@link PdfFormField#addKid(PdfFormField) addKid()}.
315
     * @param noToggleToOff if <CODE>true</CODE>, exactly one radio button must be selected at all
316
     * times; clicking the currently selected button has no effect.
317
     * If <CODE>false</CODE>, clicking
318
     * the selected button deselects it, leaving no button selected.
319
     * @param radiosInUnison if <CODE>true</CODE>, a group of radio buttons within a radio button field that
320
     * use the same value for the on state will turn on and off in unison; that is if
321
     * one is checked, they are all checked. If <CODE>false</CODE>, the buttons are mutually exclusive
322
     * (the same behavior as HTML radio buttons)
323
     * @return the radio group
324
     */    
325
    public PdfFormField getRadioGroup(boolean noToggleToOff, boolean radiosInUnison) {
326
        PdfFormField field = PdfFormField.createRadioButton(writer, noToggleToOff);
327 1 1. getRadioGroup : negated conditional → NO_COVERAGE
        if (radiosInUnison)
328
            field.setFieldFlags(PdfFormField.FF_RADIOSINUNISON);
329 1 1. getRadioGroup : removed call to com/lowagie/text/pdf/PdfFormField::setFieldName → NO_COVERAGE
        field.setFieldName(fieldName);
330 2 1. getRadioGroup : Replaced bitwise AND with OR → NO_COVERAGE
2. getRadioGroup : negated conditional → NO_COVERAGE
        if ((options & READ_ONLY) != 0)
331
            field.setFieldFlags(PdfFormField.FF_READ_ONLY);
332 2 1. getRadioGroup : Replaced bitwise AND with OR → NO_COVERAGE
2. getRadioGroup : negated conditional → NO_COVERAGE
        if ((options & REQUIRED) != 0)
333
            field.setFieldFlags(PdfFormField.FF_REQUIRED);
334 2 1. getRadioGroup : negated conditional → NO_COVERAGE
2. getRadioGroup : removed call to com/lowagie/text/pdf/PdfFormField::setValueAsName → NO_COVERAGE
        field.setValueAsName(checked ? onValue : "Off");
335 1 1. getRadioGroup : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getRadioGroup to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return field;
336
    }
337
    
338
    /**
339
     * Gets the radio field. It's only composed of the widget keys and must be used
340
     * with {@link #getRadioGroup(boolean,boolean)}.
341
     * @return the radio field
342
     * @throws IOException on error
343
     * @throws DocumentException on error
344
     */    
345
    public PdfFormField getRadioField() throws IOException, DocumentException {
346 1 1. getRadioField : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getRadioField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getField(true);
347
    }
348
    
349
    /**
350
     * Gets the check field.
351
     * @return the check field
352
     * @throws IOException on error
353
     * @throws DocumentException on error
354
     */    
355
    public PdfFormField getCheckField() throws IOException, DocumentException {
356 1 1. getCheckField : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getCheckField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getField(false);
357
    }
358
    
359
    /**
360
     * Gets a radio or check field.
361
     * @param isRadio <CODE>true</CODE> to get a radio field, <CODE>false</CODE> to get
362
     * a check field
363
     * @throws IOException on error
364
     * @throws DocumentException on error
365
     * @return the field
366
     */    
367
    protected PdfFormField getField(boolean isRadio) throws IOException, DocumentException {
368
        PdfFormField field = null;
369 1 1. getField : negated conditional → NO_COVERAGE
        if (isRadio)
370
            field = PdfFormField.createEmpty(writer);
371
        else
372
            field = PdfFormField.createCheckBox(writer);
373 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setWidget → NO_COVERAGE
        field.setWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
374 1 1. getField : negated conditional → NO_COVERAGE
        if (!isRadio) {
375 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setFieldName → NO_COVERAGE
            field.setFieldName(fieldName);
376 2 1. getField : Replaced bitwise AND with OR → NO_COVERAGE
2. getField : negated conditional → NO_COVERAGE
            if ((options & READ_ONLY) != 0)
377
                field.setFieldFlags(PdfFormField.FF_READ_ONLY);
378 2 1. getField : Replaced bitwise AND with OR → NO_COVERAGE
2. getField : negated conditional → NO_COVERAGE
            if ((options & REQUIRED) != 0)
379
                field.setFieldFlags(PdfFormField.FF_REQUIRED);
380 2 1. getField : negated conditional → NO_COVERAGE
2. getField : removed call to com/lowagie/text/pdf/PdfFormField::setValueAsName → NO_COVERAGE
            field.setValueAsName(checked ? onValue : "Off");            
381
        }
382 1 1. getField : negated conditional → NO_COVERAGE
        if (text != null)
383 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setMKNormalCaption → NO_COVERAGE
            field.setMKNormalCaption(text);
384 1 1. getField : negated conditional → NO_COVERAGE
        if (rotation != 0)
385 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setMKRotation → NO_COVERAGE
            field.setMKRotation(rotation);
386 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setBorderStyle → NO_COVERAGE
        field.setBorderStyle(new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)));
387
        PdfAppearance tpon = getAppearance(isRadio, true);
388
        PdfAppearance tpoff = getAppearance(isRadio, false);
389 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE
        field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, onValue, tpon);
390 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE
        field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpoff);
391 2 1. getField : negated conditional → NO_COVERAGE
2. getField : removed call to com/lowagie/text/pdf/PdfFormField::setAppearanceState → NO_COVERAGE
        field.setAppearanceState(checked ? onValue : "Off");
392
        PdfAppearance da = (PdfAppearance)tpon.getDuplicate();
393 1 1. getField : removed call to com/lowagie/text/pdf/PdfAppearance::setFontAndSize → NO_COVERAGE
        da.setFontAndSize(getRealFont(), fontSize);
394 1 1. getField : negated conditional → NO_COVERAGE
        if (textColor == null)
395 1 1. getField : removed call to com/lowagie/text/pdf/PdfAppearance::setGrayFill → NO_COVERAGE
            da.setGrayFill(0);
396
        else
397 1 1. getField : removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE
            da.setColorFill(textColor);
398 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setDefaultAppearanceString → NO_COVERAGE
        field.setDefaultAppearanceString(da);
399 1 1. getField : negated conditional → NO_COVERAGE
        if (borderColor != null)
400 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setMKBorderColor → NO_COVERAGE
            field.setMKBorderColor(borderColor);
401 1 1. getField : negated conditional → NO_COVERAGE
        if (backgroundColor != null)
402 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setMKBackgroundColor → NO_COVERAGE
            field.setMKBackgroundColor(backgroundColor);
403
        switch (visibility) {
404
            case HIDDEN:
405 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE
                field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN);
406
                break;
407
            case VISIBLE_BUT_DOES_NOT_PRINT:
408
                break;
409
            case HIDDEN_BUT_PRINTABLE:
410 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE
                field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW);
411
                break;
412
            default:
413 1 1. getField : removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE
                field.setFlags(PdfAnnotation.FLAGS_PRINT);
414
                break;
415
        }
416 1 1. getField : mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return field;
417
    }
418
}

Mutations

140

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/RadioCheckField::setOnValue → NO_COVERAGE

141

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/RadioCheckField::setCheckType → NO_COVERAGE

163

1.1
Location : setCheckType
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : setCheckType
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : setCheckType
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : setCheckType
Killed by : none
negated conditional → NO_COVERAGE

166

1.1
Location : setCheckType
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

2.2
Location : setCheckType
Killed by : none
removed call to com/lowagie/text/pdf/RadioCheckField::setText → NO_COVERAGE

168

1.1
Location : setCheckType
Killed by : none
removed call to com/lowagie/text/pdf/RadioCheckField::setFont → NO_COVERAGE

219

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

220

1.1
Location : getAppearance
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

222

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

223

1.1
Location : getAppearance
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

225

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

226

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

228

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

229

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

230

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

232

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

235

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

236

1.1
Location : getAppearance
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

238

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

240

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

243

1.1
Location : getAppearance
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

244

1.1
Location : getAppearance
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

247

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::saveState → NO_COVERAGE

248

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::rectangle → NO_COVERAGE

249

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::clip → NO_COVERAGE

250

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::newPath → NO_COVERAGE

251

1.1
Location : getAppearance
Killed by : none
negated conditional → NO_COVERAGE

252

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::resetGrayFill → NO_COVERAGE

254

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE

255

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::beginText → NO_COVERAGE

256

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setFontAndSize → NO_COVERAGE

257

1.1
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

3.3
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setTextMatrix → NO_COVERAGE

258

1.1
Location : getAppearance
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : getAppearance
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

259

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::showText → NO_COVERAGE

260

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::endText → NO_COVERAGE

261

1.1
Location : getAppearance
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::restoreState → NO_COVERAGE

262

1.1
Location : getAppearance
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

275

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE

278

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE

281

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setMatrix → NO_COVERAGE

285

1.1
Location : getAppearanceRadioCircle
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

286

1.1
Location : getAppearanceRadioCircle
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

287

1.1
Location : getAppearanceRadioCircle
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : getAppearanceRadioCircle
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

288

1.1
Location : getAppearanceRadioCircle
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

289

1.1
Location : getAppearanceRadioCircle
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearanceRadioCircle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

290

1.1
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

291

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE

292

1.1
Location : getAppearanceRadioCircle
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

2.2
Location : getAppearanceRadioCircle
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

3.3
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE

293

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::fill → NO_COVERAGE

295

1.1
Location : getAppearanceRadioCircle
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

296

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setLineWidth → NO_COVERAGE

297

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setColorStroke → NO_COVERAGE

298

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE

299

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::stroke → NO_COVERAGE

301

1.1
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

302

1.1
Location : getAppearanceRadioCircle
Killed by : none
negated conditional → NO_COVERAGE

303

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::resetGrayFill → NO_COVERAGE

305

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE

306

1.1
Location : getAppearanceRadioCircle
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

2.2
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::circle → NO_COVERAGE

307

1.1
Location : getAppearanceRadioCircle
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::fill → NO_COVERAGE

309

1.1
Location : getAppearanceRadioCircle
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getAppearanceRadioCircle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

327

1.1
Location : getRadioGroup
Killed by : none
negated conditional → NO_COVERAGE

329

1.1
Location : getRadioGroup
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setFieldName → NO_COVERAGE

330

1.1
Location : getRadioGroup
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

2.2
Location : getRadioGroup
Killed by : none
negated conditional → NO_COVERAGE

332

1.1
Location : getRadioGroup
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

2.2
Location : getRadioGroup
Killed by : none
negated conditional → NO_COVERAGE

334

1.1
Location : getRadioGroup
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getRadioGroup
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setValueAsName → NO_COVERAGE

335

1.1
Location : getRadioGroup
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getRadioGroup to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

346

1.1
Location : getRadioField
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getRadioField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

356

1.1
Location : getCheckField
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getCheckField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

369

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

373

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setWidget → NO_COVERAGE

374

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

375

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setFieldName → NO_COVERAGE

376

1.1
Location : getField
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

2.2
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

378

1.1
Location : getField
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

2.2
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

380

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setValueAsName → NO_COVERAGE

382

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

383

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setMKNormalCaption → NO_COVERAGE

384

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

385

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setMKRotation → NO_COVERAGE

386

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setBorderStyle → NO_COVERAGE

389

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE

390

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE

391

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setAppearanceState → NO_COVERAGE

393

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setFontAndSize → NO_COVERAGE

394

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

395

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setGrayFill → NO_COVERAGE

397

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfAppearance::setColorFill → NO_COVERAGE

398

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setDefaultAppearanceString → NO_COVERAGE

399

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

400

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setMKBorderColor → NO_COVERAGE

401

1.1
Location : getField
Killed by : none
negated conditional → NO_COVERAGE

402

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setMKBackgroundColor → NO_COVERAGE

405

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE

410

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE

413

1.1
Location : getField
Killed by : none
removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE

416

1.1
Location : getField
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/RadioCheckField::getField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2