org.eclipse.graphiti.util
Class TextBuilder

java.lang.Object
  extended by org.eclipse.graphiti.util.TextBuilder

public class TextBuilder
extends Object

Class to construct TextStyleRegions while adding text.

Since:
0.12

Nested Class Summary
static class TextBuilder.TextBuilderRegion
          Inner class for storing the partial region styles.
 
Field Summary
private  int length
          Number of code points in text.
private  List<TextStyleRegion> regions
          Regions created in the collected text.
private  Map<String,TextBuilder.TextBuilderRegion> styles
          Partly finished text styles.
private  StringBuilder text
          Constructed text string.
 
Constructor Summary
TextBuilder()
           
 
Method Summary
 void add(String text)
          Add text to the builder.
 void finishRegion(String name)
          Finish a region.
 void forgetRegion(String name)
          Drop a region that was created but not yet finished.
 int getLength()
          Get current length of the collected text.
 TextBuilder.TextBuilderRegion getRegion(String name)
          Get a previously created and not yet finished region.
 List<TextStyleRegion> getRegions()
          Get the regions created and finished for the text.
 boolean isEmpty()
          Is any text added yet?
 TextBuilder.TextBuilderRegion startRegion(String name)
          Start a new region in the text.
 String toString()
          Get the collected text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

private StringBuilder text
Constructed text string.


length

private int length
Number of code points in text.


regions

private List<TextStyleRegion> regions
Regions created in the collected text.


styles

private Map<String,TextBuilder.TextBuilderRegion> styles
Partly finished text styles.

Constructor Detail

TextBuilder

public TextBuilder()
Method Detail

add

public void add(String text)
Add text to the builder.

Parameters:
text - Text to append.

getLength

public int getLength()
Get current length of the collected text.

Returns:
Length of the text collected so far (number of code points).

isEmpty

public boolean isEmpty()
Is any text added yet?

Returns:
true if no text added yet, else false.

toString

public String toString()
Get the collected text.

Overrides:
toString in class Object
Returns:
The concatenated strings previously given through add(java.lang.String).

getRegions

public List<TextStyleRegion> getRegions()
Get the regions created and finished for the text.

Returns:
Regions of the text.

startRegion

public TextBuilder.TextBuilderRegion startRegion(String name)
Start a new region in the text. Returns the created region for setting the style of the new region.

Parameters:
name - Name of the region.
Returns:
The created region.

getRegion

public TextBuilder.TextBuilderRegion getRegion(String name)
Get a previously created and not yet finished region.

Parameters:
name - Name of the region to retrieve.
Returns:
The queried region if it exists, else null.

finishRegion

public void finishRegion(String name)
Finish a region.

Parameters:
name - Name of the region to finish.

forgetRegion

public void forgetRegion(String name)
Drop a region that was created but not yet finished.

Parameters:
name - Name of the region to forget.


Copyright (c) SAP AG 2005, 2012.