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)DataTypeByte.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeByte.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 (DataTypeByte.this._scale > 0 && text.length() == DataTypeByte.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 ( DataTypeByte.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 DataTypeByte.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeByte.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 DataTypeByte.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)DataTypeInteger.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeInteger.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(-1 != index) { 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 (DataTypeInteger.this._scale > 0 && text.length() == DataTypeInteger.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 ( DataTypeInteger.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 DataTypeInteger.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeInteger.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 DataTypeInteger.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/DataTypeByte.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeInteger.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)DataTypeByte.this._textComponent;
8
				JTextComponent _theComponent = (JTextComponent)DataTypeInteger.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 ( ! DataTypeByte.this._isSigned && c == '-') {
12
				if ( ! DataTypeInteger.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) {
26
						
25
               if(-1 != index)
26
               {
27
if (index == text.length() -1) {
27
                  if (index == text.length() -1) {
28
							text = text.substring(0, text.length()-1);	// truncate string
28
                     text = text.substring(0, text.length()-1);	// truncate string
29
						}
30
						else {
31
							
29
                  }
30
                  else {
32
text = text.substring(0, index) + text.substring(index+1);
31
                     text = text.substring(0, index) + text.substring(index+1);
33
						}
34
	
32
                  }
33
               }
35
					((IRestorableTextComponent)_theComponent).updateText( text);
34
					((IRestorableTextComponent)_theComponent).updateText( text);
36
						_beepHelper.beep(_theComponent);
35
					_beepHelper.beep(_theComponent);
37
					}
36
					
38
					e.consume();
37
e.consume();
39
				}
38
				}
40
				if ( ! ( Character.isDigit(c) ||
39
				if ( ! ( Character.isDigit(c) ||
41
					(c == '-') ||
40
					(c == '-') ||
42
					(c == KeyEvent.VK_BACK_SPACE) ||
41
					(c == KeyEvent.VK_BACK_SPACE) ||
43
					(c == KeyEvent.VK_DELETE) ) ) {
42
					(c == KeyEvent.VK_DELETE) ) ) {
44
					_beepHelper.beep(_theComponent);
43
					_beepHelper.beep(_theComponent);
45
					e.consume();
44
					e.consume();
46
				}
45
				}
47
				// check for max size reached (only works when DB provides non-zero scale info
46
				// check for max size reached (only works when DB provides non-zero scale info
48
				if (DataTypeByte.this._scale > 0 &&
47
				if (DataTypeInteger.this._scale > 0 &&
49
					text.length() == DataTypeByte.this._scale &&
48
					text.length() == DataTypeInteger.this._scale &&
50
					c != KeyEvent.VK_BACK_SPACE &&
49
					c != KeyEvent.VK_BACK_SPACE &&
51
					c != KeyEvent.VK_DELETE) {
50
					c != KeyEvent.VK_DELETE) {
52
					// max size reached
51
					// max size reached
53
					e.consume();
52
					e.consume();
54
					_beepHelper.beep(_theComponent);
53
					_beepHelper.beep(_theComponent);
55
				}
54
				}
56
				// handle cases of null
55
				// handle cases of null
57
				// The processing is different when nulls are allowed and when they are not.
56
				// The processing is different when nulls are allowed and when they are not.
58
				//
57
				//
59
				if ( DataTypeByte.this._isNullable) {
58
				if ( DataTypeInteger.this._isNullable) {
60
					// user enters something when field is null
59
					// user enters something when field is null
61
					if (text.equals("<null>")) {
60
					if (text.equals("<null>")) {
62
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
61
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
63
							// delete when null => original value
62
							// delete when null => original value
64
							DataTypeByte.this._textComponent.restoreText();
63
							DataTypeInteger.this._textComponent.restoreText();
65
							e.consume();
64
							e.consume();
66
						}
65
						}
67
						else {
66
						else {
68
							// non-delete when null => clear field and add text
67
							// non-delete when null => clear field and add text
69
							DataTypeByte.this._textComponent.updateText("");
68
							DataTypeInteger.this._textComponent.updateText("");
70
							// fall through to normal processing of this key stroke
69
							// fall through to normal processing of this key stroke
71
						}
70
						}
72
					}
71
					}
73
					else {
72
					else {
74
						// check for user deletes last thing in field
73
						// check for user deletes last thing in field
75
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
74
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
76
							if (text.length() <= 1 ) {
75
							if (text.length() <= 1 ) {
77
								// about to delete last thing in field, so replace with null
76
								// about to delete last thing in field, so replace with null
78
								DataTypeByte.this._textComponent.updateText("<null>");
77
								DataTypeInteger.this._textComponent.updateText("<null>");
79
								e.consume();
78
								e.consume();
80
							}
79
							}
81
						}
80
						}
82
					}
81
					}
83
				}
82
				}
84
				else {
83
				else {
85
                    // field is not nullable
84
                    // field is not nullable
86
                    //
85
                    //
87
                    handleNotNullableField(text, c, e, _textComponent);
86
                    handleNotNullableField(text, c, e, _textComponent);
88
				
87
				
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