01: package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
02:
03: import javax.swing.JTextField;
04:
05: /**
06: * @author gwg
07: *
08: * JTextField that saves and restores the original value.
09: * The original value is saved when the table does a setText()
10: * at the start of editing. During editing, the key handlers
11: * may restore the original value or update the contents
12: * without changing the original value.
13: *
14: */
15: public class RestorableJTextField extends JTextField implements
16: IRestorableTextComponent {
17:
18: /*
19: * The original value set in this cell by the table
20: */
21: private String _originalValue = null;
22:
23: /*
24: * When the table initiates editing and sets this field, remember the value as the
25: * original value of the field
26: */
27: public void setText(String originalValue) {
28: if (originalValue == null)
29: _originalValue = "<null>";
30: else
31: _originalValue = originalValue;
32: super .setText(_originalValue);
33: }
34:
35: /*
36: * Used by editing operations to set textField value without
37: * changing the original text saved in the class
38: */
39: public void updateText(String newText) {
40: super .setText(newText);
41: }
42:
43: /*
44: * Used by editing operations to reset the field to its original value.
45: */
46: public void restoreText() {
47: super.setText(_originalValue);
48: }
49: }
|