borland.jbcl Packages  borland.jbcl Class Hierarchy  borland.jbcl.util 

TextFormat component

java.lang.Object
   +----java.text.Format
           +----borland.jbcl.util.TextFormat

About the TextFormat component

Constructors  Properties  Methods  

Implements Serializable, Cloneable

This method extends the basic Format class but allows for special formatting of text. Similar to other Format derivatives, it is based on a control pattern. The format of the control pattern is as follows:

Format: <pattern>; <keepLiterals>; <fillCharacter>; <replaceCharacter>

Parameters:

pattern
Can contain any of the following characters (they are a common format shared by many products):
0   Digit 0:9, entry required, '+' and '-' not allowed
9   Digit 0:9, entry optional, '+' and '-' not allowed
#   Digit or space, entry optional, plus and minus signs allowed
L   Letter A:Z, entry required
l   Letter A:Z, entry optional
?   Letter A:Z, entry optional
A   Letter A:Z or digit 0:9, entry required
a   letter A:Z or digit 0:9, entry optional
C   any character or space, entry required
c   Any character or space, entry optional
&   Any character or space, entry required
<   Causes all characters following to be converted to lowercase
>   Causes all characters following to be converted to uppercase
!   Causes strings too short to fill from right to left
\   Backslash escape -- allows any Unicode value to follow (e.g. "\u2003")
^   Initial place for cursor when editing begins
'   Encloses a literal expression (for example, the pattern
    "990' units sold'" would display as "27 units sold")
*   Encloses a password encrypted string (for example
    the pattern "*AAAAaaaa*" would accept a password at
    least 4, and at most 8 alphanumeric characters).  
    Characters typed or displayed appear as the '*' character

An example of a US phone number might be "!(999)000-0000"

keepLiterals
If this value is "0", then literals in the string are removed before the value is stored. For example (408)555-5330 becomes 4085555330. Any other value (including no value at all) defaults to "1", which means that literals are preserved.

fillCharacter
Whenever a string is formatted that is too short to fill all the available positions in the pattern, this character is used to fill the extra space(s). For example, formatting "( )555-5330 with the pattern "!(999)000-0000;1;* produces "(***)555-5330". Note that a value of zero (indicated by "\0") means that no filling occurs.

replaceCharacter
Whenever a string is parsed, all occurrences of "fillCharacter" are replaced with "replaceCharacter". Using the example above, parsing (***)555-5330 with the pattern "!(999)000-0000;1;*;_" produces "(___)555-5330". Again, a zero value is allowed in this field (using "\0") and has the effect of removing the fillCharacters.

Note: Each of the special fields (keepLiterals, fillCharacter, replaceCharacter) have their own setter and getter methods.


TextFormat constructors

TextFormat properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in java.lang.Object

TextFormat methods

Methods implemented in this class

Methods implemented in java.lang.Object

Methods implemented in java.text.Format


TextFormat constructors

TextFormat()

  public TextFormat()
Constructs a TextFormat object with no specified string pattern.

TextFormat(java.lang.String)

  public TextFormat(java.lang.String pattern)
Constructs a TextFormat object with the specified string pattern.

TextFormat properties

fillCharacter

 public char getFillCharacter()
 public void setFillCharacter(char c)
Retrieves and sets the fill character used in the string.

Parameters:

c
The character that is used to fill spaces when the string is too short to fill all available spaces.

keepLiterals

 public boolean getKeepLiterals()
 public void setKeepLiterals(boolean tf)
Determines whether literals remain in the string when it is stored. keepLiterals is true when literals are stored; otherwise, it is false.

Parameters:

tf
Set tf to true to store literals; set to tf to false remove literals when the string is stored.

replaceCharacter

 public char getReplaceCharacter()
 public void setReplaceCharacter(char c)

Parameters:

c
The character that replaces the fill character when the string is parsed. A "\0" value results in removing all fill characters in the string.

TextFormat methods

applyPattern(java.lang.String)

  public void applyPattern(java.lang.String pattern)
Sets the pattern to the specified value.

format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)

  public final StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)

Overrides: java.text.Format.format(Object, StringBuffer, FieldPosition)

format(java.lang.String, java.lang.StringBuffer, java.text.FieldPosition)

  public StringBuffer format(java.lang.String toBeFormatted, java.lang.StringBuffer result, java.text.FieldPosition pos)
This method formats the given String (toBeFormatted) using the pattern associated with this object. If the input string has insufficient characters to fill the pattern, it is filled with the character indicated by the setFillChar() method. The result parameter is assigned the return value of this method.

parse(java.lang.String, java.text.ParsePosition)

  public StringBuffer parse(java.lang.String text, java.text.ParsePosition pos)
This method parses (or decomposes) a String using the existing pattern. It allocates a new StringBuffer and fills it with the parsed version of the text parameter.

parseObject(java.lang.String, java.text.ParsePosition)

  public final Object parseObject(java.lang.String source, java.text.ParsePosition pos)

Parameters:

source
The string that is parsed.
pos
The input-output parameter.

Overrides: java.text.Format.parseObject(String, ParsePosition)

toPattern()

  public String toPattern()
Returns the pattern used for formatting.