FileDocCategorySizeDatePackage
FormattedDocument.javaAPI DocExample1747Tue Dec 12 18:59:20 GMT 2000None

FormattedDocument

public class FormattedDocument extends PlainDocument

Fields Summary
private Format
format
Constructors Summary
public FormattedDocument(Format f)

        format = f;
    
Methods Summary
public java.text.FormatgetFormat()

        return format;
    
public voidinsertString(int offs, java.lang.String str, javax.swing.text.AttributeSet a)


        String currentText = getText(0, getLength());
        String beforeOffset = currentText.substring(0, offs);
        String afterOffset = currentText.substring(offs, currentText.length());
        String proposedResult = beforeOffset + str + afterOffset;

        try {
            format.parseObject(proposedResult);
            super.insertString(offs, str, a);
        } catch (ParseException e) {
            Toolkit.getDefaultToolkit().beep();
            System.err.println("insertString: could not parse: "
                               + proposedResult);
        }
    
public voidremove(int offs, int len)

        String currentText = getText(0, getLength());
        String beforeOffset = currentText.substring(0, offs);
        String afterOffset = currentText.substring(len + offs,
                                                   currentText.length());
        String proposedResult = beforeOffset + afterOffset;

        try {
            if (proposedResult.length() != 0)
                format.parseObject(proposedResult);
            super.remove(offs, len);
        } catch (ParseException e) {
            Toolkit.getDefaultToolkit().beep();
            System.err.println("remove: could not parse: " + proposedResult);
        }