Back to index

wims  3.65+svn20090927
Public Member Functions | Private Attributes
SharpTools.AddressField.NumberFilterDocument Class Reference

List of all members.

Public Member Functions

 NumberFilterDocument ()
void insertString (int offset, String text, AttributeSet aset) throws BadLocationException

Private Attributes

StringBuffer __scratchBuffer

Detailed Description

Definition at line 51 of file

Constructor & Destructor Documentation

Definition at line 54 of file

           __scratchBuffer = new StringBuffer();

Member Function Documentation

void SharpTools.AddressField.NumberFilterDocument.insertString ( int  offset,
String  text,
AttributeSet  aset 
) throws BadLocationException [inline]

Definition at line 59 of file

           if (text == null || text.length() == 0)


           // Reject all strings that cause the contents of the field not
           // to be a valid number (i.e., string representation of a double)
           try {
              __scratchBuffer.append(getText(0, getLength()));
              __scratchBuffer.insert(offset, text);
              // Kludge: Append a 0 so that leading decimal points
              // and signs will be accepted
           } catch(BadLocationException ble) {
           } catch(StringIndexOutOfBoundsException sioobe) {
           String buf = __scratchBuffer.toString();
           boolean hasNumber = false;
           // only allow {letters}{numbers}
           for (int i=0; i<buf.length(); i++) {
              char c = buf.charAt(i);

              // is a letter?
              if (!Character.isLetter(c)) {
                  // no, is a digit?
                  if (Character.isDigit(c) && i>0)
                     // the first c has to be letter
                     // yes, following should be all digits
                     hasNumber = true;
                     // no, invalid
              else if (hasNumber) // should not be letter anymore
           super.insertString(offset, text.toUpperCase(), aset);

Here is the call graph for this function:

Member Data Documentation

Definition at line 52 of file

The documentation for this class was generated from the following file: