public class Phrase extends java.util.ArrayList implements TextElementArray, MarkupAttributes
Phrase
is a series of Chunk
s.
A Phrase
has a main Font
, but some chunks
within the phrase can have a Font
that differs from the
main Font
. All the Chunk
s in a Phrase
have the same leading
.
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)));
Element
,
Chunk
,
Paragraph
,
Anchor
,
Serialized FormModifier and Type | Field and 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 markupAttributes
|
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
Modifier | Constructor and Description |
---|---|
|
Phrase()
Constructs a
Phrase without specifying a leading. |
private |
Phrase(boolean dummy)
Constructs a Phrase that can be used in the static getInstance() method.
|
|
Phrase(Chunk chunk)
Constructs a
Phrase with a certain Chunk . |
|
Phrase(float leading)
Constructs a
Phrase with a certain leading. |
|
Phrase(float leading,
Chunk chunk)
Constructs a
Phrase with a certain Chunk
and a certain leading. |
|
Phrase(float leading,
java.lang.String string)
Constructs a
Phrase with a certain leading and a certain String . |
|
Phrase(float leading,
java.lang.String string,
Font font)
Constructs a
Phrase with a certain leading, a certain String
and a certain Font . |
|
Phrase(java.util.Properties attributes)
Returns a
Phrase that has been constructed taking in account
the value of some attributes. |
|
Phrase(java.lang.String string)
Constructs a
Phrase with a certain String . |
|
Phrase(java.lang.String string,
Font font)
Constructs a
Phrase with a certain String and a certain Font . |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
java.lang.Object o)
Adds a
Chunk , an Anchor or another Phrase
to this Phrase . |
boolean |
add(java.lang.Object o)
Adds a
Chunk , Anchor or another Phrase
to this Phrase . |
boolean |
addAll(java.util.Collection collection)
Adds a collection of
Chunk s
to this Phrase . |
private boolean |
addChunk(Chunk chunk)
Adds a Chunk.
|
protected void |
addSpecial(java.lang.Object object)
Adds a
Object to the Paragraph . |
java.lang.String |
content()
Returns the content as a String object.
|
Font |
font()
Gets the font of the first
Chunk that appears in this Phrase . |
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 a
Set of String attribute names for the
MarkupAttributes implementor. |
java.util.Properties |
getMarkupAttributes()
Return a
Properties -object containing all the markupAttributes. |
boolean |
isEmpty()
Checks is this
Phrase contains no or 1 empty Chunk . |
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 an
ElementListener . |
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.
|
addAll, clear, clone, contains, ensureCapacity, get, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, set, size, subList, toArray, toArray, trimToSize
protected float leading
protected Font font
protected java.util.Properties markupAttributes
private Phrase(boolean dummy)
dummy
- a dummy parameterpublic Phrase()
Phrase
without specifying a leading.public Phrase(float leading)
Phrase
with a certain leading.leading
- the leadingpublic Phrase(Chunk chunk)
Phrase
with a certain Chunk
.chunk
- a Chunk
public Phrase(float leading, Chunk chunk)
Phrase
with a certain Chunk
and a certain leading.leading
- the leadingchunk
- a Chunk
public Phrase(java.lang.String string)
Phrase
with a certain String
.string
- a String
public Phrase(java.lang.String string, Font font)
Phrase
with a certain String
and a certain Font
.string
- a String
font
- a Font
public Phrase(float leading, java.lang.String string)
Phrase
with a certain leading and a certain String
.leading
- the leadingstring
- a String
public Phrase(float leading, java.lang.String string, Font font)
Phrase
with a certain leading, a certain String
and a certain Font
.leading
- the leadingstring
- a String
font
- a Font
public Phrase(java.util.Properties attributes)
Phrase
that has been constructed taking in account
the value of some attributes.attributes
- Some attributespublic static final Phrase getInstance(java.lang.String string)
string
- public static final Phrase getInstance(int leading, java.lang.String string)
leading
- string
- public static final Phrase getInstance(int leading, java.lang.String string, Font font)
leading
- string
- font
- public boolean process(ElementListener listener)
ElementListener
.public int type()
public java.util.ArrayList getChunks()
public void add(int index, java.lang.Object o)
Chunk
, an Anchor
or another Phrase
to this Phrase
.add
in interface java.util.List
add
in class java.util.ArrayList
index
- index at which the specified element is to be insertedo
- an object of type Chunk
, Anchor
or Phrase
java.lang.ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
public boolean add(java.lang.Object o)
Chunk
, Anchor
or another Phrase
to this Phrase
.add
in interface TextElementArray
add
in interface java.util.Collection
add
in interface java.util.List
add
in class java.util.ArrayList
o
- an object of type Chunk
, Anchor
or Phrase
java.lang.ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
private boolean addChunk(Chunk chunk)
This method is a hack to solve a problem I had with phrases that were split between chunks in the wrong place.
chunk
- a Chunk to add to the Phrasepublic boolean addAll(java.util.Collection collection)
Chunk
s
to this Phrase
.addAll
in interface java.util.Collection
addAll
in interface java.util.List
addAll
in class java.util.ArrayList
collection
- a collection of Chunk
s, Anchor
s and Phrase
s.true
if the action succeeded, false
if not.java.lang.ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
protected void addSpecial(java.lang.Object object)
Object
to the Paragraph
.object
- the object to add.public void setLeading(float leading)
leading
- the new leadingpublic boolean isEmpty()
Phrase
contains no or 1 empty Chunk
.isEmpty
in interface java.util.Collection
isEmpty
in interface java.util.List
isEmpty
in class java.util.ArrayList
false
if the Phrase
contains more than one or more non-emptyChunk
s.public boolean leadingDefined()
public float leading()
public Font font()
Chunk
that appears in this Phrase
.Font
public java.lang.String content()
public static boolean isTag(java.lang.String tag)
tag
- the given tagpublic void setMarkupAttribute(java.lang.String name, java.lang.String value)
MarkupAttributes
setMarkupAttribute
in interface MarkupAttributes
name
- String
attribute name.value
- String
attribute value.MarkupAttributes.setMarkupAttribute(java.lang.String, java.lang.String)
public void setMarkupAttributes(java.util.Properties markupAttributes)
MarkupAttributes
setMarkupAttributes
in interface MarkupAttributes
markupAttributes
- a Properties
-object containing markupattributesMarkupAttributes.setMarkupAttributes(java.util.Properties)
public java.lang.String getMarkupAttribute(java.lang.String name)
MarkupAttributes
getMarkupAttribute
in interface MarkupAttributes
name
- String
attribute name.String
.MarkupAttributes.getMarkupAttribute(java.lang.String)
public java.util.Set getMarkupAttributeNames()
MarkupAttributes
Set
of String
attribute names for the
MarkupAttributes
implementor.getMarkupAttributeNames
in interface MarkupAttributes
Set
.MarkupAttributes.getMarkupAttributeNames()
public java.util.Properties getMarkupAttributes()
MarkupAttributes
Properties
-object containing all the markupAttributes.getMarkupAttributes
in interface MarkupAttributes
Properties
MarkupAttributes.getMarkupAttributes()