net.rim.device.api.ui.text
Class NumericTextFilter

java.lang.Object
  |
  +--net.rim.device.api.ui.text.TextFilter
        |
        +--net.rim.device.api.ui.text.NumericTextFilter

public class NumericTextFilter
extends TextFilter

Filters out characters not usable in strings showing numeric data.

This filter favours characters in numeric strings (that is numeric digits, and a minus sign if in the first position.


Field Summary
static int ALLOW_DECIMAL
          Text style that allows numeric strings with decimal notation.
static int ALLOW_NEGATIVE
          Text style that allows negative numbers in numeric strings.
 
Fields inherited from class net.rim.device.api.ui.text.TextFilter
ADN_SIM_PHONE, DEFAULT, DEFAULT_SMART_PHONE, EMAIL, FDN_SIM_PHONE, FILENAME, HEXADECIMAL, INTEGER, IP, LOWERCASE, NUMERIC, PHONE, PIN_ADDRESS, REAL_NUMERIC, SIM_PHONE, SMS_PHONE, STYLE_SHIFT, UPPERCASE, URL, VOICEMAIL_PHONE
 
Constructor Summary
NumericTextFilter()
          Constructs a new NumericTextFilter instance.
NumericTextFilter(int style)
          Constructs a new NumericTextFilter instance with provided style.
 
Method Summary
 char convert(char character, AbstractString text, int position, int status)
          Passes character through numeric text filter.
 char convert(char character, int status)
          Passes character through numeric text filter.
 boolean validate(AbstractString text)
          Determines if provided string contains valid numeric characters.
 boolean validate(char character)
          Determines if character is valid numeric string character.
 boolean validate(char character, AbstractString text, int position)
          Determines if character is valid numeric string character.
 
Methods inherited from class net.rim.device.api.ui.text.TextFilter
get
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALLOW_DECIMAL

public static final int ALLOW_DECIMAL
Text style that allows numeric strings with decimal notation.

ALLOW_NEGATIVE

public static final int ALLOW_NEGATIVE
Text style that allows negative numbers in numeric strings.
Constructor Detail

NumericTextFilter

public NumericTextFilter()
Constructs a new NumericTextFilter instance.

This method builds a new numeric text filter that allows neither negative integers, nor decimals.


NumericTextFilter

public NumericTextFilter(int style)
Constructs a new NumericTextFilter instance with provided style.

Use this method to build a new numeric text filter that can allow negative numbers and/or decimals.

Parameters:
style - Style for this field.
Method Detail

convert

public char convert(char character,
                    AbstractString text,
                    int position,
                    int status)
Passes character through numeric text filter.
Overrides:
convert in class TextFilter
Parameters:
character - Character to test.
text - Text in the current edit field.
position - Current position of cursor in text.
status - Ignored.
Returns:
If you provide a valid character, this method passes it through unaltered. Otherwise, this method returns the ALTed version of the provided character.
Since:
JDE 4.2.0

convert

public char convert(char character,
                    int status)
Passes character through numeric text filter.
Overrides:
convert in class TextFilter
Parameters:
character - Character to test.
status - Ignored.
Returns:
If you provide a valid character, this method passes it through unaltered. Otherwise, this method returns the ALTed version of the provided character.

validate

public boolean validate(AbstractString text)
Determines if provided string contains valid numeric characters.

This method checks each character in your provided string with validate(char) for validity. It does no checking that your string is well formed numeric text, with one exception: this method returns true if the string contains only a single minus sign (if this filter allows negative numbers).

Overrides:
validate in class TextFilter
Parameters:
text - String to check.
Returns:
True if each character in the string passes a validity check, with an optional minus sign at the begining; otherwise, false.

validate

public boolean validate(char character)
Determines if character is valid numeric string character.
Overrides:
validate in class TextFilter
Parameters:
character - Character to test.
Returns:
True if the character is a digit, minus sign, or period; otherwise, false.

validate

public boolean validate(char character,
                        AbstractString text,
                        int position)
Determines if character is valid numeric string character.
Overrides:
validate in class TextFilter
Parameters:
character - Character to test.
text - Text in the current edit field.
position - Current position of cursor in text.
Returns:
True if the character is a digit, minus sign at the beginning of the number, or period; otherwise, false.
Since:
JDE 4.2.0



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.