Constructor: |
public Phrase() {
this(16);
}
Constructs a Phrase without specifying a leading. |
public Phrase(Phrase phrase) {
super();
this.addAll(phrase);
leading = phrase.getLeading();
font = phrase.getFont();
setHyphenation(phrase.getHyphenation());
}
Copy constructor for Phrase . |
public Phrase(float leading) {
this.leading = leading;
font = new Font();
}
Constructs a Phrase with a certain leading. Parameters:
leading - the leading
|
public Phrase(Chunk chunk) {
super.add(chunk);
font = chunk.getFont();
setHyphenation(chunk.getHyphenation());
}
Constructs a Phrase with a certain Chunk . Parameters:
chunk - a Chunk
|
public Phrase(String string) {
this(Float.NaN, string, new Font());
}
Constructs a Phrase with a certain String . Parameters:
string - a String
|
public Phrase(float leading,
Chunk chunk) {
this.leading = leading;
super.add(chunk);
font = chunk.getFont();
setHyphenation(chunk.getHyphenation());
}
Constructs a Phrase with a certain Chunk
and a certain leading. Parameters:
leading - the leading
chunk - a Chunk
|
public Phrase(String string,
Font font) {
this(Float.NaN, string, font);
}
Constructs a Phrase with a certain String and a certain Font . Parameters:
string - a String
font - a Font
|
public Phrase(float leading,
String string) {
this(leading, string, new Font());
}
Constructs a Phrase with a certain leading and a certain String . Parameters:
leading - the leading
string - a String
|
public Phrase(float leading,
String string,
Font font) {
this.leading = leading;
this.font = font;
/* bugfix by August Detlefsen */
if (string != null && string.length() != 0) {
super.add(new Chunk(string, font));
}
}
Constructs a Phrase with a certain leading, a certain String
and a certain Font . Parameters:
leading - the leading
string - a String
font - a Font
|
Method from com.lowagie.text.Phrase Detail: |
public boolean add(Object o) {
if (o == null) return false;
if (o instanceof String) {
return super.add(new Chunk((String) o, font));
}
if (o instanceof RtfElementInterface) {
return super.add(o);
}
try {
Element element = (Element) o;
switch(element.type()) {
case Element.CHUNK:
return addChunk((Chunk) o);
case Element.PHRASE:
case Element.PARAGRAPH:
Phrase phrase = (Phrase) o;
boolean success = true;
Element e;
for (Iterator i = phrase.iterator(); i.hasNext(); ) {
e = (Element) i.next();
if (e instanceof Chunk) {
success &= addChunk((Chunk)e);
}
else {
success &= this.add(e);
}
}
return success;
case Element.MARKED:
case Element.ANCHOR:
case Element.ANNOTATION:
case Element.TABLE: // case added by David Freels
case Element.PTABLE: // case added by mr. Karen Vardanyan
// This will only work for PDF!!! Not for RTF/HTML
case Element.LIST:
case Element.YMARK:
return super.add(o);
default:
throw new ClassCastException(String.valueOf(element.type()));
}
}
catch(ClassCastException cce) {
throw new ClassCastException("Insertion of illegal Element: " + cce.getMessage());
}
}
Adds a Chunk , Anchor or another Phrase
to this Phrase . |
public void add(int index,
Object o) {
if (o == null) return;
try {
Element element = (Element) o;
if (element.type() == Element.CHUNK) {
Chunk chunk = (Chunk) element;
if (!font.isStandardFont()) {
chunk.setFont(font.difference(chunk.getFont()));
}
if (hyphenation != null && chunk.getHyphenation() == null && !chunk.isEmpty()) {
chunk.setHyphenation(hyphenation);
}
super.add(index, chunk);
}
else if (element.type() == Element.PHRASE ||
element.type() == Element.ANCHOR ||
element.type() == Element.ANNOTATION ||
element.type() == Element.TABLE || // line added by David Freels
element.type() == Element.YMARK ||
element.type() == Element.MARKED) {
super.add(index, element);
}
else {
throw new ClassCastException(String.valueOf(element.type()));
}
}
catch(ClassCastException cce) {
throw new ClassCastException("Insertion of illegal Element: " + cce.getMessage());
}
}
Adds a Chunk , an Anchor or another Phrase
to this Phrase . |
public boolean addAll(Collection collection) {
for (Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
this.add(iterator.next());
}
return true;
}
Adds a collection of Chunk s
to this Phrase . |
protected boolean addChunk(Chunk chunk) {
Font f = chunk.getFont();
String c = chunk.getContent();
if (font != null && !font.isStandardFont()) {
f = font.difference(chunk.getFont());
}
if (size() > 0 && !chunk.hasAttributes()) {
try {
Chunk previous = (Chunk) get(size() - 1);
if (!previous.hasAttributes()
&& (f == null
|| f.compareTo(previous.getFont()) == 0)
&& !"".equals(previous.getContent().trim())
&& !"".equals(c.trim())) {
previous.append(c);
return true;
}
}
catch(ClassCastException cce) {
}
}
Chunk newChunk = new Chunk(c, f);
newChunk.setAttributes(chunk.getAttributes());
if (hyphenation != null && newChunk.getHyphenation() == null && !newChunk.isEmpty()) {
newChunk.setHyphenation(hyphenation);
}
return super.add(newChunk);
}
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. |
protected void addSpecial(Object object) {
super.add(object);
}
Adds a Object to the Paragraph . |
public ArrayList getChunks() {
ArrayList tmp = new ArrayList();
for (Iterator i = iterator(); i.hasNext(); ) {
tmp.addAll(((Element) i.next()).getChunks());
}
return tmp;
}
Gets all the chunks in this element. |
public String getContent() {
StringBuffer buf = new StringBuffer();
for (Iterator i = getChunks().iterator(); i.hasNext(); ) {
buf.append(i.next().toString());
}
return buf.toString();
}
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. |
public Font getFont() {
return font;
}
Gets the font of the first Chunk that appears in this Phrase . |
public HyphenationEvent getHyphenation() {
return hyphenation;
}
Getter for the hyphenation settings. |
public static final Phrase getInstance(String string) {
return getInstance(16, string, new Font());
}
Gets a special kind of Phrase that changes some characters into corresponding symbols. |
public static final Phrase getInstance(int leading,
String string) {
return getInstance(leading, string, new Font());
}
Gets a special kind of Phrase that changes some characters into corresponding symbols. |
public static final Phrase getInstance(int leading,
String string,
Font font) {
Phrase p = new Phrase(true);
p.setLeading(leading);
p.font = font;
if (font.getFamily() != Font.SYMBOL && font.getFamily() != Font.ZAPFDINGBATS && font.getBaseFont() == null) {
int index;
while((index = SpecialSymbol.index(string)) > -1) {
if (index > 0) {
String firstPart = string.substring(0, index);
((ArrayList)p).add(new Chunk(firstPart, font));
string = string.substring(index);
}
Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
StringBuffer buf = new StringBuffer();
buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
string = string.substring(1);
while (SpecialSymbol.index(string) == 0) {
buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
string = string.substring(1);
}
((ArrayList)p).add(new Chunk(buf.toString(), symbol));
}
}
if (string != null && string.length() != 0) {
((ArrayList)p).add(new Chunk(string, font));
}
return p;
}
Gets a special kind of Phrase that changes some characters into corresponding symbols. |
public float getLeading() {
if (Float.isNaN(leading) && font != null) {
return font.getCalculatedLeading(1.5f);
}
return leading;
}
Gets the leading of this phrase. |
public boolean hasLeading() {
if (Float.isNaN(leading)) {
return false;
}
return true;
}
Checks you if the leading of this phrase is defined. |
public boolean isContent() {
return true;
}
|
public boolean isEmpty() {
switch(size()) {
case 0:
return true;
case 1:
Element element = (Element) get(0);
if (element.type() == Element.CHUNK && ((Chunk) element).isEmpty()) {
return true;
}
return false;
default:
return false;
}
}
Checks is this Phrase contains no or 1 empty Chunk . |
public boolean isNestable() {
return true;
}
|
public boolean process(ElementListener listener) {
try {
for (Iterator i = iterator(); i.hasNext(); ) {
listener.add((Element) i.next());
}
return true;
}
catch(DocumentException de) {
return false;
}
}
Processes the element by adding it (or the different parts) to an
ElementListener . |
public void setFont(Font font) {
this.font = font;
}
Sets the main font of this phrase. |
public void setHyphenation(HyphenationEvent hyphenation) {
this.hyphenation = hyphenation;
}
Setter for the hyphenation. |
public void setLeading(float leading) {
this.leading = leading;
}
Sets the leading of this phrase. |
public int type() {
return Element.PHRASE;
}
Gets the type of the text element. |