- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Element>
-
- com.lowagie.text.Phrase
-
- All Implemented Interfaces:
Element
,TextElementArray
,Serializable
,Cloneable
,Iterable<Element>
,Collection<Element>
,List<Element>
,RandomAccess
public class Phrase extends ArrayList<Element> implements TextElementArray
APhrase
is a series ofChunk
s.A
Phrase
has a mainFont
, but some chunks within the phrase can have aFont
that differs from the mainFont
. All theChunk
s in aPhrase
have the sameleading
.Example:
// When no parameters are passed, the default leading = 16 Phrase phrase0 = new Phrase(); Phrase phrase1 = new Phrase("this is a phrase"); // In this example the leading is passed as a parameter Phrase phrase2 = new Phrase(16, "this is a phrase with leading 16"); // When a Font is passed (explicitly or embedded in a chunk), the default leading = 1.5 * size of the font Phrase phrase3 = new Phrase("this is a phrase with a red, normal font Courier, size 12", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, new Color(255, 0, 0))); Phrase phrase4 = new Phrase(new Chunk("this is a phrase")); Phrase phrase5 = new Phrase(18, new Chunk("this is a phrase", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
- See Also:
Element
,Chunk
,Paragraph
,Anchor
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Font
font
This is the font of this phrase.protected HyphenationEvent
hyphenation
Null, unless the Phrase has to be hyphenated.protected float
leading
This is the leading of this phrase.-
Fields inherited from class java.util.AbstractList
modCount
-
Fields inherited from interface com.lowagie.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, FOOTNOTE, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MODIFICATIONDATE, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK
-
-
Constructor Summary
Constructors Constructor Description Phrase()
Constructs aPhrase
without specifying a leading.Phrase(float leading)
Constructs aPhrase
with a certain leading.Phrase(float leading, Chunk chunk)
Constructs aPhrase
with a certainChunk
and a certain leading.Phrase(float leading, String string)
Constructs aPhrase
with a certain leading and a certainString
.Phrase(float leading, String string, Font font)
Constructs aPhrase
with a certain leading, a certainString
and a certainFont
.Phrase(Chunk chunk)
Constructs aPhrase
with a certainChunk
.Phrase(Phrase phrase)
Copy constructor forPhrase
.Phrase(String string)
Constructs aPhrase
with a certainString
.Phrase(String string, Font font)
Constructs aPhrase
with a certainString
and a certainFont
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Element element)
Adds aChunk
, anAnchor
or anotherPhrase
to thisPhrase
.boolean
add(Element element)
Adds an object to theTextElementArray
.boolean
add(String o)
Adds aChunk
,Anchor
or anotherPhrase
to thisPhrase
.boolean
addAll(Collection<? extends Element> collection)
Adds a collection ofChunk
s to thisPhrase
.protected boolean
addChunk(Chunk chunk)
Adds a Chunk.protected void
addSpecial(Object object)
Adds aObject
to theParagraph
.ArrayList<Element>
getChunks()
Gets all the chunks in this element.String
getContent()
Returns the content as a String object.Font
getFont()
Gets the font of the firstChunk
that appears in thisPhrase
.HyphenationEvent
getHyphenation()
Getter for the hyphenation settings.static Phrase
getInstance(int leading, String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.static Phrase
getInstance(int leading, String string, Font font)
Gets a special kind of Phrase that changes some characters into corresponding symbols.static Phrase
getInstance(String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.float
getLeading()
Gets the leading of this phrase.boolean
hasLeading()
Checks you if the leading of this phrase is defined.boolean
isContent()
Checks if this element is a content object.boolean
isEmpty()
Checks is thisPhrase
contains no or 1 emptyChunk
.boolean
isNestable()
Checks if this element is nestable.boolean
process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.void
setFont(Font font)
Sets the main font of this phrase.void
setHyphenation(HyphenationEvent hyphenation)
Setter for the hyphenation.void
setLeading(float leading)
Sets the leading of this phrase.int
type()
Gets the type of the text element.-
Methods inherited from class java.util.ArrayList
addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
containsAll
-
-
-
-
Field Detail
-
leading
protected float leading
This is the leading of this phrase.
-
font
protected Font font
This is the font of this phrase.
-
hyphenation
protected HyphenationEvent hyphenation
Null, unless the Phrase has to be hyphenated.- Since:
- 2.1.2
-
-
Constructor Detail
-
Phrase
public Phrase()
Constructs aPhrase
without specifying a leading.
-
Phrase
public Phrase(Phrase phrase)
Copy constructor forPhrase
.- Parameters:
phrase
- an object ofPhrase
, that you want to create a new object from
-
Phrase
public Phrase(float leading)
Constructs aPhrase
with a certain leading.- Parameters:
leading
- the leading
-
Phrase
public Phrase(Chunk chunk)
Constructs aPhrase
with a certainChunk
.- Parameters:
chunk
- aChunk
-
Phrase
public Phrase(float leading, Chunk chunk)
Constructs aPhrase
with a certainChunk
and a certain leading.- Parameters:
leading
- the leadingchunk
- aChunk
-
Phrase
public Phrase(String string)
Constructs aPhrase
with a certainString
.- Parameters:
string
- aString
-
Phrase
public Phrase(String string, Font font)
Constructs aPhrase
with a certainString
and a certainFont
.- Parameters:
string
- aString
font
- aFont
-
Phrase
public Phrase(float leading, String string)
Constructs aPhrase
with a certain leading and a certainString
.- Parameters:
leading
- the leadingstring
- aString
-
-
Method Detail
-
getInstance
public static final Phrase getInstance(String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
string
- input- Returns:
- a newly constructed Phrase
-
getInstance
public static final Phrase getInstance(int leading, String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading
- leading spacesstring
- input- Returns:
- a newly constructed Phrase
-
getInstance
public static final Phrase getInstance(int leading, String string, Font font)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading
- leading spacesstring
- inputfont
- font to be used- Returns:
- a newly constructed Phrase
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.
-
type
public int type()
Gets the type of the text element.
-
isContent
public boolean isContent()
Description copied from interface:Element
Checks if this element is a content object. If not, it's a metadata object.- Specified by:
isContent
in interfaceElement
- Returns:
- true if this is a 'content' element; false if this is a 'metadata' element
- Since:
- iText 2.0.8
- See Also:
Element.isContent()
-
isNestable
public boolean isNestable()
Description copied from interface:Element
Checks if this element is nestable.- Specified by:
isNestable
in interfaceElement
- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
add
public void add(int index, Element element)
Adds aChunk
, anAnchor
or anotherPhrase
to thisPhrase
.- Specified by:
add
in interfaceList<Element>
- Overrides:
add
in classArrayList<Element>
- Parameters:
index
- index at which the specified element is to be insertedelement
- an object of typeChunk
,Anchor
orPhrase
- Throws:
ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
add
public boolean add(String o)
Adds aChunk
,Anchor
or anotherPhrase
to thisPhrase
.- Parameters:
o
- an object of typeChunk
,Anchor
orPhrase
- Returns:
- a boolean
- Throws:
ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
add
public boolean add(Element element)
Description copied from interface:TextElementArray
Adds an object to theTextElementArray
.
-
addAll
public boolean addAll(Collection<? extends Element> collection)
Adds a collection ofChunk
s to thisPhrase
.- Specified by:
addAll
in interfaceCollection<Element>
- Specified by:
addAll
in interfaceList<Element>
- Overrides:
addAll
in classArrayList<Element>
- Parameters:
collection
- a collection ofChunk
s,Anchor
s andPhrase
s.- Returns:
true
if the action succeeded,false
if not.- Throws:
ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
addChunk
protected boolean addChunk(Chunk chunk)
Adds a Chunk.This method is a hack to solve a problem I had with phrases that were split between chunks in the wrong place.
- Parameters:
chunk
- a Chunk to add to the Phrase- Returns:
- true if adding the Chunk succeeded
-
addSpecial
protected void addSpecial(Object object)
Adds aObject
to theParagraph
.- Parameters:
object
- the object to add.
-
getLeading
public float getLeading()
Gets the leading of this phrase.- Returns:
- the linespacing
-
setLeading
public void setLeading(float leading)
Sets the leading of this phrase.- Parameters:
leading
- the new leading
-
hasLeading
public boolean hasLeading()
Checks you if the leading of this phrase is defined.- Returns:
- true if the leading is defined
-
getFont
public Font getFont()
Gets the font of the firstChunk
that appears in thisPhrase
.- Returns:
- a
Font
-
setFont
public void setFont(Font font)
Sets the main font of this phrase.- Parameters:
font
- the new font
-
getContent
public String getContent()
Returns the content as a String object. This method differs from toString because toString will return an ArrayList with the toString value of the Chunks in this Phrase.- Returns:
- an
String
-
isEmpty
public boolean isEmpty()
Checks is thisPhrase
contains no or 1 emptyChunk
.
-
getHyphenation
public HyphenationEvent getHyphenation()
Getter for the hyphenation settings.- Returns:
- a HyphenationEvent
- Since:
- 2.1.2
-
setHyphenation
public void setHyphenation(HyphenationEvent hyphenation)
Setter for the hyphenation.- Parameters:
hyphenation
- a HyphenationEvent instance- Since:
- 2.1.2
-
-