borland Packages Class Hierarchy dx.text Package
java.lang.Object +----java.text.Format +----com.borland.dx.text.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:
BooleanFormat
patterns and formats
BooleanFormat 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 com.borland.dbswing.JdbStatusLabel
(or other status listener), ValidationExceptions
appear on the StatusLabel
. Otherwise, ValidationException
errors display in the DBExceptionDialog
.
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 |
public BooleanFormat()Creates a
BooleanFormat
object.
public BooleanFormat(String pattern)Creates a
BooleanFormat
object with the specified pattern.
pattern
String
pattern that specifies formatting of true, false, and null values.
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(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".
pattern
public StringBuffer format(Boolean value, StringBuffer result, FieldPosition pos)This method formats a boolean value into a
java.lang.StringBuffer
.
value
result
pos
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)This method formats a boolean value into a
java.lang.StringBuffer
. For more information on this method, see
java.text.Format.format(Object, StringBuffer, FieldPosition)
.
obj
Object
to format. Defaults to null.
toAppendTo
pos
public Boolean parse(String text, ParsePosition pos)This method parses a string into a boolean value. For more information on this method, see
java.text.Format.parseObject(String, ParsePosition)
.
text
pos
public final Object parseObject(String source, ParsePosition pos)This method parses a string into an
Object
. 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.
For more information on this method, see
java.text.Format.parseObject(String, ParsePosition)
.
source
pos
public String toPattern()Returns the
String
pattern specification of the BooleanFormat
component.