package net.sf.jpluck.swing;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
public class LimitedDocument extends PlainDocument {
private int maxLength;
public LimitedDocument(int maxLength) {
this.maxLength = maxLength;
}
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
if (getLength() + str.length() <= maxLength) {
super.insertString(offs, str, a);
} else {
throw new BadLocationException("Too long", offs);
}
}
}