1 /*
2 * Copyright (C) 2000 Bill Bereza
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Bill Bereza
19 * email : bereza@pobox.com
20 * url : http://www.pobox.com/~bereza/
21 */
22 package net.bereza.money.gui;
23
24 import javax.swing;
25 import javax.swing.text;
26
27 public class UpperCaseField extends JTextField {
28
29 public UpperCaseField(int cols) {
30 super(cols);
31 }
32
33 protected Document createDefaultModel() {
34 return new UpperCaseDocument();
35 }
36
37 static class UpperCaseDocument extends PlainDocument {
38
39 public void insertString(int offs, String str, AttributeSet a)
40 throws BadLocationException {
41
42 if (str == null) {
43 return;
44 }
45 char[] upper = str.toCharArray();
46 for (int i = 0; i < upper.length; i++) {
47 upper[i] = Character.toUpperCase(upper[i]);
48 }
49 super.insertString(offs, new String(upper), a);
50 }
51 }
52 }
53