View Javadoc
1 /* 2 * GeoVISTA Center (Penn State, Dept. of Geography) 3 * Copyright (c), 1999 - 2002, GeoVISTA Center 4 * All Rights Researved. 5 * 6 * Description: It displays the edu.psu.geovista.app.spreadsheet.formula string of a edu.psu.geovista.app.spreadsheet.formula cell when cell is being edited. 7 * It inherits all methods of the DefaultCellEditor. 8 * 9 * Date: Mar 13, 2003 10 * Time: 11:54:25 AM 11 * @author Jin Chen 12 */ 13 14 package edu.psu.geovista.app.spreadsheet.formula; 15 16 17 import javax.swing.*; 18 public class CellFomulaEditor extends DefaultCellEditor { 19 /*** the JTextField object this editor uses 20 */ 21 private JTextField cellField; 22 private FormulaEditor fe; 23 24 /*** 25 * 26 * 27 * @param textField a JtextField object 28 */ 29 public CellFomulaEditor(final JTextField textField,FormulaEditor _fe) { 30 super(textField); 31 this.fe=_fe; 32 this.cellField = textField; 33 34 /* To account for edu.psu.geovista.app.spreadsheet.formula feature only need 35 * to override the setValue method in EditorDelegate inner 36 * class. 37 */ 38 delegate = new EditorDelegate() { 39 public void setValue(Object value) { 40 41 42 if (value instanceof Cell) { 43 Cell temp = (Cell)value; 44 45 /* when editing edu.psu.geovista.app.spreadsheet.formula cell 46 * a string representation is displayed 47 */ 48 String v; 49 if (temp.isFormula()) { 50 v="=" + temp.getFormula().toString(); 51 textField.setText(v); 52 53 } 54 else { 55 56 //otherwise it is just the normal string conversion 57 if (temp.getValue()!=null){ 58 v=temp.getValue().toString(); 59 textField.setText(v); 60 } 61 else{ //Must, otherwise if temp.getValue()==null, the last entered value will be put in the cell 62 v=""; 63 textField.setText(v); 64 } 65 } 66 // fe.getFormulaField().setText(v); 67 } 68 else { 69 70 //empty cells display nothing 71 textField.setText((value == null) ? "" : value.toString()); 72 } //if 73 74 } //setValue() 75 76 public Object getCellEditorValue() { 77 return textField.getText(); 78 } 79 }; //inner class 80 //MUST, thus it will listen when editing on textfield finished 81 textField.addActionListener(delegate); 82 } 83 84 /*** get the component used by this editor 85 * @return the JTextField used by this editor 86 */ 87 public JTextField getCellField() { return cellField; } 88 }

This page was automatically generated by Maven