
import javax.swing.event.*; 
import javax.swing.text.*; 

/**
 * Class used with minor modification to PlainDocument class,
 * an extension of PlainDocument
 * A plain document that maintains no character attributes.
 */
class IntDocument extends PlainDocument { 

    /**
     * Has some error checking to throw exceptions or return, but calls
     * the super method if no exceptions
     * @param offs the starting offset >= 0
     * @param str  the string to insert; does nothing with null/empty strings
     * @param a    the attributes for the inserted content
     * @throws BadLocationException the given insert position is not
     * a valid position within the document
     */
    public void insertString(int offs, String str, AttributeSet a) 
	throws BadLocationException { 
	int length = str.length(); 
	if (str == null || length == 0) return; 
	for (int i = length; --i >= 0; ) 
	    if (!Character.isDigit(str.charAt(i))) 
		throw new BadLocationException(str, offs); 
	super.insertString(offs, str, a); 
    } 
} 
