com.isti.util.gui.textvalidator
Class ValidatedCellEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by javax.swing.DefaultCellEditor
          extended by com.isti.util.gui.textvalidator.ValidatedCellEditor
All Implemented Interfaces:
java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor, javax.swing.tree.TreeCellEditor

public class ValidatedCellEditor
extends javax.swing.DefaultCellEditor

Class ValidatedCellEditor is an extension of 'DefaultCellEditor' which only allows certain characters to be entered into it.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
javax.swing.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
ValidatedCellEditor(javax.swing.JComboBox comboBox)
          Creates a new 'ValidatedCellEditor' object.
ValidatedCellEditor(javax.swing.JTextField textField)
          Creates a new 'ValidatedCellEditor' object.
ValidatedCellEditor(TextValidator tv)
          Creates a new 'ValidatedCellEditor' object.
 
Method Summary
protected  java.awt.Color getEditorColor(boolean validFlag)
          Get the editor color.
protected  java.lang.String getErrorMessage(java.lang.String s, TextValidator tv)
          Determines if the text entry is valid.
protected  javax.swing.JComponent getJComponent()
          Returns a reference to the editor component.
protected  java.awt.Component getParentComponent()
          Gets the parent component.
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Sets an initial value for the editor.
protected  ValidatedTextComponent getValidatedTextComponent()
          Get the validated text component.
protected  boolean isEqualEntry(java.lang.String s)
          Determines if the text entry is equal to the current value.
protected  boolean isValidEntry(java.lang.String s, boolean showDialogFlag)
          Determines if the text entry is valid.
protected  boolean isValidEntry(java.lang.String s, TextValidator tv, boolean showDialogFlag)
          Determines if the text entry is valid.
protected  boolean setEditorColor(boolean validFlag)
          Set the editor color.
protected  void setEditorColor(java.awt.Color color)
          Set the editor color.
protected  boolean setEditorColor(java.lang.Object value)
          Set the editor color.
protected  int showOptionDialog(java.lang.String message, java.lang.String title)
          Show the option dialog.
 boolean stopCellEditing()
          Determines if editing has stopped.
 
Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getCellEditorValue, getClickCountToStart, getComponent, 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

ValidatedCellEditor

public ValidatedCellEditor(javax.swing.JComboBox comboBox)
Creates a new 'ValidatedCellEditor' object.

Parameters:
comboBox - comboBox a JComboBox object that implements the ValidatedTextComponent interface.
Throws:
java.lang.ClassCastException - if the JComboBox object does not implement the ValidatedTextComponent interface.

ValidatedCellEditor

public ValidatedCellEditor(javax.swing.JTextField textField)
Creates a new 'ValidatedCellEditor' object.

Parameters:
textField - a JTextField object that implements the ValidatedTextComponent interface..
Throws:
java.lang.ClassCastException - if the JTextField object does not implement the ValidatedTextComponent interface.

ValidatedCellEditor

public ValidatedCellEditor(TextValidator tv)
Creates a new 'ValidatedCellEditor' object.

Parameters:
tv - the text validator.
Method Detail

getEditorColor

protected java.awt.Color getEditorColor(boolean validFlag)
Get the editor color.

Parameters:
validFlag - true if the value is valid, false otherwise.
Returns:
the editor color.

getErrorMessage

protected java.lang.String getErrorMessage(java.lang.String s,
                                           TextValidator tv)
Determines if the text entry is valid. The text should be the entire text entry.

Parameters:
s - the text.
tv - the text validator.
Returns:
an error message or null if none.

getJComponent

protected javax.swing.JComponent getJComponent()
Returns a reference to the editor component.

Returns:
the editor JComponent
See Also:
DefaultCellEditor.getComponent()

getParentComponent

protected java.awt.Component getParentComponent()
Gets the parent component.

Returns:
the parent component.

getTableCellEditorComponent

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

Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor
Overrides:
getTableCellEditorComponent in class javax.swing.DefaultCellEditor
Parameters:
table - the JTable that is asking the editor to edit; can be null
value - the value of the cell to be edited
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

getValidatedTextComponent

protected ValidatedTextComponent getValidatedTextComponent()
Get the validated text component.

Returns:
the validated text component.

isEqualEntry

protected boolean isEqualEntry(java.lang.String s)
Determines if the text entry is equal to the current value.

Parameters:
s - the text.
Returns:
true if the text entry is equal to the current value, false otherwise.

isValidEntry

protected boolean isValidEntry(java.lang.String s,
                               boolean showDialogFlag)
Determines if the text entry is valid. The text should be the entire text entry.

Parameters:
s - the text.
showDialogFlag - true to show dialog, false otherwise.
Returns:
true if the text is valid, false otherwise.

isValidEntry

protected boolean isValidEntry(java.lang.String s,
                               TextValidator tv,
                               boolean showDialogFlag)
Determines if the text entry is valid. The text should be the entire text entry.

Parameters:
s - the text.
tv - the text validator.
showDialogFlag - true to show dialog, false otherwise.
Returns:
true if the text is valid, false otherwise.

setEditorColor

protected boolean setEditorColor(boolean validFlag)
Set the editor color.

Parameters:
validFlag - true if the value is valid, false otherwise.
Returns:
true if the value is valid, false otherwise.

setEditorColor

protected void setEditorColor(java.awt.Color color)
Set the editor color.

Parameters:
color - the color.

setEditorColor

protected boolean setEditorColor(java.lang.Object value)
Set the editor color.

Parameters:
value - the value.
Returns:
true if the value is valid, false otherwise.

showOptionDialog

protected int showOptionDialog(java.lang.String message,
                               java.lang.String title)
Show the option dialog.

Parameters:
message - the message.
title - the title.
Returns:
an integer indicating the option chosen by the user, or CLOSED_OPTION if the user closed the dialog.

stopCellEditing

public boolean stopCellEditing()
Determines if editing has stopped.

Specified by:
stopCellEditing in interface javax.swing.CellEditor
Overrides:
stopCellEditing in class javax.swing.DefaultCellEditor
Returns:
true if editing has stopped, false otherwise.