-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathUpperCaseDocumentFilter.java
More file actions
42 lines (38 loc) · 1.07 KB
/
UpperCaseDocumentFilter.java
File metadata and controls
42 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
import javax.swing.text.DocumentFilter.FilterBypass;
/**
* The UpperCaseDocumentFilter converts all characters to upper case before
* the characters are inserted into the Document.
*/
public class UpperCaseDocumentFilter extends ChainedDocumentFilter
{
/**
* Standard constructor for stand alone usage
*/
public UpperCaseDocumentFilter()
{
}
/**
* Constructor used when further filtering is required after this
* filter has been applied.
*/
public UpperCaseDocumentFilter(DocumentFilter filter)
{
super(filter);
}
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
throws BadLocationException
{
replace(fb, offs, 0, str, a);
}
public void replace(FilterBypass fb, final int offs, final int length, final String text, final AttributeSet a)
throws BadLocationException
{
if (text != null)
{
super.replace(fb, offs, length, text.toUpperCase(), a);
}
}
}