Back to index

wims  3.65+svn20090927
Public Member Functions | Private Attributes
SharpTools.NumberField.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 147 of file NumberField.java.


Constructor & Destructor Documentation

Definition at line 150 of file NumberField.java.

                                     {
           super();
           __scratchBuffer = new StringBuffer();
       }

Member Function Documentation

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

Definition at line 156 of file NumberField.java.

                                       {
           if (text == null)
              return;
           
           __scratchBuffer.setLength(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
              __scratchBuffer.append('0');
           } catch(BadLocationException ble) {
              ble.printStackTrace();
              return;
           } catch(StringIndexOutOfBoundsException sioobe) {
              sioobe.printStackTrace();
              return;
           }

           float value;
           try {
              if (integer)
                  value = Integer.parseInt(__scratchBuffer.toString());
              else
                  value = Float.parseFloat(__scratchBuffer.toString());
           } catch(NumberFormatException nfe) {
              // Resulting string will not be number, so reject it
              return;
           }

           if (positiveOnly && value<0)
              return;
           
           super.insertString(offset, text, aset);
       }

Here is the call graph for this function:


Member Data Documentation

Definition at line 148 of file NumberField.java.


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