borland.jbcl Packages borland.jbcl Class Hierarchy borland.jbcl.util
java.lang.Object +----java.text.Format +----borland.jbcl.util.BooleanFormat
Constructors Properties Methods
Implements Serializable, Cloneable
The BooleanFormat component uses a string-based pattern, typically a java.text.Format used to control the formatting of boolean values. This class is helpful when working with values that can have two values, stored as true or false, but formatted using string values you specify. For example, you can store gender information in a column of type boolean but have JBuilder format the field to display and accept input values of "Male" and "Female". In addition, the BooleanFormat class allows a third string to display for null values for data that has not yet been entered.
The BooleanFormat pattern consists of three parts, separated by semicolons:
The following table illustrates valid patterns and their formatting effects:
BooleanFormatter specification | Format for true values | Format for false values | Format for null values |
"T;F;F" | T | F | F |
"male;female" | Male | female | female |
"smoker;;" | smoker | (blank) | (blank) |
"smoker;nonsmoker;(unknown)" | smoker | nonsmoker | (unknown) |
This class can be assigned to the following Column properties:
When used as an editMask, the field width for data entry is set to the longest of the three parts in the pattern. All characters of the pattern are set as optional which means that the user is able to type any values into this field when entering or editing data. When leaving the field, the formatter is used to validate the data entered against the pattern specification and if invalid, will generate a ValidationException. If your application includes a borland.jbcl.control.StatusBar (or other status listener), ValidationExceptions appear on the StatusBar. Otherwise, ValidationException errors display in the ExceptionDialog.
You can input abbreviations if your pattern is specified such that each part is a unique string. For example, the following table illustrates the values entered for various input into a field with a specification of "Yes;No;Don't know"
:
Input value: | Parsed and stored as: |
Yes | true |
y | true |
No | false |
Don't know | assigned null |
Y | true |
Ye | true |
N | false |
D | assigned null |
"" (empty string) | assigned null |
The following table illustrates the parser logic where a pattern specification contains similar initial characters, and whether the parser can or cannot determine values based on abbreviated input. For a format specification of "marmot;monkey;mongoose"
, the following input values yield results of:
Input value: | Parsed and stored as: |
M | (ambiguous - cannot parse) |
mon | (ambiguous - cannot parse) |
ma | marmot |
Mong | mongoose |
Note: JBuilder ignores upper and lowercase differences when parsing data against a pattern specification.
public BooleanFormat()Creates a BooleanFormat object.
public BooleanFormat(java.lang.String pattern)Creates a BooleanFormat object with the specified pattern.
Parameters:
public String getFalseString()Read-only property that returns the part of the BooleanFormat specification which deals with the format of false values.
To set this property, use the BooleanFormat(String) constructor or the applyPattern() method.
public String getNullString()Read-only property that returns the part of the BooleanFormat specification which deals with the format of null values.
To set this property, use the BooleanFormat(String) constructor or the applyPattern() method.
public String getTrueString()Read-only property that returns the part of the BooleanFormat specification which deals with the format of true values.
To set this property, use the BooleanFormat(String) constructor or the applyPattern() method.
public void applyPattern(java.lang.String pattern)Sets the BooleanFormat specification that defines the format of true, false, and null values. If an empty pattern is used, this method defaults to "true;false".
Parameters:
public StringBuffer format(java.lang.Boolean value, java.lang.StringBuffer result, java.text.FieldPosition pos)This method formats an object into a java.lang.StringBuffer.
Parameters:
public final StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)This method formats an object into a java.lang.StringBuffer. All subclasses of the java.text.Format class must implement this method. For more information on this method, see java.text.Format.format(Object, StringBuffer, FieldPosition).
Parameters:
Overrides: java.text.Format.format(Object, StringBuffer, FieldPosition)
public Boolean parse(java.lang.String text, java.text.ParsePosition pos)This method parses a string into an Object. For more information on this method, see java.text.Format.parseObject(String, ParsePosition)
Parameters:
public final Object parseObject(java.lang.String source, java.text.ParsePosition pos)This method parses a string into an Object. This method returns a Boolean containing the value extracted from source. A return value of null equals a blank string or the third part of the BooleanFormat pattern. An error in parsing is indicated by returning a null and by not advancing the parse position index.
All subclasses of the java.text.Format class must implement this method. For more information on this method, see java.text.Format.parseObject(String, ParsePosition).
Parameters:
Overrides: java.text.Format.parseObject(String, ParsePosition)
public String toPattern()Returns the String pattern specification of the BooleanFormat component.