Holger's Java API

## com.antelmann.util.table
Class FormattedCellEditor

    java.lang.Object
      javax.swing.AbstractCellEditor
          com.antelmann.util.table.AbstractSpecialCellEditor
              com.antelmann.util.table.FormattedCellEditor

All Implemented Interfaces:
  Serializable, CellEditor, TableCellEditor, TreeCellEditor

    public class FormattedCellEditor

extends AbstractSpecialCellEditor
implements TableCellEditor, TreeCellEditor

edits cells flexibly while the return value is the actual Type, not a String (like it is with a DefaultCellEditor). In addition, this class allows to easily customize further validation checking including displaying an appropriate message to the user. By default, this editor allows null values to be entered by providing an empty String to the field.

Since:
  2. April 2007, 12:08
Author:
  Holger Antelmann
See Also:
  `DefaultCellEditor`, Serialized Form

Field Summary

Fields inherited from class javax.swing.AbstractCellEditor
`changeEvent, listenerList`

Constructor Summary
`FormattedCellEditor(Filter<? super String> stringFilter)` uses `FormattedCellRenderer.ToStringFormat`
`FormattedCellEditor(Format format)` calls this(format, true)
`FormattedCellEditor(Format format, boolean selectAllOnFocus)`

Method Summary
`Object` `getCellEditorValue()`
`JFormattedTextField` `getComponent()`
`Format` `getFormat()`
`boolean` `getSelectAllOnFocus()`
`Filter<? super String>` `getStringFilter()`
`Component` `getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)`
`Component` `getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)`
`protected Object` `getValidationString(String value)` called when the isValid(String) method returns false; if anything but null is returned, a dialog pops up displaying the returned Object (allowing a custom message to be displayed).
`boolean` `isCellEditable(EventObject ev)` checks for MouseEvent instances and there reacts according to the `AbstractSpecialCellEditor.getClickCountToStart()` value
`protected boolean` `isValid(String value)` checks the input String of the field before the Format parses it.
`void` `setDoNotAllowNullFilter(String messageIfValueIsEmpty)` sets a special filter that does NOT allow NULL as a value
`FormattedCellEditor` `setHorizonalAligment(int alignment)` shortcut
`void` `setSelectAllOnFocus(boolean flag)`
`void` `setStringFilter(Filter<? super String> stringFilter)` `VerboseFilter` are honored
`boolean` `stopCellEditing()`

Methods inherited from class com.antelmann.util.table.AbstractSpecialCellEditor
`getClickCountToStart, setClickCountToStart`

Methods inherited from class javax.swing.AbstractCellEditor
`addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener, shouldSelectCell`

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, shouldSelectCell`

Constructor Detail

### FormattedCellEditor

    public FormattedCellEditor(Filter<? super String> stringFilter)

  uses `FormattedCellRenderer.ToStringFormat`

### FormattedCellEditor

    public FormattedCellEditor(Format format)

  calls this(format, true)

### FormattedCellEditor

    public FormattedCellEditor(Format format,
                               boolean selectAllOnFocus)

Method Detail

### setHorizonalAligment

    public FormattedCellEditor setHorizonalAligment(int alignment)

  shortcut

### getComponent

    public JFormattedTextField getComponent()

### getFormat

    public Format getFormat()

### getSelectAllOnFocus

    public boolean getSelectAllOnFocus()

### setSelectAllOnFocus

    public void setSelectAllOnFocus(boolean flag)

### getCellEditorValue

    public Object getCellEditorValue()

  Specified by:
    `getCellEditorValue` in interface `CellEditor`

### getTableCellEditorComponent

    public Component getTableCellEditorComponent(JTable table,
                                                 Object value,
                                                 boolean isSelected,
                                                 int row,
                                                 int column)

  Specified by:
    `getTableCellEditorComponent` in interface `TableCellEditor`

### getTreeCellEditorComponent

    public Component getTreeCellEditorComponent(JTree tree,
                                                Object value,
                                                boolean isSelected,
                                                boolean expanded,
                                                boolean leaf,
                                                int row)

  Specified by:
    `getTreeCellEditorComponent` in interface `TreeCellEditor`

### isValid

    protected boolean isValid(String value)

  checks the input String of the field before the Format parses it. This method allows to check input data beyond the capabilities of the formatter; this implementation is based on `getStringFilter()` .

### getStringFilter

    public Filter<? super String> getStringFilter()

  See Also:
    `setStringFilter(Filter)`

### setStringFilter

    public void setStringFilter(Filter<? super String> stringFilter)

  `VerboseFilter` are honored

### getValidationString

    protected Object getValidationString(String value)

  called when the isValid(String) method returns false; if anything but null is returned, a dialog pops up displaying the returned Object (allowing a custom message to be displayed). This implementation (unless overridden) returns either null or - if the filter is a `VerboseFilter` - uses the given message of that filter.

### setDoNotAllowNullFilter

    public void setDoNotAllowNullFilter(String messageIfValueIsEmpty)

  sets a special filter that does NOT allow NULL as a value

  See Also:
    `setStringFilter(Filter)`

### stopCellEditing

    public boolean stopCellEditing()

  Specified by:
    `stopCellEditing` in interface `CellEditor`
  Overrides:
    `stopCellEditing` in class `AbstractCellEditor`

### isCellEditable

    public boolean isCellEditable(EventObject ev)

  Description copied from class: `AbstractSpecialCellEditor`
  checks for MouseEvent instances and there reacts according to the `AbstractSpecialCellEditor.getClickCountToStart()` value

  Specified by:
    `isCellEditable` in interface `CellEditor`
  Overrides:
    `isCellEditable` in class `AbstractSpecialCellEditor`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads