uk.ac.ic.doc.automed.editor
Class TextEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by uk.ac.ic.doc.automed.editor.TextEditor
All Implemented Interfaces:
java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor
Direct Known Subclasses:
DetachedTextEditor

public class TextEditor
extends javax.swing.AbstractCellEditor
implements javax.swing.table.TableCellEditor

Cell editor class for cache table. This class uses a combination of a TextArea
and a JScrollPane to construct a flexible scrollable text box that
appears whenever a cell's value is too long to fit in a table's column

To use this class, all you need to do is to initialise a JTable object
and invoke the following method:
myTable.setDefaultEditor(Object.class, new TextEditor(myTable)); if you would like to use the same editor for all columns. Alternatively,
you could use myColumn.setCellEditor(new TextEditor(myTable)) to
use the editor for a specific table column.

Author:
Duc M Le dmle@doc.ic.ac.uk
See Also:
Serialized Form

Field Summary
private  javax.swing.JScrollPane _scrollPane
           
private  javax.swing.JTable _table
           
private  javax.swing.JTextArea _textEditor
           
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
TextEditor()
           
TextEditor(javax.swing.JTable table)
           
 
Method Summary
static int calculateCellValueLength(java.awt.Component c, java.lang.String value)
          Get the estimated length of a text string painted on a component
 java.lang.Object getCellEditorValue()
          Implement one method of AbstractCellEditor adapter class
protected static javax.swing.JScrollPane getScrollPane(javax.swing.JTextArea textEditor)
          Initialises the scroll pane for the text area
protected  java.lang.String getSelectedValue(javax.swing.JTable table)
          Get the selected cell value
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Implement TableCellEditor interface.
Return the actual text editor to use in the selected table cell.
protected static javax.swing.JTextArea getTextArea(java.lang.String value, boolean editable, boolean wrapped, int width, int height)
          Initialises the text area to use
protected  void resetEditor(javax.swing.JTextArea textEditor, javax.swing.JCheckBox chkWrapped)
          Give default settings to text area
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 

Field Detail

_textEditor

private javax.swing.JTextArea _textEditor

_scrollPane

private javax.swing.JScrollPane _scrollPane

_table

private javax.swing.JTable _table
Constructor Detail

TextEditor

public TextEditor()

TextEditor

public TextEditor(javax.swing.JTable table)
Method Detail

getTextArea

protected static javax.swing.JTextArea getTextArea(java.lang.String value,
                                                   boolean editable,
                                                   boolean wrapped,
                                                   int width,
                                                   int height)
Initialises the text area to use


getScrollPane

protected static javax.swing.JScrollPane getScrollPane(javax.swing.JTextArea textEditor)
Initialises the scroll pane for the text area


resetEditor

protected void resetEditor(javax.swing.JTextArea textEditor,
                           javax.swing.JCheckBox chkWrapped)
Give default settings to text area


getCellEditorValue

public java.lang.Object getCellEditorValue()
Implement one method of AbstractCellEditor adapter class

Specified by:
getCellEditorValue in interface javax.swing.CellEditor

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Implement TableCellEditor interface.
Return the actual text editor to use in the selected table cell.

Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor

getSelectedValue

protected java.lang.String getSelectedValue(javax.swing.JTable table)
Get the selected cell value


calculateCellValueLength

public static int calculateCellValueLength(java.awt.Component c,
                                           java.lang.String value)
Get the estimated length of a text string painted on a component