borland Packages Class Hierarchy dx.text Package
TextFormat component
java.lang.Object
+----java.text.Format
+----com.borland.dx.text.TextFormat
About the TextFormat component
Variables Constructors Properties Methods
Implements Serializable, Cloneable
This component 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:
<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 variables
Variables implemented in this class
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
- equals(java.lang.Object)
- finalize()
- hashCode()
- notify()
- notifyAll()
- toString()
- wait()
- wait(long)
- wait(long, int)
Methods implemented in java.text.Format
- clone()
- format(java.lang.Object)
- parseObject(java.lang.String)
TextFormat variables
NOT_A_CHAR
public static char NOT_A_CHAR = 0xffff
Not a valid character.
TextFormat constructors
TextFormat()
public TextFormat()
Constructs a TextFormat object with no specified string pattern.
TextFormat(java.lang.String)
public TextFormat(String pattern)
Constructs a TextFormat object with the specified string pattern.
Parameters:
- pattern
- The pattern to construct the TextFormat object with.
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 tf to false remove literals when the string is stored.
replaceCharacter
public char getReplaceCharacter()
public void setReplaceCharacter(char c)
Retrieves and sets the character that replaces the fill character when the string is parsed.
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(String pattern)
Sets the pattern to the specified value.
Parameters:
- pattern
- The value to set the pattern to.
format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
Formats the given Object using the pattern associated with this object.
Parameters:
- obj
- The Object to be formatted.
- toAppendTo
- The StringBuffer to append the newly formatted String to.
- pos
- The starting position in the StringBuffer of the formatted String.
Overrides:
java.text.Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
format(java.lang.String, java.lang.StringBuffer, java.text.FieldPosition)
public StringBuffer format(String toBeFormatted, StringBuffer result, FieldPosition pos)
Formats the given String 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 setFillChar(). The result parameter is assigned the return value of this method.
Parameters:
- toBeFormatted
- The String to be formatted.
- result
- The formatted string.
- pos
- The starting position in the StringBuffer of the formatted String.
parse(java.lang.String, java.text.ParsePosition)
public StringBuffer parse(String 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.
Parameters:
- text
- The String to parse.
- pos
- The starting position in the StringBuffer of the parsed text.
parseObject(java.lang.String, java.text.ParsePosition)
public final Object parseObject(String source, ParsePosition pos)
Parses (or decomposes) a String into an Object.
Parameters:
- source
- The String to parse.
- pos
- The starting position in the StringBuffer of the formatted String.
toPattern()
public String toPattern()
Returns the pattern used for formatting.