org.jdesktop.swingx.table
Class NumberEditorExt

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by javax.swing.DefaultCellEditor
          extended by org.jdesktop.swingx.table.NumberEditorExt
All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TreeCellEditor

public class NumberEditorExt
extends DefaultCellEditor

Issue #393-swingx: localized NumberEditor. Added feature to use StrictNumberFormatter.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
DefaultCellEditor.EditorDelegate
 
Field Summary
 
Fields inherited from class javax.swing.DefaultCellEditor
clickCountToStart, delegate, editorComponent
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
NumberEditorExt()
          Instantiates an editor with default NumberFormat and default NumberFormatter.
NumberEditorExt(boolean useStrictFormatter)
          Instantiates an editor with default NumberFormat and NumberFormatter depending on useStrictFormatter.
NumberEditorExt(NumberFormat format)
          Instantiates an editor with the given NumberFormat and default NumberFormatter.
NumberEditorExt(NumberFormat format, boolean useStrictFormatter)
          Instantiates an editor with the given NumberFormat and NumberFormatter depending on useStrictFormatter.
 
Method Summary
 Number getCellEditorValue()
          Forwards the message from the CellEditor to the delegate.
 JFormattedTextField getComponent()
          Returns a reference to the editor component.
protected  Number getNumber()
          Returns the editor value as number.
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
          Override and set the border back to normal in case there was an error previously
protected  boolean isValid()
          Returns a boolean indicating whether the current text is valid for instantiating the expected Number type.
 boolean stopCellEditing()
          Forwards the message from the CellEditor to the delegate.
 
Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getClickCountToStart, getTreeCellEditorComponent, 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
 

Constructor Detail

NumberEditorExt

public NumberEditorExt()
Instantiates an editor with default NumberFormat and default NumberFormatter.


NumberEditorExt

public NumberEditorExt(NumberFormat format)
Instantiates an editor with the given NumberFormat and default NumberFormatter.

Parameters:
format - the NumberFormat to use for conversion, may be null to indicate usage of default NumberFormat.

NumberEditorExt

public NumberEditorExt(boolean useStrictFormatter)
Instantiates an editor with default NumberFormat and NumberFormatter depending on useStrictFormatter.

Parameters:
useStrictFormatter - if true, uses a StrictNumberFormatter, else uses default NumberFormatter

NumberEditorExt

public NumberEditorExt(NumberFormat format,
                       boolean useStrictFormatter)
Instantiates an editor with the given NumberFormat and NumberFormatter depending on useStrictFormatter.

Parameters:
format - the NumberFormat to use for conversion, may be null to indicate usage of default NumberFormat
useStrictFormatter - if true, uses a StrictNumberFormatter, else uses default NumberFormatter
Method Detail

stopCellEditing

public boolean stopCellEditing()
Description copied from class: javax.swing.DefaultCellEditor
Forwards the message from the CellEditor to the delegate.

Specified by:
stopCellEditing in interface CellEditor
Overrides:
stopCellEditing in class DefaultCellEditor
Returns:
true
See Also:
DefaultCellEditor.EditorDelegate.stopCellEditing()

isValid

protected boolean isValid()
Returns a boolean indicating whether the current text is valid for instantiating the expected Number type.

Returns:
true if text is valid, false otherwise.

getNumber

protected Number getNumber()
                    throws Exception
Returns the editor value as number. May fail for a variety of reasons, as it forces parsing of the current text as well as reflective construction of the target type.

Returns:
the editor value or null
Throws:
Exception - if creation of the expected type fails in some way.

getTableCellEditorComponent

public Component getTableCellEditorComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             int row,
                                             int column)
Override and set the border back to normal in case there was an error previously

Specified by:
getTableCellEditorComponent in interface TableCellEditor
Overrides:
getTableCellEditorComponent in class DefaultCellEditor
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

getCellEditorValue

public Number getCellEditorValue()
                          throws IllegalStateException
Forwards the message from the CellEditor to the delegate.

Overridden to instantiate a Number of the expected type. Note that this may throw a IllegalStateException if invoked without querying for a valid value with stopCellEditing. This should not happen during normal usage.

Specified by:
getCellEditorValue in interface CellEditor
Overrides:
getCellEditorValue in class DefaultCellEditor
Returns:
the value contained in the editor
Throws:
IllegalStateException - if current value invalid
See Also:
DefaultCellEditor.EditorDelegate.getCellEditorValue()

getComponent

public JFormattedTextField getComponent()
Returns a reference to the editor component.

Convenience override with type cast.

Overrides:
getComponent in class DefaultCellEditor
Returns:
the editor Component