01: package org.skunk.swing.text;
02:
03: import javax.swing.text.AttributeSet;
04: import javax.swing.text.BadLocationException;
05: import javax.swing.text.PlainDocument;
06:
07: /**
08: * a document for text fields which enables validation by an EntryFilter.
09: */
10: public class EntryDocument extends PlainDocument {
11: private EntryFilter filter;
12:
13: /**
14: * constructs an EntryDocument with the given filter
15: * @param filter the filter
16: */
17: public EntryDocument(EntryFilter filter) {
18: super ();
19: this .filter = filter;
20: }
21:
22: /**
23: * overridden to prevent insertion if the filter does not accept it.
24: */
25: public void insertString(int offs, String str, AttributeSet a)
26: throws BadLocationException {
27: String wholeString = getText(0, getLength());
28: if (filter.accepts(offs, str, a, wholeString)) {
29: super .insertString(offs, str, a);
30: }
31: }
32:
33: }
34:
35: /* $Log: EntryDocument.java,v $
36: /* Revision 1.3 2001/01/04 06:02:49 smulloni
37: /* added more javadoc documentation.
38: /*
39: /* Revision 1.2 2000/11/09 23:35:13 smullyan
40: /* log added to every Java file, with the help of python. Lock stealing
41: /* implemented, and treatment of locks made more robust.
42: /* */
|