Package jmri.swing

Class NamedBeanComboBox<B extends NamedBean>

Type Parameters:
B - the supported type of NamedBean
All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener
Direct Known Subclasses:
TurnoutTableJTable.BeanBoxRenderer

public class NamedBeanComboBox<B extends NamedBean>
extends JComboBox<B>
A JComboBox for NamedBeans.

When editable, this will create a new NamedBean if backed by a ProvidingManager if getSelectedItem() is called and the current text is neither the system name nor user name of an existing NamedBean. This will also validate input when editable, showing an Information (blue I in circle) icon to indicate a name will be used to create a new Named Bean, an Error (red X in circle) icon to indicate a typed in name cannot be used (either because it would not be valid as a user name or system name or because the name of an existing NamedBean not usable in the current context has been entered, or no icon to indicate the name of an existing Named Bean has been entered.

When not editable, this will allow (but may not actively show) continual typing of a system name or a user name by a user to match a NamedBean even if only the system name or user name or both are displayed (e.g. if a list of turnouts is shown by user name only, a user may type in the system name of the turnout and the turnout will be selected correctly). If the typing speed is slower than the UIManager's ComboBox.timeFactor setting, keyboard input acts like a normal JComboBox, with only the first character displayed matching the user input.

Note: It is recommended that implementations that exclude some NamedBeans from the combo box call JComponent.setToolTipText(String) to provide a context specific reason for excluding those items. The default tool tip reads (example for Turnouts) "Turnouts not shown cannot be used in this context.", but a better tool tip (example for Signal Heads when creating a Signal Mast) may be "Signal Heads not shown are assigned to another Signal Mast."

To change the tool tip text shown when an existing bean is not selected, this class should be subclassed and the methods getBeanInUseMessage(java.lang.String, java.lang.String), getInvalidNameFormatMessage(java.lang.String, java.lang.String, java.lang.String), getNoMatchingBeanMessage(java.lang.String, java.lang.String), and getWillCreateBeanMessage(java.lang.String, java.lang.String) should be overridden.

See Also:
Serialized Form