1 | private class KeyTextHandler extends BaseKeyTextHandler {↵ | | 1 | private class KeyTextHandler extends BaseKeyTextHandler {↵
|
2 | public void keyTyped(KeyEvent e) {↵ | | 2 | public void keyTyped(KeyEvent e) {↵
|
3 | char c = e.getKeyChar();↵ | | 3 | char c = e.getKeyChar();↵
|
4 | ↵ | | 4 | ↵
|
5 | // as a coding convenience, create a reference to the text component↵ | | 5 | // as a coding convenience, create a reference to the text component↵
|
6 | // that is typecast to JTextComponent. this is not essential, as we↵ | | 6 | // that is typecast to JTextComponent. this is not essential, as we↵
|
7 | // could typecast every reference, but this makes the code cleaner↵ | | 7 | // could typecast every reference, but this makes the code cleaner↵
|
8 | JTextComponent _theComponent = (JTextComponent)DataTypeInteger.this._textComponent;↵ | | 8 | JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent;↵
|
9 | String text = _theComponent.getText();↵ | | 9 | String text = _theComponent.getText();↵
|
10 | ↵ | | 10 | ↵
|
11 | // look for illegal chars↵ | | 11 | // look for illegal chars↵
|
12 | if ( ! DataTypeInteger.this._isSigned && c == '-') {↵ | | 12 | if ( ! DataTypeShort.this._isSigned && c == '-') {↵
|
13 | // cannot use '-' when unsigned↵ | | 13 | // cannot use '-' when unsigned↵
|
14 | _beepHelper.beep(_theComponent);↵ | | 14 | _beepHelper.beep(_theComponent);↵
|
15 | e.consume();↵ | | 15 | e.consume();↵
|
16 | }↵ | | 16 | }↵
|
17 | ↵ | | 17 | ↵
|
18 | // tabs and newlines get put into the text before this check,↵ | | 18 | // tabs and newlines get put into the text before this check,↵
|
19 | // so remove them↵ | | 19 | // so remove them↵
|
20 | // This only applies to Popup editing since these chars are↵ | | 20 | // This only applies to Popup editing since these chars are↵
|
21 | // not passed to this level by the in-cell editor.↵ | | 21 | // not passed to this level by the in-cell editor.↵
|
22 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {↵ | | 22 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {↵
|
23 | // remove all instances of the offending char↵ | | 23 | // remove all instances of the offending char↵
|
24 | int index = text.indexOf(c);↵ | | 24 | int index = text.indexOf(c);↵
|
25 | if(-1 != index)↵ | | |
|
26 | {↵ | | |
|
27 | ↵ | | 25 | if (index != -1) {↵
|
28 | if (index == text.length() -1) {↵ | | 26 | if (index == text.length() -1) {↵
|
29 | text = text.substring(0, text.length()-1); // truncate string↵ | | 27 | text = text.substring(0, text.length()-1); // truncate string↵
|
30 | }↵ | | |
|
31 | else {↵ | | |
|
32 | ↵ | | 28 | }↵
|
| | | 29 | else {↵
|
33 | text = text.substring(0, index) + text.substring(index+1);↵ | | 30 | text = text.substring(0, index) + text.substring(index+1);↵
|
34 | }↵ | | |
|
35 | }↵ | | 31 | }↵
|
36 | ((IRestorableTextComponent)_theComponent).updateText( text);↵ | | 32 | ((IRestorableTextComponent)_theComponent).updateText( text);↵
|
37 | _beepHelper.beep(_theComponent);↵ | | 33 | _beepHelper.beep(_theComponent);↵
|
38 | ↵ | | 34 | }↵
|
39 | e.consume();↵ | | 35 | e.consume();↵
|
40 | }↵ | | 36 | }↵
|
|
41 | if ( ! ( Character.isDigit(c) ||↵ | | 37 | if ( ! ( Character.isDigit(c) ||↵
|
42 | (c == '-') ||↵ | | 38 | (c == '-') ||↵
|
43 | (c == KeyEvent.VK_BACK_SPACE) ||↵ | | 39 | (c == KeyEvent.VK_BACK_SPACE) ||↵
|
44 | (c == KeyEvent.VK_DELETE) ) ) {↵ | | 40 | (c == KeyEvent.VK_DELETE) ) ) {↵
|
45 | _beepHelper.beep(_theComponent);↵ | | 41 | _beepHelper.beep(_theComponent);↵
|
46 | e.consume();↵ | | 42 | e.consume();↵
|
47 | }↵ | | 43 | }↵
|
|
48 | // check for max size reached (only works when DB provides non-zero scale info↵ | | 44 | // check for max size reached (only works when DB provides non-zero scale info↵
|
49 | if (DataTypeInteger.this._scale > 0 &&↵ | | 45 | if (DataTypeShort.this._scale > 0 &&↵
|
50 | text.length() == DataTypeInteger.this._scale &&↵ | | 46 | text.length() == DataTypeShort.this._scale &&↵
|
51 | c != KeyEvent.VK_BACK_SPACE &&↵ | | 47 | c != KeyEvent.VK_BACK_SPACE &&↵
|
52 | c != KeyEvent.VK_DELETE) {↵ | | 48 | c != KeyEvent.VK_DELETE) {↵
|
53 | // max size reached↵ | | 49 | // max size reached↵
|
54 | e.consume();↵ | | 50 | e.consume();↵
|
55 | _beepHelper.beep(_theComponent);↵ | | 51 | _beepHelper.beep(_theComponent);↵
|
56 | }↵ | | 52 | }↵
|
|
57 | // handle cases of null↵ | | 53 | // handle cases of null↵
|
58 | // The processing is different when nulls are allowed and when they are not.↵ | | 54 | // The processing is different when nulls are allowed and when they are not.↵
|
59 | //↵ | | 55 | //↵
|
|
60 | if ( DataTypeInteger.this._isNullable) {↵ | | 56 | if ( DataTypeShort.this._isNullable) {↵
|
|
61 | // user enters something when field is null↵ | | 57 | // user enters something when field is null↵
|
62 | if (text.equals("<null>")) {↵ | | 58 | if (text.equals("<null>")) {↵
|
63 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | | 59 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵
|
64 | // delete when null => original value↵ | | 60 | // delete when null => original value↵
|
65 | DataTypeInteger.this._textComponent.restoreText();↵ | | 61 | DataTypeShort.this._textComponent.restoreText();↵
|
66 | e.consume();↵ | | 62 | e.consume();↵
|
67 | }↵ | | 63 | }↵
|
68 | else {↵ | | 64 | else {↵
|
69 | // non-delete when null => clear field and add text↵ | | 65 | // non-delete when null => clear field and add text↵
|
70 | DataTypeInteger.this._textComponent.updateText("");↵ | | 66 | DataTypeShort.this._textComponent.updateText("");↵
|
71 | // fall through to normal processing of this key stroke↵ | | 67 | // fall through to normal processing of this key stroke↵
|
72 | }↵ | | 68 | }↵
|
73 | }↵ | | 69 | }↵
|
74 | else {↵ | | 70 | else {↵
|
75 | // check for user deletes last thing in field↵ | | 71 | // check for user deletes last thing in field↵
|
76 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | | 72 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵
|
77 | if (text.length() <= 1 ) {↵ | | 73 | if (text.length() <= 1 ) {↵
|
78 | // about to delete last thing in field, so replace with null↵ | | 74 | // about to delete last thing in field, so replace with null↵
|
79 | DataTypeInteger.this._textComponent.updateText("<null>");↵ | | 75 | DataTypeShort.this._textComponent.updateText("<null>");↵
|
80 | e.consume();↵ | | 76 | e.consume();↵
|
81 | }↵ | | 77 | }↵
|
82 | }↵ | | 78 | }↵
|
83 | }↵ | | 79 | }↵
|
84 | }↵ | | 80 | }↵
|
85 | else {↵ | | 81 | else {↵
|
86 | // field is not nullable↵ | | 82 | // field is not nullable↵
|
87 | //↵ | | 83 | //↵
|
88 | handleNotNullableField(text, c, e, _textComponent);↵ | | 84 | handleNotNullableField(text, c, e, _textComponent);↵
|
89 | | | 85 |
|