kiwi.ui
Class NumericCellEditor

java.lang.Object
  extended byjavax.swing.AbstractCellEditor
      extended byjavax.swing.DefaultCellEditor
          extended bykiwi.ui.NumericCellEditor
All Implemented Interfaces:
javax.swing.CellEditor, java.io.Serializable, javax.swing.table.TableCellEditor, javax.swing.tree.TreeCellEditor

public class NumericCellEditor
extends javax.swing.DefaultCellEditor

A cell editor for editing numeric fields, including integer, decimal, percentage, and currency amounts, formatted according to the rules of the current locale.

Author:
Mark Lindner, PING Software Group
See Also:
kiwi.text.FormatConstants, LocaleManager, NumericField, NumericTableCellRenderer, kiwi.db.DomainObjectFieldAdapter, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.DefaultCellEditor
javax.swing.DefaultCellEditor.EditorDelegate
 
Field Summary
private  NumericField field
           
 
Fields inherited from class javax.swing.DefaultCellEditor
clickCountToStart, delegate, editorComponent
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
NumericCellEditor(int type)
          Construct a new NumericCellEditor of the specified type.
NumericCellEditor(int type, int decimals)
          Construct a new NumericCellEditor of the specified type and number of decimals displayed.
 
Method Summary
private  java.awt.Component _prepareEditor(java.lang.Object value)
           
 java.lang.Object getCellEditorValue()
          Get the value currently in the cell editor.
 int getDecimals()
          Get the number of decimal places being displayed by this cell editor.
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Get an editor for a JTable.
 java.awt.Component getTreeCellEditorComponent(javax.swing.JTree tree, java.lang.Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
          Get an editor for a JTree.
 int getType()
          Get the formatting type.
 void setDecimals(int decimals)
          Set the number of decimal places to display for non-integer values.
 void setType(int type)
          Set the formatting type.
 boolean stopCellEditing()
          Stop cell editing.
private  boolean validate()
           
 
Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getClickCountToStart, getComponent, isCellEditable, setClickCountToStart, shouldSelectCell
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener
 
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, removeCellEditorListener
 

Field Detail

field

private NumericField field
Constructor Detail

NumericCellEditor

public NumericCellEditor(int type)
Construct a new NumericCellEditor of the specified type.

Parameters:
type - The data type to be edited by this field; one of the constants CURRENCY_FORMAT, DECIMAL_FORMAT, INTEGER_FORMATPERCENTAGE_FORMAT, defined in kiwi.text.FormatConstants.

NumericCellEditor

public NumericCellEditor(int type,
                         int decimals)
Construct a new NumericCellEditor of the specified type and number of decimals displayed.

Parameters:
type - The data type to be edited by this field; one of the constants CURRENCY_FORMAT, DECIMAL_FORMAT, INTEGER_FORMATPERCENTAGE_FORMAT, defined in kiwi.text.FormatConstants.
decimals - The number of decimal places to be displayed (for non-integer values only).
Method Detail

stopCellEditing

public final boolean stopCellEditing()
Stop cell editing. This method stops cell editing (effectively committing the edit) only if the data entered is validated successfully.

Returns:
true if cell editing may stop, and false otherwise.

validate

private boolean validate()

getCellEditorValue

public java.lang.Object getCellEditorValue()
Get the value currently in the cell editor.

Returns:
The current value, as a Double.

setType

public void setType(int type)
Set the formatting type.

Parameters:
type - The data type to be edited by this cell editor. See the constructor for more information.

getType

public int getType()
Get the formatting type.

Returns:
The data type being edited by this cell editor.

setDecimals

public void setDecimals(int decimals)
Set the number of decimal places to display for non-integer values.

Parameters:
decimals - The number of decimal places.
Throws:
java.lang.IllegalArgumentException - If decimals is less than 0.

getDecimals

public int getDecimals()
Get the number of decimal places being displayed by this cell editor.

Returns:
The number of decimal places.

_prepareEditor

private java.awt.Component _prepareEditor(java.lang.Object value)

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Get an editor for a JTable.


getTreeCellEditorComponent

public java.awt.Component getTreeCellEditorComponent(javax.swing.JTree tree,
                                                     java.lang.Object value,
                                                     boolean isSelected,
                                                     boolean expanded,
                                                     boolean leaf,
                                                     int row)
Get an editor for a JTree.