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)DataTypeDate.this._textComponent; String text = _theComponent.getText(); // 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(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeDate.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 DataTypeDate.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeDate.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 DataTypeDate.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)DataTypeTime.this._textComponent; String text = _theComponent.getText(); // 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 == 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(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeTime.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 DataTypeTime.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeTime.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 DataTypeTime.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/DataTypeDate.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTime.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
				// as a coding convenience, create a reference to the text component
4
            // as a coding convenience, create a reference to the text component
5
				// that is typecast to JTextComponent.  this is not essential, as we
5
            // that is typecast to JTextComponent.  this is not essential, as we
6
				// could typecast every reference, but this makes the code cleaner
6
            // could typecast every reference, but this makes the code cleaner
7
				JTextComponent _theComponent = (JTextComponent)DataTypeDate.this._textComponent;
7
            JTextComponent _theComponent = (JTextComponent)DataTypeTime.this._textComponent;
8
				String text = _theComponent.getText();
8
            String text = _theComponent.getText();
9
				// tabs and newlines get put into the text before this check,
9
            // tabs and newlines get put into the text before this check,
10
				// so remove them
10
            // so remove them
11
				// This only applies to Popup editing since these chars are
11
            // This only applies to Popup editing since these chars are
12
				// not passed to this level by the in-cell editor.
12
            // not passed to this level by the in-cell editor.
13
				if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
13
            if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
14
					// remove all instances of the offending char
14
               // remove all instances of the offending char
15
					int index = text.indexOf(c);
15
               int index = text.indexOf(c);
16
					if (index != -1) {
17
						if (index == text.length() -1) {
16
               if (index == text.length() -1) {
18
							text = text.substring(0, text.length()-1);	// truncate string
17
                  text = text.substring(0, text.length()-1);	// truncate string
19
						}
20
						else {
21
							
18
               }
19
               else {
22
text = text.substring(0, index) + text.substring(index+1);
20
                  text = text.substring(0, index) + text.substring(index+1);
23
						}
24
						
21
               }
25
((IRestorableTextComponent)_theComponent).updateText( text);
22
               ((IRestorableTextComponent)_theComponent).updateText( text);
26
						_beepHelper.beep(_theComponent);
23
               _beepHelper.beep(_theComponent);
27
					}
28
					e.consume();
29
				}
30
				
24
               e.consume();
25
            }
31
// handle cases of null
26
            // handle cases of null
32
				// The processing is different when nulls are allowed and when they are not.
27
            // The processing is different when nulls are allowed and when they are not.
33
				//
34
				
28
            //
35
if ( DataTypeDate.this._isNullable) {
29
            if ( DataTypeTime.this._isNullable) {
36
					// user enters something when field is null
30
               // user enters something when field is null
37
					if (text.equals("<null>")) {
31
               if (text.equals("<null>")) {
38
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
32
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
39
							// delete when null => original value
33
                     // delete when null => original value
40
							DataTypeDate.this._textComponent.restoreText();
34
                     DataTypeTime.this._textComponent.restoreText();
41
							e.consume();
42
						}
43
						else {
44
							
35
                     e.consume();
36
                  }
37
                  else {
45
// non-delete when null => clear field and add text
38
                     // non-delete when null => clear field and add text
46
							DataTypeDate.this._textComponent.updateText("");
39
                     DataTypeTime.this._textComponent.updateText("");
47
							// fall through to normal processing of this key stroke
40
                     // fall through to normal processing of this key stroke
48
						}
49
					}
50
					else {
51
						
41
                  }
42
               }
43
               else {
52
// check for user deletes last thing in field
44
                  // check for user deletes last thing in field
53
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
45
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
54
							if (text.length() <= 1 ) {
46
                     if (text.length() <= 1 ) {
55
								// about to delete last thing in field, so replace with null
47
                        // about to delete last thing in field, so replace with null
56
								DataTypeDate.this._textComponent.updateText("<null>");
48
                        DataTypeTime.this._textComponent.updateText("<null>");
57
								e.consume();
58
							}
59
						}
60
					}
61
				}
62
				else {
63
						  // field is not nullable
64
						  //
65
						
49
                        e.consume();
50
                     }
51
                  }
52
               }
53
            }
54
            else {
55
                    // field is not nullable
56
                    //
66
  handleNotNullableField(text, c, e, _textComponent)
57
                    handleNotNullableField(text, c, e, _textComponent)
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