org.gjt.btools.gui.component
Class LongStringRenderer

java.lang.Object
  |
  +--javax.swing.AbstractCellEditor
        |
        +--org.gjt.btools.gui.component.LongStringRenderer
All Implemented Interfaces:
javax.swing.CellEditor, java.io.Serializable, javax.swing.table.TableCellEditor, javax.swing.table.TableCellRenderer

public class LongStringRenderer
extends javax.swing.AbstractCellEditor
implements javax.swing.table.TableCellRenderer, javax.swing.table.TableCellEditor

A component used to represent very long strings in table cells. A standard label is inadequate for displaying very long strings because there is no way to scroll across to see beyond the initial portion that fits into the table cell. This component provides a button that brings up a dialog displaying the full cell contents.

This component is actually implemented both as a cell renderer and a cell editor. It cannot be used to edit table values, but because the user must interact directly with this component, it must be registered both as a renderer and an editor for the appropriate table cells, and the table model must declare that such cells be editable. No change will ever be made to the underlying table data.

The renderer is a simple label that will only display the leftmost portion of the cell contents. When the user clicks on such a cell, the editor appears. The editor consists of a read-only text edit field that fills most of the table cell (this field can be scrolled and selections can be made) and a button at the very right hand end that brings up a dialog displaying the full cell contents. Such dialogs are not model and can be left on screen as long as desired (so for instance multiple cell contents can be viewed and compared). The cell contents are copied to the dialog and so the dialog may remain on screen well after the table has been destroyed.

The table cells may contain any objects; the method Object.toString() will be used to convert them into strings for display. The method for choosing a title for the corresponding content viewer dialog can be changed by overriding method getDialogTitle(). The default implementation simply uses the corresponding column heading in the table.

See Also:
getDialogTitle(javax.swing.JTable, java.lang.Object, int, int), Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
LongStringRenderer()
          Creates a new long string renderer.
LongStringRenderer(int clicksToEdit)
          Creates a new long string renderer.
 
Method Summary
 java.lang.Object getCellEditorValue()
          Returns the value of the table cell being edited.
 java.lang.String getDialogTitle(javax.swing.JTable table, java.lang.Object value, int row, int column)
          Returns the title to use for the dialog that will display the full contents of the given cell.
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Returns the component that does the pseudo-editing.
 java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column)
          Returns the component that does the rendering.
 boolean isCellEditable(java.util.EventObject e)
          Determines if the given event is cause to start editing the table cell.
 boolean shouldSelectCell(java.util.EventObject e)
          Prepares the component for editing as requested by the given event.
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener, 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, removeCellEditorListener, stopCellEditing
 

Constructor Detail

LongStringRenderer

public LongStringRenderer()
Creates a new long string renderer. Cell editing will begin with a single mouse click.


LongStringRenderer

public LongStringRenderer(int clicksToEdit)
Creates a new long string renderer.

Parameters:
clicksToEdit - the number of mouse clicks required for cell editing to begin.
Method Detail

getDialogTitle

public java.lang.String getDialogTitle(javax.swing.JTable table,
                                       java.lang.Object value,
                                       int row,
                                       int column)
Returns the title to use for the dialog that will display the full contents of the given cell. The default implementation returns the name of the column in which the given cell lies.

Parameters:
table - the table containing the given cell.
value - the value stored in the given cell.
row - the row of the given cell in the table.
column - the column of the given cell in the table.
Returns:
the title to use for the corresponding content viewer dialog.

getTableCellRendererComponent

public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table,
                                                        java.lang.Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column)
Returns the component that does the rendering.

Specified by:
getTableCellRendererComponent in interface javax.swing.table.TableCellRenderer
Parameters:
table - the table in which a cell is being rendered.
value - the value of the table cell being rendered.
isSelected - whether or not the table cell is currently selected.
hasFocus - whether or not the table cell currently has the focus.
row - the row of the table cell being rendered.
column - the column of the table cell being rendered.
Returns:
the component that does the rendering.

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Returns the component that does the pseudo-editing.

Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor
Parameters:
table - the table in which a cell is being edited.
value - the value of the table cell being edited.
isSelected - whether or not the table cell is currently selected.
row - the row of the table cell being edited.
column - the column of the table cell being edited.
Returns:
the component that does the editing.

isCellEditable

public boolean isCellEditable(java.util.EventObject e)
Determines if the given event is cause to start editing the table cell.

Specified by:
isCellEditable in interface javax.swing.CellEditor
Overrides:
isCellEditable in class javax.swing.AbstractCellEditor
Parameters:
e - the event under consideration.
Returns:
true if and only if the table cell should be edited.

getCellEditorValue

public java.lang.Object getCellEditorValue()
Returns the value of the table cell being edited.

Specified by:
getCellEditorValue in interface javax.swing.CellEditor
Returns:
the value of the table cell being edited.

shouldSelectCell

public boolean shouldSelectCell(java.util.EventObject e)
Prepares the component for editing as requested by the given event.

Specified by:
shouldSelectCell in interface javax.swing.CellEditor
Overrides:
shouldSelectCell in class javax.swing.AbstractCellEditor
Parameters:
e - the event that caused editing to begin.
Returns:
true if and only if the table cell being edited should be selected.


Copyright © 1998-2001, Ben Burton
This software is released under the GNU Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).