Class ITextCellEditor

All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TreeCellEditor

public abstract class ITextCellEditor extends TextCellEditor<Object>
Base class for custom text-based table-cell editors in which a cell's value can be created using an InternationalFormatter. An InternationalFormatter can create dates, times, and numbers. To use this class, the methods getFormat(), getFormatter() and convertObject(Object) must be implement:
  • getFormatter() provides a subclass of InternationalFormatter that will format text strings to produce a desired object. This method is called once in the constructor.
  • getFormat() will provide a format that programs the formatter returned by getFormatter(). This method is called once in the constructor.
  • convertObject(Object) converts the value of the text field used by a cell into an object of the desired type.

This class is based on the example provided in a Java tutorial. That link includes a copyright and permission to use/modify that example. This class generalizes that example.

See Also:
  • Constructor Details

    • ITextCellEditor

      public ITextCellEditor()
      Constructor.
  • Method Details

    • getFormat

      protected abstract Format getFormat()
      Get the format used to parse the string representation for the object in the cells handled by this cell editor.
      Returns:
      the format
    • alignment

      protected int alignment()
      Return the alignment for text. Valid values are SwingConstants.LEFT, SwingConstants.CENTER SwingConstants.RIGHT, SwingConstants.LEADING (the default), or SwingConstants.TRAILING.
      Returns:
      the alignment constant
    • getFormatter

      protected abstract InternationalFormatter getFormatter()
      Get the formatter for this object. The formatter will be configured by this object's constructor to use the format returned by getFormat().
      Returns:
      the formatter
    • convertObject

      protected abstract Object convertObject(Object o) throws ITextCellEditor.NoConvertException
      Convert an object to the correct type for a cell. An instance of InputTablePane assigns an object type to each column. In case editing a cell creates a different type, this class can be used to convert that type to the desired one. For example, a database application may want table entries to be instances of java.sql.Date. If the object o ends up as an instance of Date, it can be easily converted to java.sql.Date by the expression new java.sql.Date(((java.util.Date)o).getTime()).
      Parameters:
      o - the object
      Returns:
      the converted object
      Throws:
      ITextCellEditor.NoConvertException - if the argument cannot be converted to the desired type
    • revertMessage

      protected abstract String revertMessage()
      Message to use if the new value for a cell is not valid. For example, if the value must be a date using a specific date format, this message might be "The value must be a date specified by <br> the format MM/DD/YYYY"

      Each line of the message should be about 40 characters long except for the last line. The message is treated as an HTML fragment.

      Returns:
      the message string
    • getTableCellEditorComponent

      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
      Sets an initial value for the editor. This will cause the editor to stopEditing and lose any partially edited value if the editor is editing when this method is called.

      Returns the component that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.

      Note: this description was copied from the documentation for TableCellEditor.

      Specified by:
      getTableCellEditorComponent in interface TableCellEditor
      Overrides:
      getTableCellEditorComponent in class TextCellEditor<Object>
      Parameters:
      table - the JTable that is asking the editor to edit; can be null
      value - the value of the cell to be edited; it is up to the specific editor to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
      isSelected - true if the cell is to be rendered with highlighting
      row - the row of the cell being edited
      column - the column of the cell being edited
      Returns:
      the component for editing
    • getTreeCellEditorComponent

      public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
      Specified by:
      getTreeCellEditorComponent in interface TreeCellEditor
      Overrides:
      getTreeCellEditorComponent in class TextCellEditor<Object>
    • getCellEditorValue

      public Object getCellEditorValue()
      Returns the value contained in this editor.
      Specified by:
      getCellEditorValue in interface CellEditor
      Overrides:
      getCellEditorValue in class TextCellEditor<Object>
      Returns:
      the value contained in this editor
    • stopCellEditing

      public boolean stopCellEditing()
      Specified by:
      stopCellEditing in interface CellEditor
      Overrides:
      stopCellEditing in class TextCellEditor<Object>