Save This Page
Home » openjdk-7 » net.jbeans » util » text » [javadoc | source]
    1   /* -------------------------------------------------------------------
    2    * Java source file for the class NumberDocument
    3    * 
    4    * Copyright (c), 2002, Masahiro Takatsuka.
    5    * All Rights Researved.
    6    * 
    7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
    8    * $Author: takatsukam $
    9    * 
   10    * $Date: 2003/07/25 04:51:47 $
   11    * 
   12    * $Id: NumberDocument.java,v 1.1.1.1 2003/07/25 04:51:47 takatsukam Exp $
   13    * 
   14    * Reference:		Document no:
   15    * ___				___
   16    * 
   17    * To Do:
   18    * ___
   19    * 
   20   ------------------------------------------------------------------- */
   21   
   22   /* --------------------------- Package ---------------------------- */
   23   package net.jbeans.util.text;
   24   
   25   /* ------------------ Import classes (packages) ------------------- */
   26   import javax.swing.text;
   27   
   28   /*====================================================================
   29                   Implementation of class NumberDocument                
   30   ====================================================================*/
   31   /**
   32    * A text document which will reject any characters that are not
   33    * digits.
   34    * 
   35    * @version $Revision: 1.1.1.1 $
   36    * @author Masahiro Takatsuka (masa@jbeans.net)
   37    * @see PlainDocument
   38    */
   39   
   40   public final class NumberDocument extends PlainDocument {
   41       public final void insertString(int offs, String str, AttributeSet atts) 
   42   		throws BadLocationException  {
   43   		char ch = str.charAt(0);
   44   		if (!Character.isDigit(ch) &&
   45   			ch != '.' &&
   46   			ch != 'e' && ch != 'E' &&
   47   			ch != '-' && ch != '+')  {
   48   			return;
   49   		}
   50           super.insertString(offs, str, atts);
   51       }
   52   }
   53   

Save This Page
Home » openjdk-7 » net.jbeans » util » text » [javadoc | source]