1 | /* | |
2 | * $Id: Section.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 java.util.ArrayList; | |
54 | import java.util.Collection; | |
55 | import java.util.Iterator; | |
56 | import com.lowagie.text.error_messages.MessageLocalization; | |
57 | ||
58 | /** | |
59 | * A <CODE>Section</CODE> is a part of a <CODE>Document</CODE> containing | |
60 | * other <CODE>Section</CODE>s, <CODE>Paragraph</CODE>s, <CODE>List</CODE> | |
61 | * and/or <CODE>Table</CODE>s. | |
62 | * <P> | |
63 | * Remark: you can not construct a <CODE>Section</CODE> yourself. | |
64 | * You will have to ask an instance of <CODE>Section</CODE> to the | |
65 | * <CODE>Chapter</CODE> or <CODE>Section</CODE> to which you want to | |
66 | * add the new <CODE>Section</CODE>. | |
67 | * <P> | |
68 | * Example: | |
69 | * <BLOCKQUOTE><PRE> | |
70 | * Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255))); | |
71 | * Chapter chapter2 = new Chapter(title2, 2); | |
72 | * Paragraph someText = new Paragraph("This is some text"); | |
73 | * chapter2.add(someText); | |
74 | * Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0))); | |
75 | * <STRONG>Section section1 = chapter2.addSection(title21);</STRONG> | |
76 | * Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section."); | |
77 | * <STRONG>section1.add(someSectionText);</STRONG> | |
78 | * Paragraph title211 = new Paragraph("This is SubSection 1 in Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, new Color(255, 0, 0))); | |
79 | * <STRONG>Section section11 = section1.addSection(40, title211, 2);</STRONG> | |
80 | * <STRONG>section11.add(someSectionText);</STRONG> | |
81 | * </PRE></BLOCKQUOTE> | |
82 | */ | |
83 | ||
84 | public class Section extends ArrayList implements TextElementArray, LargeElement { | |
85 | // constant | |
86 | /** | |
87 | * A possible number style. The default number style: "1.2.3." | |
88 | * @since iText 2.0.8 | |
89 | */ | |
90 | public static final int NUMBERSTYLE_DOTTED = 0; | |
91 | /** | |
92 | * A possible number style. For instance: "1.2.3" | |
93 | * @since iText 2.0.8 | |
94 | */ | |
95 | public static final int NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT = 1; | |
96 | | |
97 | /** A serial version uid. */ | |
98 | private static final long serialVersionUID = 3324172577544748043L; | |
99 | ||
100 | // member variables | |
101 | | |
102 | /** The title of this section. */ | |
103 | protected Paragraph title; | |
104 | | |
105 | /** The bookmark title if different from the content title */ | |
106 | protected String bookmarkTitle; | |
107 | ||
108 | /** The number of sectionnumbers that has to be shown before the section title. */ | |
109 | protected int numberDepth; | |
110 | | |
111 | /** | |
112 | * The style for sectionnumbers. | |
113 | * @since iText 2.0.8 | |
114 | */ | |
115 | protected int numberStyle = NUMBERSTYLE_DOTTED; | |
116 | | |
117 | /** The indentation of this section on the left side. */ | |
118 | protected float indentationLeft; | |
119 | | |
120 | /** The indentation of this section on the right side. */ | |
121 | protected float indentationRight; | |
122 | | |
123 | /** The additional indentation of the content of this section. */ | |
124 | protected float indentation; | |
125 | | |
126 | /** false if the bookmark children are not visible */ | |
127 | protected boolean bookmarkOpen = true; | |
128 | | |
129 | /** true if the section has to trigger a new page */ | |
130 | protected boolean triggerNewPage = false; | |
131 | | |
132 | /** This is the number of subsections. */ | |
133 | protected int subsections = 0; | |
134 | | |
135 | /** This is the complete list of sectionnumbers of this section and the parents of this section. */ | |
136 | protected ArrayList numbers = null; | |
137 | | |
138 | /** | |
139 | * Indicates if the Section will be complete once added to the document. | |
140 | * @since iText 2.0.8 | |
141 | */ | |
142 | protected boolean complete = true; | |
143 | | |
144 | /** | |
145 | * Indicates if the Section was added completely to the document. | |
146 | * @since iText 2.0.8 | |
147 | */ | |
148 | protected boolean addedCompletely = false; | |
149 | | |
150 | /** | |
151 | * Indicates if this is the first time the section was added. | |
152 | * @since iText 2.0.8 | |
153 | */ | |
154 | protected boolean notAddedYet = true; | |
155 | | |
156 | // constructors | |
157 | | |
158 | /** | |
159 | * Constructs a new <CODE>Section</CODE>. | |
160 | */ | |
161 | protected Section() { | |
162 | title = new Paragraph(); | |
163 | numberDepth = 1; | |
164 | } | |
165 | | |
166 | /** | |
167 | * Constructs a new <CODE>Section</CODE>. | |
168 | * | |
169 | * @param title a <CODE>Paragraph</CODE> | |
170 | * @param numberDepth the numberDepth | |
171 | */ | |
172 | protected Section(Paragraph title, int numberDepth) { | |
173 | this.numberDepth = numberDepth; | |
174 | this.title = title; | |
175 | } | |
176 | | |
177 | // implementation of the Element-methods | |
178 | | |
179 | /** | |
180 | * Processes the element by adding it (or the different parts) to an | |
181 | * <CODE>ElementListener</CODE>. | |
182 | * | |
183 | * @param listener the <CODE>ElementListener</CODE> | |
184 | * @return <CODE>true</CODE> if the element was processed successfully | |
185 | */ | |
186 | public boolean process(ElementListener listener) { | |
187 | try { | |
188 | Element element; | |
189 | for (Object o : this) { | |
190 | element = (Element) o; | |
191 | listener.add(element); | |
192 | } | |
193 |
1
1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
194 | } | |
195 | catch(DocumentException de) { | |
196 |
1
1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
197 | } | |
198 | } | |
199 | | |
200 | /** | |
201 | * Gets the type of the text element. | |
202 | * | |
203 | * @return a type | |
204 | */ | |
205 | public int type() { | |
206 | return Element.SECTION; | |
207 | } | |
208 | | |
209 | /** | |
210 | * Checks if this object is a <CODE>Chapter</CODE>. | |
211 | * | |
212 | * @return <CODE>true</CODE> if it is a <CODE>Chapter</CODE>, | |
213 | * <CODE>false</CODE> if it is a <CODE>Section</CODE>. | |
214 | */ | |
215 | public boolean isChapter() { | |
216 |
2
1. isChapter : negated conditional → NO_COVERAGE 2. isChapter : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type() == Element.CHAPTER; |
217 | } | |
218 | | |
219 | /** | |
220 | * Checks if this object is a <CODE>Section</CODE>. | |
221 | * | |
222 | * @return <CODE>true</CODE> if it is a <CODE>Section</CODE>, | |
223 | * <CODE>false</CODE> if it is a <CODE>Chapter</CODE>. | |
224 | */ | |
225 | public boolean isSection() { | |
226 |
2
1. isSection : negated conditional → NO_COVERAGE 2. isSection : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type() == Element.SECTION; |
227 | } | |
228 | | |
229 | /** | |
230 | * Gets all the chunks in this element. | |
231 | * | |
232 | * @return an <CODE>ArrayList</CODE> | |
233 | */ | |
234 | public ArrayList getChunks() { | |
235 | ArrayList tmp = new ArrayList(); | |
236 | for (Object o : this) { | |
237 | tmp.addAll(((Element) o).getChunks()); | |
238 | } | |
239 |
1
1. getChunks : mutated return of Object value for com/lowagie/text/Section::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return tmp; |
240 | } | |
241 | | |
242 | /** | |
243 | * @see com.lowagie.text.Element#isContent() | |
244 | * @since iText 2.0.8 | |
245 | */ | |
246 | public boolean isContent() { | |
247 | return true; | |
248 | } | |
249 | ||
250 | /** | |
251 | * @see com.lowagie.text.Element#isNestable() | |
252 | * @since iText 2.0.8 | |
253 | */ | |
254 | public boolean isNestable() { | |
255 | return false; | |
256 | } | |
257 | | |
258 | // overriding some of the ArrayList-methods | |
259 | | |
260 | /** | |
261 | * Adds a <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE> | |
262 | * to this <CODE>Section</CODE>. | |
263 | * | |
264 | * @param index index at which the specified element is to be inserted | |
265 | * @param o an object of type <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE>= | |
266 | * @throws ClassCastException if the object is not a <CODE>Paragraph</CODE>, <CODE>List</CODE> or <CODE>Table</CODE> | |
267 | */ | |
268 | public void add(int index, Object o) { | |
269 |
1
1. add : negated conditional → NO_COVERAGE |
if (isAddedCompletely()) { |
270 | throw new IllegalStateException(MessageLocalization.getComposedMessage("this.largeelement.has.already.been.added.to.the.document")); | |
271 | } | |
272 | try { | |
273 | Element element = (Element) o; | |
274 |
1
1. add : negated conditional → NO_COVERAGE |
if (element.isNestable()) { |
275 |
1
1. add : removed call to java/util/ArrayList::add → NO_COVERAGE |
super.add(index, element); |
276 | } | |
277 | else { | |
278 | throw new ClassCastException(MessageLocalization.getComposedMessage("you.can.t.add.a.1.to.a.section", element.getClass().getName())); | |
279 | } | |
280 | } | |
281 | catch(ClassCastException cce) { | |
282 | throw new ClassCastException(MessageLocalization.getComposedMessage("insertion.of.illegal.element.1", cce.getMessage())); | |
283 | } | |
284 | } | |
285 | | |
286 | /** | |
287 | * Adds a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or another <CODE>Section</CODE> | |
288 | * to this <CODE>Section</CODE>. | |
289 | * | |
290 | * @param o an object of type <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or another <CODE>Section</CODE> | |
291 | * @return a boolean | |
292 | * @throws ClassCastException if the object is not a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> or <CODE>Section</CODE> | |
293 | */ | |
294 | public boolean add(Object o) { | |
295 |
1
1. add : negated conditional → NO_COVERAGE |
if (isAddedCompletely()) { |
296 | throw new IllegalStateException(MessageLocalization.getComposedMessage("this.largeelement.has.already.been.added.to.the.document")); | |
297 | } | |
298 | try { | |
299 | Element element = (Element) o; | |
300 |
1
1. add : negated conditional → NO_COVERAGE |
if (element.type() == Element.SECTION) { |
301 | Section section = (Section) o; | |
302 |
2
1. add : Replaced integer addition with subtraction → NO_COVERAGE 2. add : removed call to com/lowagie/text/Section::setNumbers → NO_COVERAGE |
section.setNumbers(++subsections, numbers); |
303 |
1
1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return super.add(section); |
304 | } | |
305 |
2
1. add : negated conditional → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
else if (o instanceof MarkedSection && ((MarkedObject)o).element.type() == Element.SECTION) { |
306 | MarkedSection mo = (MarkedSection)o; | |
307 | Section section = (Section)mo.element; | |
308 |
2
1. add : Replaced integer addition with subtraction → NO_COVERAGE 2. add : removed call to com/lowagie/text/Section::setNumbers → NO_COVERAGE |
section.setNumbers(++subsections, numbers); |
309 |
1
1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return super.add(mo); |
310 | } | |
311 |
1
1. add : negated conditional → NO_COVERAGE |
else if (element.isNestable()) { |
312 |
1
1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return super.add(o); |
313 | } | |
314 | else { | |
315 | throw new ClassCastException(MessageLocalization.getComposedMessage("you.can.t.add.a.1.to.a.section", element.getClass().getName())); | |
316 | } | |
317 | } | |
318 | catch(ClassCastException cce) { | |
319 | throw new ClassCastException(MessageLocalization.getComposedMessage("insertion.of.illegal.element.1", cce.getMessage())); | |
320 | } | |
321 | } | |
322 | | |
323 | /** | |
324 | * Adds a collection of <CODE>Element</CODE>s | |
325 | * to this <CODE>Section</CODE>. | |
326 | * | |
327 | * @param collection a collection of <CODE>Paragraph</CODE>s, <CODE>List</CODE>s and/or <CODE>Table</CODE>s | |
328 | * @return <CODE>true</CODE> if the action succeeded, <CODE>false</CODE> if not. | |
329 | * @throws ClassCastException if one of the objects isn't a <CODE>Paragraph</CODE>, <CODE>List</CODE>, <CODE>Table</CODE> | |
330 | */ | |
331 | public boolean addAll(Collection collection) { | |
332 | for (Object o : collection) { | |
333 | this.add(o); | |
334 | } | |
335 |
1
1. addAll : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
336 | } | |
337 | | |
338 | // methods that return a Section | |
339 | | |
340 | /** | |
341 | * Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it. | |
342 | * | |
343 | * @param indentation the indentation of the new section | |
344 | * @param title the title of the new section | |
345 | * @param numberDepth the numberDepth of the section | |
346 | * @return a new Section object | |
347 | */ | |
348 | public Section addSection(float indentation, Paragraph title, int numberDepth) { | |
349 |
1
1. addSection : negated conditional → NO_COVERAGE |
if (isAddedCompletely()) { |
350 | throw new IllegalStateException(MessageLocalization.getComposedMessage("this.largeelement.has.already.been.added.to.the.document")); | |
351 | } | |
352 | Section section = new Section(title, numberDepth); | |
353 |
1
1. addSection : removed call to com/lowagie/text/Section::setIndentation → NO_COVERAGE |
section.setIndentation(indentation); |
354 | add(section); | |
355 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return section; |
356 | } | |
357 | | |
358 | /** | |
359 | * Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it. | |
360 | * | |
361 | * @param indentation the indentation of the new section | |
362 | * @param title the title of the new section | |
363 | * @return a new Section object | |
364 | */ | |
365 | public Section addSection(float indentation, Paragraph title) { | |
366 |
2
1. addSection : Replaced integer addition with subtraction → NO_COVERAGE 2. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(indentation, title, numberDepth + 1); |
367 | } | |
368 | | |
369 | /** | |
370 | * Creates a <CODE>Section</CODE>, add it to this <CODE>Section</CODE> and returns it. | |
371 | * | |
372 | * @param title the title of the new section | |
373 | * @param numberDepth the numberDepth of the section | |
374 | * @return a new Section object | |
375 | */ | |
376 | public Section addSection(Paragraph title, int numberDepth) { | |
377 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(0, title, numberDepth); |
378 | } | |
379 | | |
380 | /** | |
381 | * Adds a marked section. For use in class MarkedSection only! | |
382 | */ | |
383 | public MarkedSection addMarkedSection() { | |
384 |
1
1. addMarkedSection : Replaced integer addition with subtraction → NO_COVERAGE |
MarkedSection section = new MarkedSection(new Section(null, numberDepth + 1)); |
385 | add(section); | |
386 |
1
1. addMarkedSection : mutated return of Object value for com/lowagie/text/Section::addMarkedSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return section; |
387 | } | |
388 | | |
389 | /** | |
390 | * Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it. | |
391 | * | |
392 | * @param title the title of the new section | |
393 | * @return a new Section object | |
394 | */ | |
395 | public Section addSection(Paragraph title) { | |
396 |
2
1. addSection : Replaced integer addition with subtraction → NO_COVERAGE 2. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(0, title, numberDepth + 1); |
397 | } | |
398 | | |
399 | /** | |
400 | * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. | |
401 | * | |
402 | * @param indentation the indentation of the new section | |
403 | * @param title the title of the new section | |
404 | * @param numberDepth the numberDepth of the section | |
405 | * @return a new Section object | |
406 | */ | |
407 | public Section addSection(float indentation, String title, int numberDepth) { | |
408 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(indentation, new Paragraph(title), numberDepth); |
409 | } | |
410 | | |
411 | /** | |
412 | * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. | |
413 | * | |
414 | * @param title the title of the new section | |
415 | * @param numberDepth the numberDepth of the section | |
416 | * @return a new Section object | |
417 | */ | |
418 | public Section addSection(String title, int numberDepth) { | |
419 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(new Paragraph(title), numberDepth); |
420 | } | |
421 | | |
422 | /** | |
423 | * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. | |
424 | * | |
425 | * @param indentation the indentation of the new section | |
426 | * @param title the title of the new section | |
427 | * @return a new Section object | |
428 | */ | |
429 | public Section addSection(float indentation, String title) { | |
430 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(indentation, new Paragraph(title)); |
431 | } | |
432 | | |
433 | /** | |
434 | * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. | |
435 | * | |
436 | * @param title the title of the new section | |
437 | * @return a new Section object | |
438 | */ | |
439 | public Section addSection(String title) { | |
440 |
1
1. addSection : mutated return of Object value for com/lowagie/text/Section::addSection to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return addSection(new Paragraph(title)); |
441 | } | |
442 | | |
443 | // public methods | |
444 | | |
445 | /** | |
446 | * Sets the title of this section. | |
447 | * | |
448 | * @param title the new title | |
449 | */ | |
450 | public void setTitle(Paragraph title) { | |
451 | this.title = title; | |
452 | } | |
453 | ||
454 | /** | |
455 | * Returns the title, preceded by a certain number of sectionnumbers. | |
456 | * | |
457 | * @return a <CODE>Paragraph</CODE> | |
458 | */ | |
459 | public Paragraph getTitle() { | |
460 |
1
1. getTitle : mutated return of Object value for com/lowagie/text/Section::getTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return constructTitle(title, numbers, numberDepth, numberStyle); |
461 | } | |
462 | | |
463 | /** | |
464 | * Constructs a Paragraph that will be used as title for a Section or Chapter. | |
465 | * @param title the title of the section | |
466 | * @param numbers a list of sectionnumbers | |
467 | * @param numberDepth how many numbers have to be shown | |
468 | * @param numberStyle the numbering style | |
469 | * @return a Paragraph object | |
470 | * @since iText 2.0.8 | |
471 | */ | |
472 | public static Paragraph constructTitle(Paragraph title, ArrayList numbers, int numberDepth, int numberStyle) { | |
473 |
1
1. constructTitle : negated conditional → NO_COVERAGE |
if (title == null) { |
474 |
1
1. constructTitle : mutated return of Object value for com/lowagie/text/Section::constructTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
475 | } | |
476 | ||
477 | int depth = Math.min(numbers.size(), numberDepth); | |
478 |
2
1. constructTitle : changed conditional boundary → NO_COVERAGE 2. constructTitle : negated conditional → NO_COVERAGE |
if (depth < 1) { |
479 |
1
1. constructTitle : mutated return of Object value for com/lowagie/text/Section::constructTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return title; |
480 | } | |
481 | StringBuilder buf = new StringBuilder(" "); | |
482 |
3
1. constructTitle : changed conditional boundary → NO_COVERAGE 2. constructTitle : Changed increment from 1 to -1 → NO_COVERAGE 3. constructTitle : negated conditional → NO_COVERAGE |
for (int i = 0; i < depth; i++) { |
483 | buf.insert(0, "."); | |
484 | buf.insert(0, ((Integer) numbers.get(i)).intValue()); | |
485 | } | |
486 |
1
1. constructTitle : negated conditional → NO_COVERAGE |
if (numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT) { |
487 |
1
1. constructTitle : Replaced integer subtraction with addition → NO_COVERAGE |
buf.deleteCharAt(buf.length() - 2); |
488 | } | |
489 | Paragraph result = new Paragraph(title); | |
490 |
1
1. constructTitle : removed call to com/lowagie/text/Paragraph::add → NO_COVERAGE |
result.add(0, new Chunk(buf.toString(), title.getFont())); |
491 |
1
1. constructTitle : mutated return of Object value for com/lowagie/text/Section::constructTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return result; |
492 | } | |
493 | | |
494 | /** | |
495 | * Sets the depth of the sectionnumbers that will be shown preceding the title. | |
496 | * <P> | |
497 | * If the numberdepth is 0, the sections will not be numbered. If the numberdepth | |
498 | * is 1, the section will be numbered with their own number. If the numberdepth is | |
499 | * higher (for instance x > 1), the numbers of x - 1 parents will be shown. | |
500 | * | |
501 | * @param numberDepth the new numberDepth | |
502 | */ | |
503 | public void setNumberDepth(int numberDepth) { | |
504 | this.numberDepth = numberDepth; | |
505 | } | |
506 | | |
507 | /** | |
508 | * Returns the numberdepth of this <CODE>Section</CODE>. | |
509 | * | |
510 | * @return the numberdepth | |
511 | */ | |
512 | public int getNumberDepth() { | |
513 | return numberDepth; | |
514 | } | |
515 | ||
516 | /** | |
517 | * Sets the style for numbering sections. | |
518 | * Possible values are NUMBERSTYLE_DOTTED: 1.2.3. (the default) | |
519 | * or NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT: 1.2.3 | |
520 | * @since iText 2.0.8 | |
521 | */ | |
522 | public void setNumberStyle(int numberStyle) { | |
523 | this.numberStyle = numberStyle; | |
524 | } | |
525 | | |
526 | /** | |
527 | * Gets the style used for numbering sections. | |
528 | * @since iText 2.0.8 | |
529 | * @return a value corresponding with a numbering style | |
530 | */ | |
531 | public int getNumberStyle() { | |
532 | return numberStyle; | |
533 | } | |
534 | | |
535 | /** | |
536 | * Sets the indentation of this <CODE>Section</CODE> on the left side. | |
537 | * | |
538 | * @param indentation the indentation | |
539 | */ | |
540 | public void setIndentationLeft(float indentation) { | |
541 | indentationLeft = indentation; | |
542 | } | |
543 | ||
544 | /** | |
545 | * Returns the indentation of this <CODE>Section</CODE> on the left side. | |
546 | * | |
547 | * @return the indentation | |
548 | */ | |
549 | public float getIndentationLeft() { | |
550 | return indentationLeft; | |
551 | } | |
552 | | |
553 | /** | |
554 | * Sets the indentation of this <CODE>Section</CODE> on the right side. | |
555 | * | |
556 | * @param indentation the indentation | |
557 | */ | |
558 | public void setIndentationRight(float indentation) { | |
559 | indentationRight = indentation; | |
560 | } | |
561 | ||
562 | /** | |
563 | * Returns the indentation of this <CODE>Section</CODE> on the right side. | |
564 | * | |
565 | * @return the indentation | |
566 | */ | |
567 | public float getIndentationRight() { | |
568 | return indentationRight; | |
569 | } | |
570 | | |
571 | /** | |
572 | * Sets the indentation of the content of this <CODE>Section</CODE>. | |
573 | * | |
574 | * @param indentation the indentation | |
575 | */ | |
576 | public void setIndentation(float indentation) { | |
577 | this.indentation = indentation; | |
578 | } | |
579 | ||
580 | /** | |
581 | * Returns the indentation of the content of this <CODE>Section</CODE>. | |
582 | * | |
583 | * @return the indentation | |
584 | */ | |
585 | public float getIndentation() { | |
586 | return indentation; | |
587 | } | |
588 | | |
589 | /** Setter for property bookmarkOpen. | |
590 | * @param bookmarkOpen false if the bookmark children are not | |
591 | * visible. | |
592 | */ | |
593 | public void setBookmarkOpen(boolean bookmarkOpen) { | |
594 | this.bookmarkOpen = bookmarkOpen; | |
595 | } | |
596 | | |
597 | /** | |
598 | * Getter for property bookmarkOpen. | |
599 | * @return Value of property bookmarkOpen. | |
600 | */ | |
601 | public boolean isBookmarkOpen() { | |
602 | return bookmarkOpen; | |
603 | } | |
604 | | |
605 | /** | |
606 | * Setter for property triggerNewPage. | |
607 | * @param triggerNewPage true if a new page has to be triggered. | |
608 | */ | |
609 | public void setTriggerNewPage(boolean triggerNewPage) { | |
610 | this.triggerNewPage = triggerNewPage; | |
611 | } | |
612 | ||
613 | /** | |
614 | * Getter for property bookmarkOpen. | |
615 | * @return Value of property triggerNewPage. | |
616 | */ | |
617 | public boolean isTriggerNewPage() { | |
618 |
3
1. isTriggerNewPage : negated conditional → NO_COVERAGE 2. isTriggerNewPage : negated conditional → NO_COVERAGE 3. isTriggerNewPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return triggerNewPage && notAddedYet; |
619 | } | |
620 | | |
621 | /** | |
622 | * Sets the bookmark title. The bookmark title is the same as the section title but | |
623 | * can be changed with this method. | |
624 | * @param bookmarkTitle the bookmark title | |
625 | */ | |
626 | public void setBookmarkTitle(String bookmarkTitle) { | |
627 | this.bookmarkTitle = bookmarkTitle; | |
628 | } | |
629 | ||
630 | /** | |
631 | * Gets the bookmark title. | |
632 | * @return the bookmark title | |
633 | */ | |
634 | public Paragraph getBookmarkTitle() { | |
635 |
1
1. getBookmarkTitle : negated conditional → NO_COVERAGE |
if (bookmarkTitle == null) |
636 |
1
1. getBookmarkTitle : mutated return of Object value for com/lowagie/text/Section::getBookmarkTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getTitle(); |
637 | else | |
638 |
1
1. getBookmarkTitle : mutated return of Object value for com/lowagie/text/Section::getBookmarkTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Paragraph(bookmarkTitle); |
639 | } | |
640 | | |
641 | /** | |
642 | * Changes the Chapter number. | |
643 | */ | |
644 | public void setChapterNumber(int number) { | |
645 |
1
1. setChapterNumber : Replaced integer subtraction with addition → NO_COVERAGE |
numbers.set(numbers.size() - 1, number); |
646 | Object s; | |
647 | for (Object o : this) { | |
648 | s = o; | |
649 |
1
1. setChapterNumber : negated conditional → NO_COVERAGE |
if (s instanceof Section) { |
650 |
1
1. setChapterNumber : removed call to com/lowagie/text/Section::setChapterNumber → NO_COVERAGE |
((Section) s).setChapterNumber(number); |
651 | } | |
652 | } | |
653 | } | |
654 | ||
655 | /** | |
656 | * Returns the depth of this section. | |
657 | * | |
658 | * @return the depth | |
659 | */ | |
660 | public int getDepth() { | |
661 | return numbers.size(); | |
662 | } | |
663 | | |
664 | // private methods | |
665 | | |
666 | /** | |
667 | * Sets the number of this section. | |
668 | * | |
669 | * @param number the number of this section | |
670 | * @param numbers an <CODE>ArrayList</CODE>, containing the numbers of the Parent | |
671 | */ | |
672 | private void setNumbers(int number, ArrayList numbers) { | |
673 | this.numbers = new ArrayList(); | |
674 | this.numbers.add(number); | |
675 | this.numbers.addAll(numbers); | |
676 | } | |
677 | ||
678 | /** | |
679 | * Indicates if this is the first time the section is added. | |
680 | * @since iText2.0.8 | |
681 | * @return true if the section wasn't added yet | |
682 | */ | |
683 | public boolean isNotAddedYet() { | |
684 | return notAddedYet; | |
685 | } | |
686 | ||
687 | /** | |
688 | * Sets the indication if the section was already added to | |
689 | * the document. | |
690 | * @since iText2.0.8 | |
691 | * @param notAddedYet | |
692 | */ | |
693 | public void setNotAddedYet(boolean notAddedYet) { | |
694 | this.notAddedYet = notAddedYet; | |
695 | } | |
696 | | |
697 | /** | |
698 | * @since iText 2.0.8 | |
699 | */ | |
700 | protected boolean isAddedCompletely() { | |
701 | return addedCompletely; | |
702 | } | |
703 | | |
704 | /** | |
705 | * @since iText 2.0.8 | |
706 | */ | |
707 | protected void setAddedCompletely(boolean addedCompletely) { | |
708 | this.addedCompletely = addedCompletely; | |
709 | } | |
710 | | |
711 | /** | |
712 | * @since iText 2.0.8 | |
713 | * @see com.lowagie.text.LargeElement#flushContent() | |
714 | */ | |
715 | public void flushContent() { | |
716 |
1
1. flushContent : removed call to com/lowagie/text/Section::setNotAddedYet → NO_COVERAGE |
setNotAddedYet(false); |
717 | title = null; | |
718 | Element element; | |
719 |
1
1. flushContent : negated conditional → NO_COVERAGE |
for (Iterator i = iterator(); i.hasNext(); ) { |
720 | element = (Element)i.next(); | |
721 |
1
1. flushContent : negated conditional → NO_COVERAGE |
if (element instanceof Section) { |
722 | Section s = (Section)element; | |
723 |
2
1. flushContent : negated conditional → NO_COVERAGE 2. flushContent : negated conditional → NO_COVERAGE |
if (!s.isComplete() && size() == 1) { |
724 |
1
1. flushContent : removed call to com/lowagie/text/Section::flushContent → NO_COVERAGE |
s.flushContent(); |
725 | return; | |
726 | } | |
727 | else { | |
728 |
1
1. flushContent : removed call to com/lowagie/text/Section::setAddedCompletely → NO_COVERAGE |
s.setAddedCompletely(true); |
729 | } | |
730 | } | |
731 |
1
1. flushContent : removed call to java/util/Iterator::remove → NO_COVERAGE |
i.remove(); |
732 | } | |
733 | } | |
734 | ||
735 | /** | |
736 | * @since iText 2.0.8 | |
737 | * @see com.lowagie.text.LargeElement#isComplete() | |
738 | */ | |
739 | public boolean isComplete() { | |
740 | return complete; | |
741 | } | |
742 | ||
743 | /** | |
744 | * @since iText 2.0.8 | |
745 | * @see com.lowagie.text.LargeElement#setComplete(boolean) | |
746 | */ | |
747 | public void setComplete(boolean complete) { | |
748 | this.complete = complete; | |
749 | } | |
750 | ||
751 | /** | |
752 | * Adds a new page to the section. | |
753 | * @since 2.1.1 | |
754 | */ | |
755 | public void newPage() { | |
756 | this.add(Chunk.NEXTPAGE); | |
757 | } | |
758 | } | |
Mutations | ||
193 |
1.1 |
|
196 |
1.1 |
|
216 |
1.1 2.2 |
|
226 |
1.1 2.2 |
|
239 |
1.1 |
|
269 |
1.1 |
|
274 |
1.1 |
|
275 |
1.1 |
|
295 |
1.1 |
|
300 |
1.1 |
|
302 |
1.1 2.2 |
|
303 |
1.1 |
|
305 |
1.1 2.2 |
|
308 |
1.1 2.2 |
|
309 |
1.1 |
|
311 |
1.1 |
|
312 |
1.1 |
|
335 |
1.1 |
|
349 |
1.1 |
|
353 |
1.1 |
|
355 |
1.1 |
|
366 |
1.1 2.2 |
|
377 |
1.1 |
|
384 |
1.1 |
|
386 |
1.1 |
|
396 |
1.1 2.2 |
|
408 |
1.1 |
|
419 |
1.1 |
|
430 |
1.1 |
|
440 |
1.1 |
|
460 |
1.1 |
|
473 |
1.1 |
|
474 |
1.1 |
|
478 |
1.1 2.2 |
|
479 |
1.1 |
|
482 |
1.1 2.2 3.3 |
|
486 |
1.1 |
|
487 |
1.1 |
|
490 |
1.1 |
|
491 |
1.1 |
|
618 |
1.1 2.2 3.3 |
|
635 |
1.1 |
|
636 |
1.1 |
|
638 |
1.1 |
|
645 |
1.1 |
|
649 |
1.1 |
|
650 |
1.1 |
|
716 |
1.1 |
|
719 |
1.1 |
|
721 |
1.1 |
|
723 |
1.1 2.2 |
|
724 |
1.1 |
|
728 |
1.1 |
|
731 |
1.1 |