01: package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
02:
03: import javax.swing.JTextArea;
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 RestorableJTextArea extends JTextArea 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: setCaretPosition(0);
34: }
35:
36: /*
37: * Used by editing operations to set textField value without
38: * changing the original text saved in the class
39: */
40: public void updateText(String newText) {
41: super .setText(newText);
42: setCaretPosition(0);
43: }
44:
45: /*
46: * Used by editing operations to reset the field to its original value.
47: */
48: public void restoreText() {
49: super .setText(_originalValue);
50: setCaretPosition(0);
51: }
52: }
|