ptolemy.actor.gui
Class PortConfigurerDialog.ValidatingJTextFieldCellEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by javax.swing.DefaultCellEditor
          extended by ptolemy.actor.gui.PortConfigurerDialog.ValidatingJTextFieldCellEditor
All Implemented Interfaces:
java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor, javax.swing.tree.TreeCellEditor
Enclosing class:
PortConfigurerDialog

public class PortConfigurerDialog.ValidatingJTextFieldCellEditor
extends javax.swing.DefaultCellEditor

A validating JTextField table cell editor for use with JTable. To determine if a selection is valid, this class uses the CellValidator class.

Based on IntegerEditor from http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/IntegerEditor.java

Since:
Ptolemy II 5.1
Version:
$Id: PortConfigurerDialog.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Christopher Brooks, Sun Microsystems
See Also:
Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
javax.swing.DefaultCellEditor.EditorDelegate
 
Field Summary
private  javax.swing.JFormattedTextField _jFormattedTextField
          The JTextField.
private  java.lang.Object _oldValue
          Old value of the JTextField.
private  boolean _userWantsToEdit
          True if the user wants to edit after having an invalid selection.
private  PortConfigurerDialog.CellValidator _validator
          Class that validates the cell.
 
Fields inherited from class javax.swing.DefaultCellEditor
clickCountToStart, delegate, editorComponent
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
PortConfigurerDialog.ValidatingJTextFieldCellEditor()
          Construct a validating JTextField JTable Cell editor.
PortConfigurerDialog.ValidatingJTextFieldCellEditor(javax.swing.JFormattedTextField jFormattedTextField)
          Construct a validating JTextField JTable Cell editor.
 
Method Summary
 java.lang.Object getCellEditorValue()
          Get the cell editor value.
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
           
 void setValidator(PortConfigurerDialog.CellValidator validator)
          Set the validator.
 boolean stopCellEditing()
          Check the selection and determine whether we should stop editing.
protected  boolean userSaysRevert(java.lang.String selectedItem)
          Return true if the user wants to revert to the original value.
 
Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, 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
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, removeCellEditorListener
 

Field Detail

_jFormattedTextField

private javax.swing.JFormattedTextField _jFormattedTextField
The JTextField.


_oldValue

private java.lang.Object _oldValue
Old value of the JTextField.


_userWantsToEdit

private boolean _userWantsToEdit
True if the user wants to edit after having an invalid selection.


_validator

private PortConfigurerDialog.CellValidator _validator
Class that validates the cell.

Constructor Detail

PortConfigurerDialog.ValidatingJTextFieldCellEditor

public PortConfigurerDialog.ValidatingJTextFieldCellEditor()
Construct a validating JTextField JTable Cell editor.


PortConfigurerDialog.ValidatingJTextFieldCellEditor

public PortConfigurerDialog.ValidatingJTextFieldCellEditor(javax.swing.JFormattedTextField jFormattedTextField)
Construct a validating JTextField JTable Cell editor.

Parameters:
jFormattedTextField - The JTextField that provides choices.
Method Detail

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor
Overrides:
getTableCellEditorComponent in class javax.swing.DefaultCellEditor

getCellEditorValue

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

Specified by:
getCellEditorValue in interface javax.swing.CellEditor
Overrides:
getCellEditorValue in class javax.swing.DefaultCellEditor
Returns:
The string value of the selected item in the combobox.

setValidator

public void setValidator(PortConfigurerDialog.CellValidator validator)
Set the validator.

Parameters:
validator - The validator.

stopCellEditing

public boolean stopCellEditing()
Check the selection and determine whether we should stop editing. If the selection is invalid, ask the user if they want to revert. If the selection is valid, then call stopCellEditing in the super class

Specified by:
stopCellEditing in interface javax.swing.CellEditor
Overrides:
stopCellEditing in class javax.swing.DefaultCellEditor
Returns:
False if the selection is invalid. Otherwise, return whatever super.stopCellEditing() returns.

userSaysRevert

protected boolean userSaysRevert(java.lang.String selectedItem)
Return true if the user wants to revert to the original value. A dialog box pops up that tells the user that their selection is invalid.

Parameters:
selectedItem - The selected item.
Returns:
True if the user elects to revert to the last good value. Otherwise, returns false, indicating that the user wants to continue editing.