private class KeyTextHandler extends BaseKeyTextHandler { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeLong.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeLong.this._isSigned && c == '-') { // cannot use '-' when unsigned _beepHelper.beep(_theComponent); e.consume(); } // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } if ( ! ( Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // check for max size reached (only works when DB provides non-zero scale info if (DataTypeLong.this._scale > 0 && text.length() == DataTypeLong.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { // max size reached e.consume(); _beepHelper.beep(_theComponent); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeLong.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeLong.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeLong.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeLong.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent);
private class KeyTextHandler extends BaseKeyTextHandler { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeShort.this._isSigned && c == '-') { // cannot use '-' when unsigned _beepHelper.beep(_theComponent); e.consume(); } // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } if ( ! ( Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // check for max size reached (only works when DB provides non-zero scale info if (DataTypeShort.this._scale > 0 && text.length() == DataTypeShort.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { // max size reached e.consume(); _beepHelper.beep(_theComponent); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeShort.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeShort.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeShort.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeShort.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent);
Clone fragments detected by clone detection tool
File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeLong.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeShort.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
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)DataTypeLong.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 ( ! DataTypeLong.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 (index != -1) {
25
					if (index != -1) {
26
						if (index == text.length() -1) {
26
						if (index == text.length() -1) {
27
							text = text.substring(0, text.length()-1);	// truncate string
27
							text = text.substring(0, text.length()-1);	// truncate string
28
						}
28
						}
29
						else {
29
						else {
30
							text = text.substring(0, index) + text.substring(index+1);
30
							text = text.substring(0, index) + text.substring(index+1);
31
						}					
31
						}
32
						((IRestorableTextComponent)_theComponent).updateText( text);
32
						((IRestorableTextComponent)_theComponent).updateText( text);
33
						_beepHelper.beep(_theComponent);
33
						_beepHelper.beep(_theComponent);
34
					}
34
					}
35
					e.consume();
35
					e.consume();
36
				}
36
				}
37
				if ( ! ( Character.isDigit(c) ||
37
				if ( ! ( Character.isDigit(c) ||
38
					(c == '-') ||
38
					(c == '-') ||
39
					(c == KeyEvent.VK_BACK_SPACE) ||
39
					(c == KeyEvent.VK_BACK_SPACE) ||
40
					(c == KeyEvent.VK_DELETE) ) ) {
40
					(c == KeyEvent.VK_DELETE) ) ) {
41
					_beepHelper.beep(_theComponent);
41
					_beepHelper.beep(_theComponent);
42
					e.consume();
42
					e.consume();
43
				}
43
				}
44
				// 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
45
				if (DataTypeLong.this._scale > 0 &&
45
				if (DataTypeShort.this._scale > 0 &&
46
					text.length() == DataTypeLong.this._scale &&
46
					text.length() == DataTypeShort.this._scale &&
47
					c != KeyEvent.VK_BACK_SPACE &&
47
					c != KeyEvent.VK_BACK_SPACE &&
48
					c != KeyEvent.VK_DELETE) {
48
					c != KeyEvent.VK_DELETE) {
49
					// max size reached
49
					// max size reached
50
					e.consume();
50
					e.consume();
51
					_beepHelper.beep(_theComponent);
51
					_beepHelper.beep(_theComponent);
52
				}
52
				}
53
				// handle cases of null
53
				// handle cases of null
54
				// 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.
55
				//
55
				//
56
				if ( DataTypeLong.this._isNullable) {
56
				if ( DataTypeShort.this._isNullable) {
57
					// user enters something when field is null
57
					// user enters something when field is null
58
					if (text.equals("<null>")) {
58
					if (text.equals("<null>")) {
59
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
59
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
60
							// delete when null => original value
60
							// delete when null => original value
61
							DataTypeLong.this._textComponent.restoreText();
61
							DataTypeShort.this._textComponent.restoreText();
62
							e.consume();
62
							e.consume();
63
						}
63
						}
64
						else {
64
						else {
65
							// non-delete when null => clear field and add text
65
							// non-delete when null => clear field and add text
66
							DataTypeLong.this._textComponent.updateText("");
66
							DataTypeShort.this._textComponent.updateText("");
67
							// fall through to normal processing of this key stroke
67
							// fall through to normal processing of this key stroke
68
						}
68
						}
69
					}
69
					}
70
					else {
70
					else {
71
						// check for user deletes last thing in field
71
						// check for user deletes last thing in field
72
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
72
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
73
							if (text.length() <= 1 ) {
73
							if (text.length() <= 1 ) {
74
								// about to delete last thing in field, so replace with null
74
								// about to delete last thing in field, so replace with null
75
								DataTypeLong.this._textComponent.updateText("<null>");
75
								DataTypeShort.this._textComponent.updateText("<null>");
76
								e.consume();
76
								e.consume();
77
							}
77
							}
78
						}
78
						}
79
					}
79
					}
80
				}
80
				}
81
				else {
81
				else {
82
                    // field is not nullable
82
                    // field is not nullable
83
                    //
83
                    //
84
                    handleNotNullableField(text, c, e, _textComponent);
84
                    handleNotNullableField(text, c, e, _textComponent);
85
				
85
				
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0