Class Phrase
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList
-
- com.gitlab.pdftk_java.com.lowagie.text.Phrase
-
- All Implemented Interfaces:
Element
,MarkupAttributes
,TextElementArray
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable
,java.util.Collection
,java.util.List
,java.util.RandomAccess
public class Phrase extends java.util.ArrayList implements TextElementArray, MarkupAttributes
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 (explicitely 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 float
leading
This is the leading of this phrase.protected java.util.Properties
markupAttributes
Contains extra markupAttributesprivate static long
serialVersionUID
-
Fields inherited from interface com.gitlab.pdftk_java.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, GRAPHIC, HEADER, IMGRAW, IMGTEMPLATE, JPEG, KEYWORDS, LIST, LISTITEM, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE
-
-
Constructor Summary
Constructors Modifier Constructor Description Phrase()
Constructs aPhrase
without specifying a leading.private
Phrase(boolean dummy)
Constructs a Phrase that can be used in the static getInstance() method.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, java.lang.String string)
Constructs aPhrase
with a certain leading and a certainString
.Phrase(float leading, java.lang.String string, Font font)
Constructs aPhrase
with a certain leading, a certainString
and a certainFont
.Phrase(Chunk chunk)
Constructs aPhrase
with a certainChunk
.Phrase(java.lang.String string)
Constructs aPhrase
with a certainString
.Phrase(java.lang.String string, Font font)
Constructs aPhrase
with a certainString
and a certainFont
.Phrase(java.util.Properties attributes)
Returns aPhrase
that has been constructed taking in account the value of some attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, java.lang.Object o)
Adds aChunk
, anAnchor
or anotherPhrase
to thisPhrase
.boolean
add(java.lang.Object o)
Adds aChunk
,Anchor
or anotherPhrase
to thisPhrase
.boolean
addAll(java.util.Collection collection)
Adds a collection ofChunk
s to thisPhrase
.private boolean
addChunk(Chunk chunk)
Adds a Chunk.protected void
addSpecial(java.lang.Object object)
Adds aObject
to theParagraph
.Font
font()
Gets the font of the firstChunk
that appears in thisPhrase
.java.util.ArrayList
getChunks()
Gets all the chunks in this element.static Phrase
getInstance(int leading, java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.static Phrase
getInstance(int leading, java.lang.String string, Font font)
Gets a special kind of Phrase that changes some characters into corresponding symbols.static Phrase
getInstance(java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.java.lang.String
getMarkupAttribute(java.lang.String name)
Returns the value of the specified attribute.java.util.Set
getMarkupAttributeNames()
Returns aSet
ofString
attribute names for theMarkupAttributes
implementor.java.util.Properties
getMarkupAttributes()
Return aProperties
-object containing all the markupAttributes.boolean
isEmpty()
Checks is thisPhrase
contains no or 1 emptyChunk
.static boolean
isTag(java.lang.String tag)
Checks if a given tag corresponds with this object.float
leading()
Gets the leading of this phrase.boolean
leadingDefined()
Checks you if the leading of this phrase is defined.boolean
process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.void
setLeading(float leading)
Sets the leading of this phrase.void
setMarkupAttribute(java.lang.String name, java.lang.String value)
Sets the specified attribute.void
setMarkupAttributes(java.util.Properties markupAttributes)
Sets the markupAttributes.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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
leading
protected float leading
This is the leading of this phrase.
-
font
protected Font font
This is the font of this phrase.
-
markupAttributes
protected java.util.Properties markupAttributes
Contains extra markupAttributes
-
-
Constructor Detail
-
Phrase
private Phrase(boolean dummy)
Constructs a Phrase that can be used in the static getInstance() method.- Parameters:
dummy
- a dummy parameter
-
Phrase
public Phrase()
Constructs aPhrase
without specifying a leading.
-
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(java.lang.String string)
Constructs aPhrase
with a certainString
.- Parameters:
string
- aString
-
Phrase
public Phrase(java.lang.String string, Font font)
Constructs aPhrase
with a certainString
and a certainFont
.- Parameters:
string
- aString
font
- aFont
-
Phrase
public Phrase(float leading, java.lang.String string)
Constructs aPhrase
with a certain leading and a certainString
.- Parameters:
leading
- the leadingstring
- aString
-
Phrase
public Phrase(float leading, java.lang.String string, Font font)
Constructs aPhrase
with a certain leading, a certainString
and a certainFont
.- Parameters:
leading
- the leadingstring
- aString
font
- aFont
-
Phrase
public Phrase(java.util.Properties attributes)
Returns aPhrase
that has been constructed taking in account the value of some attributes.- Parameters:
attributes
- Some attributes
-
-
Method Detail
-
getInstance
public static final Phrase getInstance(java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
string
-- Returns:
- a newly constructed Phrase
-
getInstance
public static final Phrase getInstance(int leading, java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading
-string
-- Returns:
- a newly constructed Phrase
-
getInstance
public static final Phrase getInstance(int leading, java.lang.String string, Font font)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading
-string
-font
-- 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.
-
getChunks
public java.util.ArrayList getChunks()
Gets all the chunks in this element.
-
add
public void add(int index, java.lang.Object o)
Adds aChunk
, anAnchor
or anotherPhrase
to thisPhrase
.- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classjava.util.ArrayList
- Parameters:
index
- index at which the specified element is to be insertedo
- an object of typeChunk
,Anchor
orPhrase
- Throws:
java.lang.ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
add
public boolean add(java.lang.Object o)
Adds aChunk
,Anchor
or anotherPhrase
to thisPhrase
.- Specified by:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.List
- Specified by:
add
in interfaceTextElementArray
- Overrides:
add
in classjava.util.ArrayList
- Parameters:
o
- an object of typeChunk
,Anchor
orPhrase
- Returns:
- a boolean
- Throws:
java.lang.ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
addChunk
private 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
-
addAll
public boolean addAll(java.util.Collection collection)
Adds a collection ofChunk
s to thisPhrase
.- Specified by:
addAll
in interfacejava.util.Collection
- Specified by:
addAll
in interfacejava.util.List
- Overrides:
addAll
in classjava.util.ArrayList
- Parameters:
collection
- a collection ofChunk
s,Anchor
s andPhrase
s.- Returns:
true
if the action succeeded,false
if not.- Throws:
java.lang.ClassCastException
- when you try to add something that isn't aChunk
,Anchor
orPhrase
-
addSpecial
protected void addSpecial(java.lang.Object object)
Adds aObject
to theParagraph
.- Parameters:
object
- the object to add.
-
setLeading
public void setLeading(float leading)
Sets the leading of this phrase.- Parameters:
leading
- the new leading
-
isEmpty
public boolean isEmpty()
Checks is thisPhrase
contains no or 1 emptyChunk
.- Specified by:
isEmpty
in interfacejava.util.Collection
- Specified by:
isEmpty
in interfacejava.util.List
- Overrides:
isEmpty
in classjava.util.ArrayList
- Returns:
false
if thePhrase
contains more than one or more non-emptyChunk
s.
-
leadingDefined
public boolean leadingDefined()
Checks you if the leading of this phrase is defined.- Returns:
- true if the leading is defined
-
leading
public float leading()
Gets the leading of this phrase.- Returns:
- the linespacing
-
font
public Font font()
Gets the font of the firstChunk
that appears in thisPhrase
.- Returns:
- a
Font
-
isTag
public static boolean isTag(java.lang.String tag)
Checks if a given tag corresponds with this object.- Parameters:
tag
- the given tag- Returns:
- true if the tag corresponds
-
setMarkupAttribute
public void setMarkupAttribute(java.lang.String name, java.lang.String value)
Description copied from interface:MarkupAttributes
Sets the specified attribute.- Specified by:
setMarkupAttribute
in interfaceMarkupAttributes
- Parameters:
name
-String
attribute name.value
-String
attribute value.- See Also:
MarkupAttributes.setMarkupAttribute(java.lang.String, java.lang.String)
-
setMarkupAttributes
public void setMarkupAttributes(java.util.Properties markupAttributes)
Description copied from interface:MarkupAttributes
Sets the markupAttributes.- Specified by:
setMarkupAttributes
in interfaceMarkupAttributes
- Parameters:
markupAttributes
- aProperties
-object containing markupattributes- See Also:
MarkupAttributes.setMarkupAttributes(java.util.Properties)
-
getMarkupAttribute
public java.lang.String getMarkupAttribute(java.lang.String name)
Description copied from interface:MarkupAttributes
Returns the value of the specified attribute.- Specified by:
getMarkupAttribute
in interfaceMarkupAttributes
- Parameters:
name
-String
attribute name.- Returns:
String
.- See Also:
MarkupAttributes.getMarkupAttribute(java.lang.String)
-
getMarkupAttributeNames
public java.util.Set getMarkupAttributeNames()
Description copied from interface:MarkupAttributes
Returns aSet
ofString
attribute names for theMarkupAttributes
implementor.- Specified by:
getMarkupAttributeNames
in interfaceMarkupAttributes
- Returns:
Set
.- See Also:
MarkupAttributes.getMarkupAttributeNames()
-
getMarkupAttributes
public java.util.Properties getMarkupAttributes()
Description copied from interface:MarkupAttributes
Return aProperties
-object containing all the markupAttributes.- Specified by:
getMarkupAttributes
in interfaceMarkupAttributes
- Returns:
Properties
- See Also:
MarkupAttributes.getMarkupAttributes()
-
-