package usda.weru.weps.gui;

/**
 *
 * @author jcgao
 */
//import javax.swing.text.PlainDocument;
import javax.swing.text.*;

/**
 *
 * @author maxerdwien
 */
public class LimitDocument extends PlainDocument {

    private static final long serialVersionUID = 1L;

    private final int limit;

    LimitDocument(int limit) {
        super();
        this.limit = limit;
    }

    /**
     *
     * @param offset
     * @param str
     * @param attr
     * @throws BadLocationException
     */
    @Override
    public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
        if (str == null) {
            return;
        }
        if (getLength() + str.length() <= limit) {
            super.insertString(offset, str, null);
        }
    }
}
