borland Packages  Class Hierarchy  jbcl.util Package  Index 

BooleanFormat component

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

About the BooleanFormat component

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.


BooleanFormat constructors

BooleanFormat properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in java.lang.Object

BooleanFormat methods

Methods implemented in this class

Methods implemented in java.lang.Object

Methods implemented in java.text.Format


BooleanFormat constructors

BooleanFormat()

  public BooleanFormat()
Creates a BooleanFormat object.

BooleanFormat(java.lang.String)

  public BooleanFormat(java.lang.String pattern)
Creates a BooleanFormat object with the specified pattern.

Parameters:

pattern
The String pattern that specifies formatting of true, false, and null values.

BooleanFormat properties

falseString

 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.

nullString

 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.

trueString

 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.


BooleanFormat methods

applyPattern(java.lang.String)

  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:

pattern
The format specification.

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

  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:

value
The boolean value to format. Defaults to null.
result
Where the formatted string should be appended to.
pos
On input: an alignment field, if desired. On output: the offsets of the alignment field.

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)
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:

obj
The boolean value to format. Defaults to null.
toAppendTo
Where the formatted string should be appended to.
pos
On input: an alignment field, if desired. On output: the offsets of the alignment field.

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

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

  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:

text
The string containing a value to be parsed.
pos
On input: an alignment field, if desired. On output: the offsets of the alignment field.

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

  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:

source
The string containing a value to be parsed.
pos
On input: an alignment field, if desired. On output: the offsets of the alignment field.

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

toPattern()

  public String toPattern()
Returns the String pattern specification of the BooleanFormat component.