Back to index

wims  3.65+svn20090927
SharpCellEditor.java
Go to the documentation of this file.
00001 /*
00002  * @(#)SharpCellEditor.java
00003  *
00004  * $Id: SharpCellEditor.java,v 1.7 2000/12/02 21:44:52 rkc10 Exp $
00005  *
00006  * Created on October 27, 2000, 2:19 AM
00007  */
00008 package SharpTools;
00009 import javax.swing.*;
00010 
00019 public class SharpCellEditor extends DefaultCellEditor {
00020 
00023     private JTextField textField;
00024     
00030     public SharpCellEditor(final JTextField textField) {
00031         super(textField);
00032        this.textField = textField;
00033 
00034         /* To account for formula feature only need
00035          * to override the setValue method in EditorDelegate inner
00036          * class.
00037          */
00038         delegate = new EditorDelegate() {
00039             public void setValue(Object value) {
00040               if (value instanceof Cell) {
00041                     Cell temp = (Cell)value;
00042                     
00043                     /* when editing formula cell
00044                      * a string representation is displayed
00045                      */
00046                     if (temp.isFormula()) {
00047                         textField.setText("=" + temp.getFormula().toString());
00048                     }
00049                     else {
00050                         
00051                         //otherwise it is just the normal string conversion
00052                         textField.setText(temp.getValue().toString());
00053                     }
00054                 }
00055                 else {
00056                     
00057                     //empty cells display nothing
00058                     textField.setText((value == null) ? "" : value.toString());
00059                 }
00060 
00061             }
00062 
00063            public Object getCellEditorValue() {
00064               return textField.getText();
00065            }
00066         };
00067        textField.addActionListener(delegate);
00068     }
00069 
00073     public JTextField getTextField() { return textField; }
00074 }