Cell.java

1
/*
2
 * $Id: Cell.java 4065 2009-09-16 23:09:11Z psoares33 $
3
 * $Name$
4
 *
5
 * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * (the "License"); you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10
 *
11
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 * for the specific language governing rights and limitations under the License.
14
 *
15
 * The Original Code is 'iText, a free JAVA-PDF library'.
16
 *
17
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19
 * All Rights Reserved.
20
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22
 *
23
 * Contributor(s): all the names of the contributors are added in the source code
24
 * where applicable.
25
 *
26
 * Alternatively, the contents of this file may be used under the terms of the
27
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28
 * provisions of LGPL are applicable instead of those above.  If you wish to
29
 * allow use of your version of this file only under the terms of the LGPL
30
 * License and not to allow others to use your version of this file under
31
 * the MPL, indicate your decision by deleting the provisions above and
32
 * replace them with the notice and other provisions required by the LGPL.
33
 * If you do not delete the provisions above, a recipient may use your version
34
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35
 *
36
 * This library is free software; you can redistribute it and/or modify it
37
 * under the terms of the MPL as stated above or under the terms of the GNU
38
 * Library General Public License as published by the Free Software Foundation;
39
 * either version 2 of the License, or any later version.
40
 *
41
 * This library is distributed in the hope that it will be useful, but WITHOUT
42
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44
 * details.
45
 *
46
 * If you didn't download this code from the following link, you should check if
47
 * you aren't using an obsolete version:
48
 * http://www.lowagie.com/iText/
49
 */
50
51
package com.lowagie.text;
52
53
import com.lowagie.text.alignment.HorizontalAlignment;
54
import com.lowagie.text.alignment.VerticalAlignment;
55
import com.lowagie.text.alignment.WithHorizontalAlignment;
56
import com.lowagie.text.alignment.WithVerticalAlignment;
57
import java.util.ArrayList;
58
import java.util.Iterator;
59
import com.lowagie.text.error_messages.MessageLocalization;
60
61
import com.lowagie.text.pdf.PdfPCell;
62
63
/**
64
 * A <CODE>Cell</CODE> is a <CODE>Rectangle</CODE> containing other
65
 * <CODE>Element</CODE>s.
66
 * <P>
67
 * A <CODE>Cell</CODE> must be added to a <CODE>Table</CODE>.
68
 * The <CODE>Table</CODE> will place the <CODE>Cell</CODE> in
69
 * a <CODE>Row</CODE>.
70
 * <P>
71
 * Example:
72
 * <BLOCKQUOTE><PRE>
73
 * Table table = new Table(3);
74
 * table.setBorderWidth(1);
75
 * table.setBorderColor(new Color(0, 0, 255));
76
 * table.setCellpadding(5);
77
 * table.setCellspacing(5);
78
 * <STRONG>Cell cell = new Cell("header");</STRONG>
79
 * <STRONG>cell.setHeader(true);</STRONG>
80
 * <STRONG>cell.setColspan(3);</STRONG>
81
 * table.addCell(cell);
82
 * <STRONG>cell = new Cell("example cell with colspan 1 and rowspan 2");</STRONG>
83
 * <STRONG>cell.setRowspan(2);</STRONG>
84
 * <STRONG>cell.setBorderColor(new Color(255, 0, 0));</STRONG>
85
 * table.addCell(cell);
86
 * table.addCell("1.1");
87
 * table.addCell("2.1");
88
 * table.addCell("1.2");
89
 * table.addCell("2.2");
90
 * </PRE></BLOCKQUOTE>
91
 *
92
 * @see        Rectangle
93
 * @see        Element
94
 * @see        Table
95
 * @see        Row
96
 */
97
98
public class Cell extends Rectangle implements TextElementArray, WithHorizontalAlignment, WithVerticalAlignment {
99
100
    // membervariables
101
102
    /**
103
     * The <CODE>ArrayList</CODE> of <CODE>Element</CODE>s
104
     * that are part of the content of the Cell.
105
     */
106
    protected ArrayList arrayList = null;
107
108
    /** The horizontal alignment of the cell content. */
109
    protected int horizontalAlignment = Element.ALIGN_UNDEFINED;
110
111
    /** The vertical alignment of the cell content. */
112
    protected int verticalAlignment = Element.ALIGN_UNDEFINED;
113
114
    /**
115
     * The width of the cell as a String.
116
     * It can be an absolute value "100" or a percentage "20%".
117
     */
118
    protected float width;
119
    protected boolean percentage = false;
120
121
    /** The colspan of the cell. */
122
    protected int colspan = 1;
123
124
    /** The rowspan of the cell. */
125
    protected int rowspan = 1;
126
127
    /** The leading of the content inside the cell. */
128
    float leading = Float.NaN;
129
130
    /** Is this <CODE>Cell</CODE> a header? */
131
    protected boolean header;
132
133
    /**
134
     * Maximum number of lines allowed in the cell.  
135
     * The default value of this property is not to limit the maximum number of lines
136
     * (contributed by dperezcar@fcc.es)
137
     */
138
    protected int maxLines = Integer.MAX_VALUE;
139
    
140
    /**
141
     * If a truncation happens due to the maxLines property, then this text will 
142
     * be added to indicate a truncation has happened.
143
     * Default value is null, and means avoiding marking the truncation.  
144
     * A useful value of this property could be e.g. "..."
145
     * (contributed by dperezcar@fcc.es)
146
     */
147
    String showTruncation;
148
149
    /**
150
     * Indicates that the largest ascender height should be used to determine the
151
     * height of the first line.  Note that this only has an effect when rendered
152
     * to PDF.  Setting this to true can help with vertical alignment problems.
153
     */
154
    protected boolean useAscender = false;
155
156
    /**
157
     * Indicates that the largest descender height should be added to the height of
158
     * the last line (so characters like y don't dip into the border).   Note that
159
     * this only has an effect when rendered to PDF.
160
     */
161
    protected boolean useDescender = false;
162
163
    /**
164
     * Adjusts the cell contents to compensate for border widths.  Note that
165
     * this only has an effect when rendered to PDF.
166
     */
167
    protected boolean useBorderPadding;
168
    
169
    /** Does this <CODE>Cell</CODE> force a group change? */
170
    protected boolean groupChange = true;
171
172
    // constructors
173
174
    /** Constructs an empty <CODE>Cell</CODE>. */
175
    public Cell() {
176
        // creates a Rectangle with BY DEFAULT a border of 0.5
177
        super(0, 0, 0, 0);
178 1 1. : removed call to com/lowagie/text/Cell::setBorder → SURVIVED
        setBorder(UNDEFINED);
179 1 1. : removed call to com/lowagie/text/Cell::setBorderWidth → SURVIVED
        setBorderWidth(0.5f);
180
        // initializes the arraylist
181
        arrayList = new ArrayList();
182
    }
183
184
    /**
185
     * Constructs an empty <CODE>Cell</CODE> (for internal use only).
186
     *
187
     * @param   dummy   a dummy value
188
     */
189
    public Cell(boolean dummy) {
190
        this();
191
        arrayList.add(new Paragraph(0));
192
    }
193
194
    /**
195
     * Constructs a <CODE>Cell</CODE> with a certain content.<p>
196
     * The <CODE>String</CODE> will be converted into a <CODE>Paragraph</CODE>.
197
     * @param    content        a <CODE>String</CODE>
198
     */
199
    public Cell(String content) {
200
        this();
201
        try {
202 1 1. : removed call to com/lowagie/text/Cell::addElement → NO_COVERAGE
            addElement(new Paragraph(content));
203
        }
204
        catch(BadElementException bee) {
205
        }
206
    }
207
208
    /**
209
     * Constructs a <CODE>Cell</CODE> with a certain <CODE>Element</CODE>.<p>
210
     * if the element is a <CODE>ListItem</CODE>, <CODE>Row</CODE> or
211
     * <CODE>Cell</CODE>, an exception will be thrown.
212
     *
213
     * @param    element        the element
214
     * @throws    BadElementException when the creator was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
215
     */
216
    public Cell(Element element) throws BadElementException {
217
        this();
218 1 1. : negated conditional → NO_COVERAGE
         if(element instanceof Phrase) {
219 1 1. : removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE
            setLeading(((Phrase)element).getLeading());
220
        }
221 1 1. : removed call to com/lowagie/text/Cell::addElement → NO_COVERAGE
        addElement(element);
222
    }
223
224
    // implementation of the Element-methods
225
226
    /**
227
     * Processes the element by adding it (or the different parts) to an
228
     * <CODE>ElementListener</CODE>.
229
     *
230
     * @param    listener    an <CODE>ElementListener</CODE>
231
     * @return    <CODE>true</CODE> if the element was processed successfully
232
     */
233
    public boolean process(ElementListener listener) {
234
        try {
235 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return listener.add(this);
236
        }
237
        catch(DocumentException de) {
238 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
239
        }
240
    }
241
242
    /**
243
     * Gets the type of the text element.
244
     *
245
     * @return    a type
246
     */
247
    public int type() {
248
        return Element.CELL;
249
    }
250
251
    /**
252
     * Gets all the chunks in this element.
253
     *
254
     * @return    an <CODE>ArrayList</CODE>
255
     */
256
    public ArrayList getChunks() {
257
        ArrayList tmp = new ArrayList();
258
        for (Object o : arrayList) {
259
            tmp.addAll(((Element) o).getChunks());
260
        }
261 1 1. getChunks : mutated return of Object value for com/lowagie/text/Cell::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return tmp;
262
    }
263
264
    // Getters and setters
265
266
    /**
267
     * Gets the horizontal alignment.
268
     *
269
     * @return    a value
270
     */
271
       public int getHorizontalAlignment() {
272
           return horizontalAlignment;
273
       }
274
275
    /**
276
     * Sets the horizontal alignment.
277
     * @param    value    the new value
278
     * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
279
     * use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
280
     */
281
    public void setHorizontalAlignment(int value) {
282
        horizontalAlignment = value;
283
    }
284
285
    /**
286
     * Sets the alignment of this cell.
287
     * This methods allows you to set the alignment as a String.
288
     * @param    alignment        the new alignment as a <CODE>String</CODE>
289
     * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
290
     * use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
291
     */
292
    public void setHorizontalAlignment(String alignment) {
293
        setHorizontalAlignment(ElementTags.alignmentValue(alignment));
294
    }
295
296
    /**
297
     * Gets the vertical alignment.
298
     * @return    a value
299
     */
300
    public int getVerticalAlignment() {
301
        return verticalAlignment;
302
    }
303
304
    /**
305
     * Sets the vertical alignment.
306
     * @param    value    the new value
307
     * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
308
     * use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
309
     */
310
    public void setVerticalAlignment(int value) {
311
        verticalAlignment = value;
312
    }
313
314
    /**
315
     * Sets the alignment of this paragraph.
316
     *
317
     * @param    alignment        the new alignment as a <CODE>String</CODE>
318
     * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
319
     * use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
320
     */
321
    public void setVerticalAlignment(String alignment) {
322
        setVerticalAlignment(ElementTags.alignmentValue(alignment));
323
    }
324
325
    /**
326
     * Sets the width.
327
     *
328
     * @param    value    the new value
329
     */
330
    public void setWidth(float value) {
331
        this.width = value;
332
    }
333
    
334
    /**
335
     * Sets the width.
336
     * It can be an absolute value "100" or a percentage "20%"
337
     *
338
     * @param    value    the new value
339
     */
340
    public void setWidth(String value) {
341 1 1. setWidth : negated conditional → NO_COVERAGE
        if (value.endsWith("%")) {
342 1 1. setWidth : Replaced integer subtraction with addition → NO_COVERAGE
            value = value.substring(0, value.length() - 1);
343
            percentage = true;
344
        }
345
        width = Integer.parseInt(value);
346
    }
347
    
348
    /**
349
     * Gets the width.
350
     */
351
    public float getWidth() {
352
        return width;
353
    }
354
355
    /**
356
     * Gets the width as a String.
357
     *
358
     * @return    a value
359
     */
360
    public String getWidthAsString() {
361
        String w = String.valueOf(width);
362 2 1. getWidthAsString : negated conditional → SURVIVED
2. getWidthAsString : Replaced integer subtraction with addition → KILLED
        if (w.endsWith(".0")) w = w.substring(0, w.length() - 2);
363 1 1. getWidthAsString : negated conditional → SURVIVED
        if (percentage) w += "%";
364 1 1. getWidthAsString : mutated return of Object value for com/lowagie/text/Cell::getWidthAsString to ( if (x != null) null else throw new RuntimeException ) → SURVIVED
        return w;
365
    }
366
367
    /**
368
     * Sets the colspan.
369
     *
370
     * @param    value    the new value
371
     */
372
    public void setColspan(int value) {
373
        colspan = value;
374
    }
375
376
    /**
377
     * Gets the colspan.
378
     * @return    a value
379
     */
380
    public int getColspan() {
381
        return colspan;
382
    }
383
384
    /**
385
     * Sets the rowspan.
386
     *
387
     * @param    value    the new value
388
     */
389
    public void setRowspan(int value) {
390
        rowspan = value;
391
    }
392
393
    /**
394
     * Gets the rowspan.
395
     * @return    a value
396
     */
397
    public int getRowspan() {
398
        return rowspan;
399
    }
400
401
    /**
402
     * Sets the leading.
403
     *
404
     * @param    value    the new value
405
     */
406
    public void setLeading(float value) {
407
        leading = value;
408
    }
409
410
    /**
411
     * Gets the leading.
412
     *
413
     * @return    a value
414
     */
415
    public float getLeading() {
416 1 1. getLeading : negated conditional → NO_COVERAGE
        if (Float.isNaN(leading)) {
417 1 1. getLeading : replaced return of float value with -(x + 1) for com/lowagie/text/Cell::getLeading → NO_COVERAGE
            return 16;
418
        }
419 1 1. getLeading : replaced return of float value with -(x + 1) for com/lowagie/text/Cell::getLeading → NO_COVERAGE
        return leading;
420
    }
421
422
    /**
423
     * Sets header.
424
     *
425
     * @param    value    the new value
426
     */
427
    public void setHeader(boolean value) {
428
        header = value;
429
    }
430
431
    /**
432
     * Is this <CODE>Cell</CODE> a header?
433
     *
434
     * @return    a value
435
     */
436
    public boolean isHeader() {
437
        return header;
438
    }
439
    
440
    /**
441
     * Setter for maxLines
442
     * @param value the maximum number of lines
443
     */
444
    public void setMaxLines(int value) {
445
        maxLines = value;
446
    }
447
    
448
    /**
449
     * Getter for maxLines
450
     * @return the maxLines value
451
     */
452
    public int getMaxLines() {
453
        return maxLines;
454
    }
455
        
456
    /**
457
     * Setter for showTruncation
458
     * @param value    Can be null for avoiding marking the truncation.
459
     */
460
    public void setShowTruncation(String value) {
461
        showTruncation = value;
462
    }
463
    
464
    /**
465
     * Getter for showTruncation
466
     * @return the showTruncation value
467
     */
468
    public String getShowTruncation() {
469
        return showTruncation;
470
    }
471
472
    /**
473
     * Sets the value of useAscender.
474
     * @param use use ascender height if true
475
     */
476
    public void setUseAscender(boolean use) {
477
        useAscender = use;
478
    }
479
480
    /**
481
     * Gets the value of useAscender
482
     * @return useAscender
483
     */
484
    public boolean isUseAscender() {
485
        return useAscender;
486
    }
487
488
    /**
489
     * Sets the value of useDescender.
490
     * @param use use descender height if true
491
     */
492
    public void setUseDescender(boolean use) {
493
        useDescender = use;
494
    }
495
496
    /**
497
     * gets the value of useDescender
498
     * @return useDescender
499
     */
500
    public boolean isUseDescender() {
501
        return useDescender;
502
    }
503
504
    /**
505
     * Sets the value of useBorderPadding.
506
     * @param use adjust layout for borders if true
507
     */
508
    public void setUseBorderPadding(boolean use) {
509
        useBorderPadding = use;
510
    }
511
512
    /**
513
     * Gets the value of useBorderPadding.
514
     * @return useBorderPadding
515
     */
516
    public boolean isUseBorderPadding() {
517
        return useBorderPadding;
518
    }
519
520
    /**
521
     * Does this <CODE>Cell</CODE> force a group change?
522
     *
523
     * @return    a value
524
     */
525
    public boolean getGroupChange() {
526
        return groupChange;
527
    }
528
529
    /**
530
     * Sets group change.
531
     *
532
     * @param    value    the new value
533
     */
534
    public void setGroupChange(boolean value) {
535
        groupChange = value;
536
    }
537
    
538
// arraylist stuff
539
540
    /**
541
     * Gets the number of <CODE>Element</CODE>s in the Cell.
542
     *
543
     * @return    a <CODE>size</CODE>.
544
     */
545
    public int size() {
546
        return arrayList.size();
547
    }
548
549
    /**
550
     * Gets an iterator of <CODE>Element</CODE>s.
551
     *
552
     * @return    an <CODE>Iterator</CODE>.
553
     */
554
    public Iterator getElements() {
555
        return arrayList.iterator();
556
    }
557
    
558
    /**
559
     * Clears all the <CODE>Element</CODE>s of this <CODE>Cell</CODE>.
560
     */
561
    public void clear() {
562
        arrayList.clear();
563
    }
564
565
    /**
566
     * Checks if the <CODE>Cell</CODE> is empty.
567
     *
568
     * @return    <CODE>false</CODE> if there are non-empty <CODE>Element</CODE>s in the <CODE>Cell</CODE>.
569
     */
570
    public boolean isEmpty() {
571
        switch(size()) {
572
            case 0:
573 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                return true;
574
            case 1:
575
                Element element = (Element) arrayList.get(0);
576
                switch (element.type()) {
577
                    case Element.CHUNK:
578 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                        return ((Chunk) element).isEmpty();
579
                    case Element.ANCHOR:
580
                    case Element.PHRASE:
581
                    case Element.PARAGRAPH:
582 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                        return ((Phrase) element).isEmpty();
583
                    case Element.LIST:
584 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                        return ((List) element).isEmpty();
585
                }
586 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
587
            default:
588 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                return false;
589
        }
590
    }
591
    
592
    /**
593
     * Makes sure there is at least 1 object in the Cell.
594
     *
595
     * Otherwise it might not be shown in the table.
596
     */
597
    void fill() {
598 1 1. fill : negated conditional → SURVIVED
        if (size() == 0) arrayList.add(new Paragraph(0));
599
    }
600
601
    /**
602
     * Checks if this <CODE>Cell</CODE> is a placeholder for a (nested) table.
603
     *
604
     * @return    true if the only element in this cell is a table
605
     */
606
    public boolean isTable() {
607 2 1. isTable : negated conditional → KILLED
2. isTable : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
        return (size() == 1)
608 1 1. isTable : negated conditional → KILLED
            && (((Element)arrayList.get(0)).type() == Element.TABLE);
609
    }
610
    
611
    /**
612
     * Adds an element to this <CODE>Cell</CODE>.
613
     * <P>
614
     * Remark: you can't add <CODE>ListItem</CODE>s, <CODE>Row</CODE>s, <CODE>Cell</CODE>s,
615
     * <CODE>JPEG</CODE>s, <CODE>GIF</CODE>s or <CODE>PNG</CODE>s to a <CODE>Cell</CODE>.
616
     *
617
     * @param element The <CODE>Element</CODE> to add
618
     * @throws BadElementException if the method was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
619
     */
620
    public void addElement(Element element) throws BadElementException {
621 1 1. addElement : negated conditional → KILLED
        if (isTable()) {
622
            Table table = (Table) arrayList.get(0);
623
            Cell tmp = new Cell(element);
624 1 1. addElement : removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE
            tmp.setBorder(NO_BORDER);
625 1 1. addElement : removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE
            tmp.setColspan(table.getColumns());
626 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
            table.addCell(tmp);
627
            return;
628
        }
629
        switch(element.type()) {
630
            case Element.LISTITEM:
631
            case Element.ROW:
632
            case Element.CELL:
633
                throw new BadElementException(MessageLocalization.getComposedMessage("you.can.t.add.listitems.rows.or.cells.to.a.cell"));
634
            case Element.LIST:
635
                List list = (List)element;
636 1 1. addElement : negated conditional → NO_COVERAGE
                if (Float.isNaN(leading)) {
637 1 1. addElement : removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE
                    setLeading(list.getTotalLeading());
638
                }
639 1 1. addElement : negated conditional → NO_COVERAGE
                if (list.isEmpty()) return;
640
                arrayList.add(element);
641
                return;
642
            case Element.ANCHOR:
643
            case Element.PARAGRAPH:
644
            case Element.PHRASE:
645
                Phrase p = (Phrase)element;
646 1 1. addElement : negated conditional → NO_COVERAGE
                if (Float.isNaN(leading)) {
647 1 1. addElement : removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE
                    setLeading(p.getLeading());
648
                }
649 1 1. addElement : negated conditional → NO_COVERAGE
                if (p.isEmpty()) return;
650
                arrayList.add(element);
651
                return;
652
            case Element.CHUNK:
653 1 1. addElement : negated conditional → SURVIVED
                if (((Chunk) element).isEmpty()) return;
654
                arrayList.add(element);
655
                return;
656
            case Element.TABLE:
657
                Table table = new Table(3);
658
                float[] widths = new float[3];
659
                widths[1] = ((Table)element).getWidth();
660
                switch(((Table)element).getAlignment()) {
661
                    case Element.ALIGN_LEFT:
662
                        widths[0] = 0f;
663 1 1. addElement : Replaced float subtraction with addition → NO_COVERAGE
                        widths[2] = 100f - widths[1];
664
                        break;
665
                    case Element.ALIGN_CENTER:
666 2 1. addElement : Replaced float subtraction with addition → NO_COVERAGE
2. addElement : Replaced float division with multiplication → NO_COVERAGE
                        widths[0] = (100f - widths[1]) / 2f;
667
                        widths[2] = widths[0];
668
                        break;
669
                    case Element.ALIGN_RIGHT:
670 1 1. addElement : Replaced float subtraction with addition → NO_COVERAGE
                        widths[0] = 100f - widths[1];
671
                        widths[2] = 0f;
672
                }
673 1 1. addElement : removed call to com/lowagie/text/Table::setWidths → NO_COVERAGE
                table.setWidths(widths);
674
                Cell tmp;
675 1 1. addElement : negated conditional → NO_COVERAGE
                if (arrayList.isEmpty()) {
676 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
                    table.addCell(getDummyCell());
677
                }
678
                else {
679
                    tmp = new Cell();
680 1 1. addElement : removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE
                    tmp.setBorder(NO_BORDER);
681 1 1. addElement : removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE
                    tmp.setColspan(3);
682
                    for (Object o : arrayList) {
683
                        tmp.add(o);
684
                    }
685 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
                    table.addCell(tmp);
686
                }
687
                tmp = new Cell();
688 1 1. addElement : removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE
                tmp.setBorder(NO_BORDER);
689 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
                table.addCell(tmp);
690 1 1. addElement : removed call to com/lowagie/text/Table::insertTable → NO_COVERAGE
                table.insertTable((Table)element);
691
                tmp = new Cell();
692 1 1. addElement : removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE
                tmp.setBorder(NO_BORDER);
693 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
                table.addCell(tmp);
694 1 1. addElement : removed call to com/lowagie/text/Table::addCell → NO_COVERAGE
                table.addCell(getDummyCell());
695 1 1. addElement : removed call to com/lowagie/text/Cell::clear → NO_COVERAGE
                clear();
696
                arrayList.add(table);
697
                return;
698
            default:
699
                arrayList.add(element);
700
        }
701
    }
702
703
    /**
704
     * Add an <CODE>Object</CODE> to this cell.
705
     *
706
     * @param o the object to add
707
     * @return always <CODE>true</CODE>
708
     */
709
    public boolean add(Object o) {
710
        try {
711 1 1. add : removed call to com/lowagie/text/Cell::addElement → SURVIVED
            this.addElement((Element) o);
712 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
            return true;
713
        }
714
        catch(ClassCastException cce) {
715
            throw new ClassCastException(MessageLocalization.getComposedMessage("you.can.only.add.objects.that.implement.the.element.interface"));
716
        }
717
        catch(BadElementException bee) {
718
            throw new ClassCastException(bee.getMessage());
719
        }
720
    }
721
722
    // helper methods
723
    
724
    /**
725
     * Get dummy cell used when merging inner tables. 
726
     * @return a cell with colspan 3 and no border
727
     */
728
    private static Cell getDummyCell() {
729
        Cell cell = new Cell(true);
730 1 1. getDummyCell : removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE
        cell.setColspan(3);
731 1 1. getDummyCell : removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE
        cell.setBorder(NO_BORDER);
732 1 1. getDummyCell : mutated return of Object value for com/lowagie/text/Cell::getDummyCell to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return cell;
733
    }
734
735
    /**
736
     * Creates a PdfPCell based on this Cell object.
737
     * @return a PdfPCell
738
     * @throws BadElementException
739
     */
740
    public PdfPCell createPdfPCell() throws BadElementException {
741 2 1. createPdfPCell : changed conditional boundary → NO_COVERAGE
2. createPdfPCell : negated conditional → NO_COVERAGE
        if (rowspan > 1) throw new BadElementException(MessageLocalization.getComposedMessage("pdfpcells.can.t.have.a.rowspan.gt.1"));
742 2 1. createPdfPCell : negated conditional → NO_COVERAGE
2. createPdfPCell : mutated return of Object value for com/lowagie/text/Cell::createPdfPCell to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
743
        PdfPCell cell = new PdfPCell();
744 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setVerticalAlignment → NO_COVERAGE
        cell.setVerticalAlignment(verticalAlignment);
745 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setHorizontalAlignment → NO_COVERAGE
        cell.setHorizontalAlignment(horizontalAlignment);
746 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setColspan → NO_COVERAGE
        cell.setColspan(colspan);
747 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setUseBorderPadding → NO_COVERAGE
        cell.setUseBorderPadding(useBorderPadding);
748 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setUseDescender → NO_COVERAGE
        cell.setUseDescender(useDescender);
749 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setLeading → NO_COVERAGE
        cell.setLeading(getLeading(), 0);
750 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::cloneNonPositionParameters → NO_COVERAGE
        cell.cloneNonPositionParameters(this);
751 2 1. createPdfPCell : negated conditional → NO_COVERAGE
2. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::setNoWrap → NO_COVERAGE
        cell.setNoWrap(getMaxLines() == 1);
752 1 1. createPdfPCell : negated conditional → NO_COVERAGE
        for (Iterator i = getElements(); i.hasNext(); ) {
753
            Element e = (Element)i.next();
754 2 1. createPdfPCell : negated conditional → NO_COVERAGE
2. createPdfPCell : negated conditional → NO_COVERAGE
            if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) {
755
                Paragraph p = new Paragraph((Phrase)e);
756 1 1. createPdfPCell : removed call to com/lowagie/text/Paragraph::setAlignment → NO_COVERAGE
                p.setAlignment(horizontalAlignment);
757
                e = p;
758
            }
759 1 1. createPdfPCell : removed call to com/lowagie/text/pdf/PdfPCell::addElement → NO_COVERAGE
            cell.addElement(e);
760
        }
761 1 1. createPdfPCell : mutated return of Object value for com/lowagie/text/Cell::createPdfPCell to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return cell;
762
    }
763
764
    // unsupported Rectangle methods
765
766
    /**
767
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
768
     * @return NA
769
     */
770
    public float getTop() {
771
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
772
    }
773
774
    /**
775
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
776
     * @return NA
777
     */
778
    public float getBottom() {
779
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
780
    }
781
782
    /**
783
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
784
     * @return NA
785
     */
786
    public float getLeft() {
787
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
788
    }
789
790
    /**
791
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
792
     * @return NA
793
     */
794
    public float getRight() {
795
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
796
    }
797
798
    /**
799
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
800
     * @param margin
801
     * @return NA
802
     */
803
    public float top(int margin) {
804
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
805
    }
806
807
    /**
808
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
809
     * @param margin
810
     * @return NA
811
     */
812
    public float bottom(int margin) {
813
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
814
    }
815
816
    /**
817
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
818
     * @param margin
819
     * @return NA
820
     */
821
    public float left(int margin) {
822
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
823
    }
824
825
    /**
826
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
827
     * @param margin NA
828
     * @return NA
829
     */
830
    public float right(int margin) {
831
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.can.t.be.calculated.see.the.faq"));
832
    }
833
834
    /**
835
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
836
     * @param value NA
837
     */
838
    public void setTop(int value) {
839
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.are.attributed.automagically.see.the.faq"));
840
    }
841
842
    /**
843
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
844
     * @param value NA
845
     */
846
    public void setBottom(int value) {
847
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.are.attributed.automagically.see.the.faq"));
848
    }
849
850
    /**
851
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
852
     * @param value NA
853
     */
854
    public void setLeft(int value) {
855
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.are.attributed.automagically.see.the.faq"));
856
    }
857
858
    /**
859
     * This method throws an <CODE>UnsupportedOperationException</CODE>.
860
     * @param value NA
861
     */
862
    public void setRight(int value) {
863
        throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("dimensions.of.a.cell.are.attributed.automagically.see.the.faq"));
864
    }
865
866
    @Override
867
    public void setHorizontalAlignment(final HorizontalAlignment alignment) {
868 1 1. setHorizontalAlignment : negated conditional → NO_COVERAGE
        if (alignment == null) {
869
            return;
870
        }
871
872
        horizontalAlignment = alignment.getId();
873
    }
874
875
    @Override
876
    public void setVerticalAlignment(final VerticalAlignment alignment) {
877 1 1. setVerticalAlignment : negated conditional → NO_COVERAGE
        if (alignment == null) {
878
            return;
879
        }
880
881
        verticalAlignment = alignment.getId();
882
    }
883
}

Mutations

178

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → SURVIVED

179

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Cell::setBorderWidth → SURVIVED

202

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Cell::addElement → NO_COVERAGE

218

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

219

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE

221

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Cell::addElement → NO_COVERAGE

235

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

238

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

261

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

341

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

342

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

362

1.1
Location : getWidthAsString
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
Replaced integer subtraction with addition → KILLED

2.2
Location : getWidthAsString
Killed by : none
negated conditional → SURVIVED

363

1.1
Location : getWidthAsString
Killed by : none
negated conditional → SURVIVED

364

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

416

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

417

1.1
Location : getLeading
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Cell::getLeading → NO_COVERAGE

419

1.1
Location : getLeading
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Cell::getLeading → NO_COVERAGE

573

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

578

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

582

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

584

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

586

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

588

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

598

1.1
Location : fill
Killed by : none
negated conditional → SURVIVED

607

1.1
Location : isTable
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

2.2
Location : isTable
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

608

1.1
Location : isTable
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

621

1.1
Location : addElement
Killed by : com.lowagie.text.html.HtmlParserTest.testParse_tableWithSpaces()
negated conditional → KILLED

624

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE

625

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE

626

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

636

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

637

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE

639

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

646

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

647

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setLeading → NO_COVERAGE

649

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

653

1.1
Location : addElement
Killed by : none
negated conditional → SURVIVED

663

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

666

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

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

670

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

673

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::setWidths → NO_COVERAGE

675

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

676

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

680

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE

681

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE

685

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

688

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE

689

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

690

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::insertTable → NO_COVERAGE

692

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE

693

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

694

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Table::addCell → NO_COVERAGE

695

1.1
Location : addElement
Killed by : none
removed call to com/lowagie/text/Cell::clear → NO_COVERAGE

711

1.1
Location : add
Killed by : none
removed call to com/lowagie/text/Cell::addElement → SURVIVED

712

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED

730

1.1
Location : getDummyCell
Killed by : none
removed call to com/lowagie/text/Cell::setColspan → NO_COVERAGE

731

1.1
Location : getDummyCell
Killed by : none
removed call to com/lowagie/text/Cell::setBorder → NO_COVERAGE

732

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

741

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

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

742

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

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

744

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setVerticalAlignment → NO_COVERAGE

745

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setHorizontalAlignment → NO_COVERAGE

746

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setColspan → NO_COVERAGE

747

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setUseBorderPadding → NO_COVERAGE

748

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setUseDescender → NO_COVERAGE

749

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setLeading → NO_COVERAGE

750

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::cloneNonPositionParameters → NO_COVERAGE

751

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

2.2
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::setNoWrap → NO_COVERAGE

752

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

754

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

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

756

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/Paragraph::setAlignment → NO_COVERAGE

759

1.1
Location : createPdfPCell
Killed by : none
removed call to com/lowagie/text/pdf/PdfPCell::addElement → NO_COVERAGE

761

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

868

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

877

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

Active mutators

Tests examined


Report generated by PIT 1.4.2