|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JComboBox
org.tentackle.ui.FormComboBox
public class FormComboBox
A forms-aware combobox.
Notes:
valueEnteredOnSelect is set to false the valueEntered
event will only be fired on focus lost and not whenever the selection is changed.FormFieldComboBox.
| Nested Class Summary | |
|---|---|
class |
FormComboBox.MultiKeySelectionManager
The standard key selection manager selects the first item that starts with a given character. This MultiKeySelectionManager keeps an internal "lead-string" of possibly more than one char. |
| Nested classes/interfaces inherited from class javax.swing.JComboBox |
|---|
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JComboBox |
|---|
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
FormComboBox()
Creates a FormComboBox with a default data model. |
|
FormComboBox(ComboBoxModel model)
Creates a FormComboBox that takes its items from an
existing ComboBoxModel. |
|
FormComboBox(Object[] items)
Creates a FormComboBox that contains the elements
in the specified array. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(ActionEvent e)
Overridden to do nothing! |
void |
addAllItems(Collection items)
Adds a collection of items to the list of objects. |
void |
addAllItems(Object[] items)
Adds an array of items to the list of objects. |
void |
addItem(Object anObject)
Adds an item to the item list. |
void |
addValueListener(ValueListener listener)
Adds a value listener that implements the binding between this component and the data. |
protected void |
fireActionEvent()
Overridden for the reason of actionEvents not being triggered by setFormValue(). |
void |
fireValueChanged()
Fires all value listeners registered on this component invoking their valueChanged-handler.This method is invoked whenever the data has been changed and that change should be reflected in the view. |
void |
fireValueEntered()
Fires all listeners registered on this component invoking their valueEntered-handler.This method is invoked whenever the user edited the view and that change should be reflected in the data. |
void |
focusGained(FocusEvent e)
Invoked when a component gains the keyboard focus. |
void |
focusLost(FocusEvent e)
Invoked when a component loses the keyboard focus. |
Object[] |
getAllItems()
Gets the current array of items. |
Object |
getFormValue()
Retrieves the value from this component. The method is used to update the data if the view has changed because the user edited it. |
String |
getFormValueText()
Gets the text representation of the current selection. |
String |
getHelpURL()
Gets the online-help URL. |
int |
getItemIndexWithLeadString(String lead,
ComboBoxModel model)
Returns the index of the first/best matching selection according to a string |
long |
getLeadKeyTimeout()
Gets the timeout for multi key selections. |
Window |
getParentWindow()
Gets the parent window of this component. |
ListCellRenderer |
getPopupRenderer()
Gets the popup renderer. |
String |
getToolTipText()
Returns the tooltip string that has been set with setToolTipText. |
void |
invalidateParentInfo()
Invalidates all container-relevant (cached) information for the hierarchy of this component's parents. For optimization purposes. |
boolean |
isAllowDeselect()
Returns the eselect feature for non-editable comboboxes |
boolean |
isCellEditorUsage()
Returns whether this component is used as a cell editor. |
boolean |
isChangeable()
Returns if this component is changeable. |
boolean |
isFireRunning()
Checks whether a fire-method is running. |
boolean |
isFormTraversable()
Returns whether this component is form traversable or not. |
boolean |
isHonourChangeable()
Returns whether this component should honour the changeable-attribute or not. |
boolean |
isMultiKeySelectionManager()
Returns whether multi-key selection is enabled. |
boolean |
isShortLongPopupEnabled()
Returns whether short/long text popup renderer enabled. |
boolean |
isValueAdjusting()
Returns whether currently adjusting the value. |
boolean |
isValueChanged()
Checks whether the contents have been changed since the last savepoint. |
boolean |
isValueEnteredOnSelect()
Returns whether valueEntered is fired on select or focus lost (default). |
void |
prepareFocusLost()
Implemented to do nothing! |
void |
processKeyEvent(KeyEvent e)
Handles KeyEvents, looking for the Tab key. |
void |
removeAllItems()
Removes all items from the item list. |
void |
removeValueListener(ValueListener listener)
Remove a value listener. |
void |
requestFocusLater()
Requests the keyboard focus for this component by appending an event to the end of the event queue. Applications should not use requestFocus() or requestFocusInWindow() unless the order in which the events are processed is unimportant. |
void |
saveValue()
Sets a savepoint for the data of this component. Allows to decide whether the user has changed the data associated with this component or not. |
boolean |
selectWithLeadString(String lead)
Selects the list item that best corresponds to the specified String and returns true, if there is an item corresponding to that lead-string. |
void |
setAllItems(Collection items)
Replaces all items by a collection of objects. |
void |
setAllItems(Object[] items)
Replaces all items by an array of objects. |
void |
setAllowDeselect(boolean allowDeselect)
Deselect feature for non-editable comboboxes |
void |
setCellEditorUsage(boolean flag)
Sets a hint that this component is used as a cell editor. Some components behave differently in tables than in forms, for example. |
void |
setChangeable(boolean changeable)
Set the component to be changeable. This is a unified abstraction and will be translated to setEditable or setEnabled, whatever is appropriate to this component. |
void |
setEditable(boolean editable)
Determines whether the JComboBox field is editable. |
void |
setFireRunning(boolean running)
Sets a component's flag that a fire-method is currently running. Used by the framework to minimize valueChanged/valueEntered processing. |
void |
setFormTraversable(boolean formTraversable)
Sets whether this component is form traversable or not, i.e. |
void |
setFormValue(Object item)
Sets a value in this component. The method is used to update the view if the data has changed. |
void |
setFormValueIndex(int index)
Sets the formvalue by its index. Avoids triggering fireValueEntered if used from application (use instead of setSelectedIndex()) |
boolean |
setFormValueText(String text)
Sets the form value by matching a given text with the objects in the selection list Tries to find the value in the object list according to its String-representation and select it if found. |
void |
setFormWrapWindow(FormWindow parent)
Sets the window that will fire a FormWrapEvent when this
components loses the keyboard focus. |
void |
setHelpURL(String helpURL)
Sets the online-help URL. If a help url is set for this component, a browser will be launched to show that url. |
void |
setHonourChangeable(boolean flag)
Sets whether this component should honour the changeable-attribute or not. The default is true. |
void |
setLeadKeyTimeout(long leadKeyTimeout)
Sets the timeout for multi key selections. |
void |
setMultiKeySelectionManager(boolean flag)
Enables multi-key selection. The default implementation installs the FormComboBox.MultiKeySelectionManager. |
void |
setPopupRenderer(ListCellRenderer aRenderer)
Set the popup renderer. By default, a JComboBox uses the same renderer for rendering the combobox itself (the selected item in the arrowButton). |
void |
setShortLongPopupEnabled(boolean flag)
Enable the special ShortLongText popup renderer.A special popupRenderer is implemented in the tentackle-plaf that supports ShortLongText-objects for a two-column popup-List. |
void |
setValueAdjusting(boolean flag)
sets a flag that we are currently adjusting a value and no fireValueEntered-Events should be triggered |
void |
setValueEnteredOnSelect(boolean flag)
Enables firing a valueEntered-Event *instead* of an actionEvent (avoids registering value- and actionEvent) The default is to fire actionEvents for selection changes and valueEvents for leaving the field (i.e. |
void |
showHelp()
Displays online help for this component. Usually triggered by KeyEvent.VK_F1 or VK_HELP or a button. |
void |
transferFocus()
Transfers the focus to the next component, as though this Component were the focus owner. |
void |
transferFocusBackward()
Transfers the focus to the previous component, as though this Component were the focus owner. |
void |
triggerValueChanged()
Promotes the fact that value changed to all FormContainers this
component is a child of. |
boolean |
wasFocusGainedFromTransfer()
Returns whether the keyboard focus was gained due to FormComponent.transferFocus()
in the opposite component. |
boolean |
wasFocusGainedFromTransferBackward()
Returns whether the keyboard focus was gained due to FormComponent.transferFocusBackward()
in the opposite component. |
boolean |
wasTransferFocus()
Returns whether this component lost the keyboard focus due to FormComponent.transferFocus(). |
boolean |
wasTransferFocusBackward()
Returns whether this component lost the keyboard focus due to FormComponent.transferFocusBackward(). |
boolean |
wasTransferFocusByEnter()
Returns whether this component lost the keyboard focus due to KeyEvent.VK_ENTER. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.tentackle.ui.FormComponent |
|---|
hasFocus |
| Constructor Detail |
|---|
public FormComboBox(ComboBoxModel model)
FormComboBox that takes its items from an
existing ComboBoxModel. Since the
ComboBoxModel is provided, a combo box created using
this constructor does not create a default combo box model and
may impact how the insert, remove and add methods behave.
model - the ComboBoxModel that provides the
displayed list of itemsJComboBox.JComboBox(javax.swing.ComboBoxModel)public FormComboBox(Object[] items)
FormComboBox that contains the elements
in the specified array. By default the first item in the array
(and therefore the data model) becomes selected.
items - an array of objects to insert into the combo boxJComboBox.JComboBox(java.lang.Object[])public FormComboBox()
FormComboBox with a default data model.
The default data model is an empty list of objects.
Use addItem to add items.
JComboBox.JComboBox()| Method Detail |
|---|
public void processKeyEvent(KeyEvent e)
KeyEvents, looking for the Tab key.
If the Tab key is found, the popup window is closed.
Overridden for keyboard shortcuts.
processKeyEvent in class JComboBoxe - the KeyEvent containing the keyboard
key that was pressedKeyEvent,
KeyListener,
KeyboardFocusManager,
DefaultKeyboardFocusManager,
Component.processEvent(java.awt.AWTEvent),
Component.dispatchEvent(java.awt.AWTEvent),
Component.addKeyListener(java.awt.event.KeyListener),
Component.enableEvents(long),
Component.isShowing()public void actionPerformed(ActionEvent e)
Reason: pressing ENTER in editable comboboxes would store the "text" of the editorfield into the selectedItem. We don't need this nonsense because FormComboBoxes are able to distinguish between the text-value and the selected object due the data binding via valueListeners.
actionPerformed in interface ActionListeneractionPerformed in class JComboBoxe - the action eventfireActionEvent()protected void fireActionEvent()
fireActionEvent in class JComboBoxactionPerformed(java.awt.event.ActionEvent)public void setEditable(boolean editable)
JComboBox field is editable.
An editable JComboBox allows the user to type into the
field or selected an item from the list to initialize the field,
after which it can be edited. (The editing affects only the field,
the list item remains intact.) A non editable JComboBox
displays the selected item in the field,
but the selection cannot be modified.
Overridden due to focus handling
setEditable in class JComboBoxeditable - true if combobox is editablepublic boolean setFormValueText(String text)
text - the string to match
public String getFormValueText()
public void setFormValueIndex(int index)
index - the object index, -1 to deselectpublic void addAllItems(Object[] items)
items - the array of items to addpublic void addAllItems(Collection items)
items - the collection of items to addpublic void setAllItems(Object[] items)
items - the array of itemspublic void setAllItems(Collection items)
items - the collection of itemspublic Object[] getAllItems()
public void removeAllItems()
Overridden to turn off annoying actionEvents during updates
removeAllItems in class JComboBoxpublic void addItem(Object anObject)
JComboBox uses a
mutable data model.
Warning: Focus and keyboard navigation problems may arise if you add duplicate String objects. A workaround is to add new objects instead of String objects and make sure that the toString() method is defined. For example:
comboBox.addItem(makeObj("Item 1"));
comboBox.addItem(makeObj("Item 1"));
...
private Object makeObj(final String item) {
return new Object() { public String toString() { return item; } };
}
Overridden to turn off annoying actionEvents during updates
addItem in class JComboBoxanObject - the Object to add to the listMutableComboBoxModelpublic void setValueEnteredOnSelect(boolean flag)
flag - true to fire on select, false only on focus lostpublic boolean isValueEnteredOnSelect()
public void setValueAdjusting(boolean flag)
flag - true if is adjustingpublic boolean isValueAdjusting()
public boolean selectWithLeadString(String lead)
lead - the first chars types by user
public int getItemIndexWithLeadString(String lead,
ComboBoxModel model)
lead - the first chars types by usermodel - the data model
public void setMultiKeySelectionManager(boolean flag)
FormComboBox.MultiKeySelectionManager.
flag - true to enable multi key selection.public boolean isMultiKeySelectionManager()
public long getLeadKeyTimeout()
public void setLeadKeyTimeout(long leadKeyTimeout)
leadKeyTimeout - the timeout in mspublic boolean isAllowDeselect()
public void setAllowDeselect(boolean allowDeselect)
allowDeselect - true if backspace/delete deselects (default), false = ignore keyspublic void setPopupRenderer(ListCellRenderer aRenderer)
Notice that this attribute will only be honoured if one of the tentackle plafs are used.
aRenderer - the popup renderer, null to disablepublic ListCellRenderer getPopupRenderer()
public void setShortLongPopupEnabled(boolean flag)
ShortLongText popup renderer.
flag - true if enable short/long text popup rendererpublic boolean isShortLongPopupEnabled()
public void focusGained(FocusEvent e)
java.awt.event.FocusListener
focusGained in interface FocusListenerpublic void focusLost(FocusEvent e)
java.awt.event.FocusListener
focusLost in interface FocusListenerpublic void requestFocusLater()
FormComponent
requestFocusLater in interface FormComponentpublic void addValueListener(ValueListener listener)
FormComponent
addValueListener in interface FormComponentlistener - the value listener to addpublic void removeValueListener(ValueListener listener)
FormComponent
removeValueListener in interface FormComponentlistener - the value listener to removepublic void fireValueChanged()
FormComponentvalueChanged-handler.
fireValueChanged in interface FormComponentpublic void fireValueEntered()
valueEntered-handler.note: valueEntered will *ONLY* be fired if the last actionEvent did not fire for the same selectedItem (see fireActionEvent)
fireValueEntered in interface FormComponentpublic void setFormValue(Object item)
Notice: this will compare the objects by "equals" as opposed to setSelectedItem()!
setFormValue in interface FormComponentitem - is the object to set, null means deselectpublic Object getFormValue()
Notice: if the combobox is editable the value will be read from the editor field. Otherwise it's read from the selected item.
getFormValue in interface FormComponentpublic void saveValue()
FormComponent
saveValue in interface FormComponentFormComponent.isValueChanged()public boolean isValueChanged()
FormComponent
isValueChanged in interface FormComponentFormComponent.saveValue()public void triggerValueChanged()
FormComponentFormContainers this
component is a child of.
triggerValueChanged in interface FormComponentpublic void setChangeable(boolean changeable)
Translated to enabled.
setChangeable in interface FormComponentchangeable - true the user can edit the data, false if show onlypublic boolean isChangeable()
FormComponent
isChangeable in interface FormComponentpublic void setHonourChangeable(boolean flag)
FormComponent
setHonourChangeable in interface FormComponentflag - true if honour the changeable attribute, false if notpublic boolean isHonourChangeable()
FormComponent
isHonourChangeable in interface FormComponentpublic void setFireRunning(boolean running)
FormComponent
setFireRunning in interface FormComponentrunning - true if some fire-method is runningpublic boolean isFireRunning()
FormComponent
isFireRunning in interface FormComponentpublic void setCellEditorUsage(boolean flag)
FormComponent
setCellEditorUsage in interface FormComponentflag - true if component is a cell editor, false if not.public boolean isCellEditorUsage()
FormComponent
isCellEditorUsage in interface FormComponentpublic void prepareFocusLost()
prepareFocusLost in interface FormComponentpublic void setFormWrapWindow(FormWindow parent)
FormComponentFormWrapEvent when this
components loses the keyboard focus. When fired the reference
to the window is cleared.
setFormWrapWindow in interface FormComponentparent - the window (usually the parent window of this component).public String getHelpURL()
FormComponent
getHelpURL in interface FormComponentpublic void setHelpURL(String helpURL)
FormComponent
setHelpURL in interface FormComponenthelpURL - the help urlFormHelper.openHelpURL(Component)public void showHelp()
FormComponent
showHelp in interface FormComponentpublic Window getParentWindow()
FormComponent
getParentWindow in interface FormComponentpublic void invalidateParentInfo()
FormComponent
invalidateParentInfo in interface FormComponentpublic String getToolTipText()
javax.swing.JComponentsetToolTipText.
getToolTipText in class JComponentJComponent.TOOL_TIP_TEXT_KEYpublic void transferFocus()
java.awt.Component
transferFocus in interface FormComponenttransferFocus in class ComponentComponent.requestFocus()public void transferFocusBackward()
java.awt.Component
transferFocusBackward in interface FormComponenttransferFocusBackward in class ContainerComponent.requestFocus()public boolean wasTransferFocus()
FormComponentFormComponent.transferFocus().
wasTransferFocus in interface FormComponentpublic boolean wasTransferFocusBackward()
FormComponentFormComponent.transferFocusBackward().
wasTransferFocusBackward in interface FormComponentpublic boolean wasFocusGainedFromTransfer()
FormComponentFormComponent.transferFocus()
in the opposite component.
wasFocusGainedFromTransfer in interface FormComponentFormFocusTraversalPolicypublic boolean wasFocusGainedFromTransferBackward()
FormComponentFormComponent.transferFocusBackward()
in the opposite component.
wasFocusGainedFromTransferBackward in interface FormComponentFormFocusTraversalPolicypublic boolean wasTransferFocusByEnter()
FormComponentKeyEvent.VK_ENTER.
wasTransferFocusByEnter in interface FormComponentpublic void setFormTraversable(boolean formTraversable)
FormComponent
setFormTraversable in interface FormComponentformTraversable - true if traversable, false if notpublic boolean isFormTraversable()
FormComponent
isFormTraversable in interface FormComponent
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||