public abstract class ComboBox<O extends OutputManager<?>> extends AbstractWidget<O> implements WidgetWithConfig<ComboBoxConfig>, SelectionListener, FocusListener, ItemListener, DataContainer, LabeledWidget<O>, ControlSetComponent, MnemonicTrait<O>, TextSelection
When the combo-box is in a non-dropped-down state, it looks like a Fill-in with a [V] character on the right. To make the drop-down menu appear, the user positions the cursor over the combo-box and presses DOWN key.
When the user selects an item in the drop-down menu (by positioning the
cursor on it and pressing ENTER), the drop-down menu disappears
and only the selected item is shown. Any use of the END-ERROR
key will cause the drop-down to be closed with no change in the selected
value. Any alphabetic or numeric character will select the next item
that starts with that character. All other keys are ignored.
Note that this class provides a Progress combo-box that matches the
DROP-DOWN-LIST
mode. The SIMPLE
and
DROP-DOWN
modes are not supported.
Widget.ZOrderClass
Modifier and Type | Field and Description |
---|---|
private MnemonicInfo |
columnMnemonic
Column mnemonic information
|
protected ComboBoxConfig |
config
Contains our attributes.
|
protected DropDown<O> |
dropDown
The drop-down list object to select one item from the list.
|
protected boolean |
endConditionRaised
A helper field for drop-down related event handling.
|
private BaseDataType |
initValue
Original value assigned to the widget.
|
private Label<O> |
label
Component label.
|
protected double |
limit
The maximum size of the data portion of the main combo-box.
|
private int |
maxlen
Maximal label length
|
private MnemonicInfo |
mnemonic
Mnemonic information
|
private ComboBoxModel<java.lang.String> |
model
Combo-box model.
|
protected boolean |
selected
Track selection.
|
protected boolean |
valueChanged
Track if a VALUE-CHANGED event needs to be raised.
|
insets, location, LOG, mousePtr, nativeInsets, physicalLocation
Constructor and Description |
---|
ComboBox(WidgetId id,
ComboBoxConfig cfg)
Special constructor used to restore the component using a given
configuration.
|
Modifier and Type | Method and Description |
---|---|
protected void |
activate()
Starts the drop-down part of the life cycle.
|
protected void |
addUISpecificEvents(EventList listToChange)
Adding mouse clicks as exit events.
|
void |
afterConfigUpdate(ComboBoxConfig beforeUpdate)
The method is called after the configuration associated with
the implementor changes.
|
double |
calcLimit(boolean body)
Calculate width limit.
|
void |
changed()
This method is invoked when selection is changed.
|
ComboBoxConfig |
config()
Provide access to the attribute of the widget.
|
java.lang.Runnable |
deactivateCode()
Get drop down deactivation Runnable
|
void |
destroy()
Destroy this widget.
|
Dimension |
dimension()
Get widget dimension.
|
abstract void |
draw()
Draws the combo box as a list item.
|
abstract void |
drawCaret()
Sets position of terminal's cursor to the first char of the combo-box.
|
protected abstract void |
dropDownRequestFocus()
Requesting focus to opened drop-down.
|
void |
exitDropDown()
Exit the drop-down (the "selection" mode of the combo-box).
|
(package private) java.lang.String |
formatValue(java.lang.String selectedItem)
Format source string using current settings and make it suitable for
display.
|
double |
getColon()
Return current value of COLON option.
|
java.lang.String |
getColumnLabelText()
Return text of the column label.
|
MnemonicInfo |
getColumnMnemonic()
Column
MnemonicInfo instance getter. |
Color |
getDColor()
Get DCOLOR attribute.
|
Widget<?> |
getDropDownList()
Get list of the drop-down
|
java.lang.String |
getItemText(java.lang.Object item)
Properly dereference the text of an object, handling Progress data type
formatting if needed.
|
Label<O> |
getLabelInstance()
Return the reference to the instance of the
Label attached
to the widget. |
java.lang.String |
getLabelText()
Return text of the label.
|
int |
getMaxLabelLen()
Calculates the minimum size of the of the combo-box by returning the
largest label width of all elements in the list.
|
MnemonicInfo |
getMnemonic()
MnemonicInfo instance getter.
|
BaseDataType |
getScreenValue()
Get widget screen value.
|
int |
getScrollPaneId()
Get the id of the drop-down scroll pane
|
int[] |
getSelection()
Obtain the list of indexes for all selected items.
|
java.lang.String |
getText()
Get text representation of the currently selected value.
|
double |
getTo()
Return TO column.
|
BaseDataType |
getValue()
Gets the currently selected item.
|
double |
height()
Get widget height.
|
protected java.util.Set<java.lang.String> |
initEventsSet()
Initializes the event set to return.
|
void |
initialize(WidgetId id,
ComboBoxConfig cfg)
Replacement API for the logic which should exist in the widget's c'tor, but the logic
can't be executed as it depends on the widget being registered into the official registry.
|
protected boolean |
isDropDownActive()
Returns
true when drop-down is visible. |
boolean |
isForceLabel()
Get current state of the flag which is forces presence of the label
regardless of the frame's NO-LABELS option.
|
boolean |
isFormatHonored()
Returns true if the format settings are used to format values.
|
boolean |
isModified()
Getting the modification state of the widget.
|
boolean |
isNoLabels()
Get current state of the NO-LABELS flag.
|
boolean |
isRightAligned()
Get widget alignment policy.
|
boolean |
isSelected()
Return
true if a drop-down value has been explicitly selected. |
boolean |
isSimpleMode()
Check if the ComboBox mode is SIMPLE
|
int |
lookup(java.lang.String item)
Returns the index of the item with the specified text.
|
boolean |
manageSystemActions()
Check if the current widget can manage non-global system actions on its own, and not via the
enclosing event loop.
|
Dimension |
minimumSize()
Get widget minimum size.
|
ComboBoxModel<java.lang.String> |
model()
Get underlying model.
|
void |
onFocusGained(FocusEvent event)
This is called when the combo-box gains the input focus.
|
void |
onFocusLost(FocusEvent focusEvent)
This is called when the combo-box loses the input focus.
|
void |
onSelect(ItemEvent itemEvent)
Notifies this component that the state of the combo-box has changed.
|
void |
postprocessConfig()
Additional processing required when widget configuration is updated AFTER the frame layout
has been performed.
|
protected void |
postprocessDropDown()
Sometimes it is required to do several action the was deferred during drop-down life cycle.
|
void |
processEvent(Event event)
Process event and dispatch it to specific method.
|
void |
processKeyEvent(KeyInput keyEvent)
Process key events that have been generated by this component.
|
void |
processSystemKey(KeyInput key)
Process the action associated with the given key in an independent drawing bracket.
|
void |
refreshItems()
Refresh items in the combo-box after assignment.
|
protected abstract void |
registerDropDownFrame()
Registers drop-down frame in current window system.
|
void |
requestFocus()
Obtain the input focus.
|
void |
setColumnMnemonic(MnemonicInfo mnemonic)
Column
MnemonicInfo instance setter. |
void |
setHidden(boolean hidden)
Tracks the hidden state of the widget and attached label.
|
void |
setLabelInstance(Label<O> label)
Assign a new instance of
Label to the widget. |
void |
setMnemonic(MnemonicInfo mnemonic)
MnemonicInfo instance setter.
|
void |
setNoLabels(boolean labels)
Force NO-LABELS flag.
|
void |
setValue(BaseDataType value)
Sets the instance representing the current value.
|
void |
setVisible(boolean visible_)
Shows or hides the combo-box and its label.
|
void |
setWasVisible()
Remember the widget was made visible at least once.
|
protected void |
valueChangedCommon()
Posts value changed event to the queue.
|
void |
valueChangedImpl()
Value changed handler.
|
boolean |
wasVisible()
Checking if the widget was made visible at least once.
|
double |
width()
Get widget width.
|
_setHidden, _setVisible, activateDirectManipulation, addFocusListener, addKeyListener, afterConfigUpdateBase, ancestor, ancestorId, autoResize, bounds, clear, clearWidget, clipRectangle, clipRectangle, clipWith, createMouseHoverAction, deactivateDirectManipulation, debug, disable, displayPhysicalLocation, enable, enclosingFrame, findMouseSource, focusTraversable, forceCursorOnFocus, forceVisibility, getActualBounds, getAndResetBitmap, getAndSetBitmap, getBitmapCopy, getCustomMousePointer, getDefaultEvent, getEffectiveMousePointer, getId, getLoadedMousePointer, getMenuMouse, getMouseActions, getPortableMouseEventCoordinates, getSelectedText, getState, getTextHeight, getTextHeightNative, getTextWidth, getTextWidthNative, getVisiblePart, getZOrderClass, hasFocus, hidden, hide, highlighted, ignoreAction, insets, isDirectManipulationCapable, isDirectManipulationRequired, isDisplayed, isEnabled, isFocusable, isHeader, isRealized, isRMBEntrySupported, isTabStop, isThreeD, isTotallyObscured, isVisible, location, mouseActions, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, moveToBottom, moveToTop, name, navigable, parent, parent, parentOrSelf, physicalBounds, physicalDimension, physicalLocation, prepParentLocation, processDirectManipulationEvent, processFocusEvent, processKeyListeners, processMnemonic, processMnemonicImpl, raiseLegacyMouseEvents, refresh, registerWidgetStateListener, repaint, repaint, requestSync, resetBitmap, resizeTo, resolveFont, resolveTitleFont, screen, screenDimension, screenHeight, screenLocation, screenPhysicalLocation, screenWidth, setBitmap, setEnabled, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, supportsCustomMousePointer, sync, topLevelWindow, toString, translate, unrealize, updateSizeWorker, window
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addFocusListener, addKeyListener, ancestor, ancestorId, bounds, clearWidget, defaultMousePtr, displayPhysicalLocation, enclosingFrame, enforceDefaultMousePtr, findMouseSource, focusTraversable, forceCursorOnFocus, forceVisibility, getActualBounds, getCustomMousePointer, getEffectiveMousePointer, getId, getLegacyWidget, getLoadedMousePointer, getMenuMouse, getMouseActions, getSelectedText, getState, getVisiblePart, getZOrderClass, hasFocus, hidden, hide, highlighted, insets, isDirectManipulable, isDisplayed, isEnabled, isFocusable, isHeader, isRealized, isRMBEntrySupported, isTabStop, isThreeD, isTotallyObscured, isVisible, location, moveToBottom, moveToTop, name, navigable, parent, parent, parentOrSelf, physicalBounds, physicalDimension, physicalLocation, processDirectManipulationEvent, processFocusEvent, processKeyListeners, processMnemonic, raiseLegacyMouseEvents, repaint, repaint, requestSync, resizeTo, screen, screenLocation, screenPhysicalLocation, setEnabled, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, supportsCustomMousePointer, topLevelWindow, unrealize, window
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased
createMnemonic, getMnemonicCharacter, getMnemonicKeyCode, getMnemonicLabel, isMnemonicSupported, updateMnemonic
invalidateSelection, isSelectionValid, removeSelectedText, setSelection
protected ComboBoxConfig config
protected DropDown<O extends OutputManager<?>> dropDown
protected double limit
protected boolean valueChanged
protected boolean endConditionRaised
private Label<O extends OutputManager<?>> label
private int maxlen
private BaseDataType initValue
protected boolean selected
private ComboBoxModel<java.lang.String> model
private MnemonicInfo mnemonic
private MnemonicInfo columnMnemonic
public ComboBox(WidgetId id, ComboBoxConfig cfg)
Call initialize(com.goldencode.p2j.ui.WidgetId, com.goldencode.p2j.ui.ComboBoxConfig)
to finish the widget initialization.
id
- The widget's ID.cfg
- Configuration data.public void initialize(WidgetId id, ComboBoxConfig cfg)
This API is called after the widget is created and added to the registry.
initialize
in interface WidgetWithConfig<ComboBoxConfig>
id
- The widget's ID.cfg
- The config used to initialize this widget.public abstract void draw()
draw
in interface Widget<O extends OutputManager<?>>
draw
in class AbstractWidget<O extends OutputManager<?>>
public abstract void drawCaret()
drawCaret
in interface Widget<O extends OutputManager<?>>
drawCaret
in class AbstractWidget<O extends OutputManager<?>>
public boolean isSimpleMode()
true
if the ComboBox mode is SIMPLEjava.lang.String formatValue(java.lang.String selectedItem)
There are 2 formatting modes:
1. Item List - this is used when the list being represented is a simple list of values rather than a set of label + value pairs, in this case the explicit format string (or the default format) will be used to format the label text for display in both the drop-down box and in the main field 2. Item Pair - used when the list is representing label/value pairs, in this case the entire text of the label will be returned (padded on the right to reach the same length as the largest of the labels)
If the honor format
flag is true
then the
widget is in "item list" mode.
selectedItem
- The source string to format.public ComboBoxConfig config()
config
in interface Widget<O extends OutputManager<?>>
config
in interface ConfigOwner<ComboBoxConfig>
config
in class AbstractWidget<O extends OutputManager<?>>
public void afterConfigUpdate(ComboBoxConfig beforeUpdate)
afterConfigUpdate
in interface ConfigOwner<ComboBoxConfig>
beforeUpdate
- Config reference capturing the config state before
the owner's config was modified.public void onSelect(ItemEvent itemEvent)
onSelect
in interface ItemListener
itemEvent
- The item related event to handle.public int lookup(java.lang.String item)
item
- The string entry whose index must be returned.public void processKeyEvent(KeyInput keyEvent)
processKeyEvent
in interface Widget<O extends OutputManager<?>>
processKeyEvent
in class AbstractWidget<O extends OutputManager<?>>
keyEvent
- The key event to be handled.public void requestFocus()
requestFocus
in interface Widget<O extends OutputManager<?>>
requestFocus
in class AbstractWidget<O extends OutputManager<?>>
public boolean isSelected()
true
if a drop-down value has been explicitly selected.selected
flag.public BaseDataType getValue()
getValue
in interface DataContainer
public void setValue(BaseDataType value)
setValue
in interface DataContainer
value
- The value representing the current widget value.public java.lang.String getText()
getText
in interface DataContainer
null
if no value is selected.public boolean isModified()
isModified
in interface DataContainer
true
if the widget value was modified,
false
otherwise.public void changed()
changed
in interface SelectionListener
public void valueChangedImpl()
public Dimension dimension()
dimension
in interface Widget<O extends OutputManager<?>>
dimension
in class AbstractWidget<O extends OutputManager<?>>
public double width()
AbstractWidget
width
in interface Widget<O extends OutputManager<?>>
width
in class AbstractWidget<O extends OutputManager<?>>
Widget.width()
public double height()
AbstractWidget
height
in interface Widget<O extends OutputManager<?>>
height
in class AbstractWidget<O extends OutputManager<?>>
Widget.height()
public java.lang.String getItemText(java.lang.Object item)
item
- The instance to be rendered as text.public void refreshItems()
refreshItems
in interface ControlSetComponent
public int[] getSelection()
Multiple selection mode is not supported in this class, so the returned array will always have a single element.
getSelection
in interface ControlSetComponent
null
but a
valid array will always be returned.public void onFocusGained(FocusEvent event)
onFocusGained
in interface FocusListener
event
- The focus event to be processed.public void onFocusLost(FocusEvent focusEvent)
onFocusLost
in interface FocusListener
focusEvent
- The focus event to be processed.public Label<O> getLabelInstance()
Label
attached
to the widget.getLabelInstance
in interface LabeledWidget<O extends OutputManager<?>>
Label
instance.public void setLabelInstance(Label<O> label)
Label
to the widget.setLabelInstance
in interface LabeledWidget<O extends OutputManager<?>>
label
- Reference to the new Label
instance.public java.lang.String getLabelText()
getLabelText
in interface LabeledWidget<O extends OutputManager<?>>
public java.lang.String getColumnLabelText()
getColumnLabelText
in interface LabeledWidget<O extends OutputManager<?>>
public double getTo()
getTo
in interface LabeledWidget<O extends OutputManager<?>>
public boolean isForceLabel()
isForceLabel
in interface LabeledWidget<O extends OutputManager<?>>
public boolean isNoLabels()
isNoLabels
in interface LabeledWidget<O extends OutputManager<?>>
public void setNoLabels(boolean labels)
setNoLabels
in interface LabeledWidget<O extends OutputManager<?>>
labels
- The new value of the flag.public double getColon()
getColon
in interface LabeledWidget<O extends OutputManager<?>>
public boolean isRightAligned()
isRightAligned
in interface LabeledWidget<O extends OutputManager<?>>
true
if the widget is formatted for right
alignment.public int getMaxLabelLen()
public void setVisible(boolean visible_)
setVisible
in interface Widget<O extends OutputManager<?>>
setVisible
in class AbstractWidget<O extends OutputManager<?>>
visible_
- true
to make the widget visible,
false
to hide the widget.public void setHidden(boolean hidden)
setHidden
in interface Widget<O extends OutputManager<?>>
setHidden
in class AbstractWidget<O extends OutputManager<?>>
hidden
- New hidden state.public Color getDColor()
protected void valueChangedCommon()
public void exitDropDown()
public Widget<?> getDropDownList()
protected void activate()
public java.lang.Runnable deactivateCode()
protected void postprocessDropDown()
protected abstract void registerDropDownFrame()
protected abstract void dropDownRequestFocus()
protected java.util.Set<java.lang.String> initEventsSet()
protected void addUISpecificEvents(EventList listToChange)
listToChange
- The event list to modify.public double calcLimit(boolean body)
This method is ChUI specific, do not call from GUI code.
body
- Perform calculation for body part of widget.public BaseDataType getScreenValue()
public Dimension minimumSize()
minimumSize
in interface Widget<O extends OutputManager<?>>
minimumSize
in class AbstractWidget<O extends OutputManager<?>>
public ComboBoxModel<java.lang.String> model()
public void processEvent(Event event)
processEvent
in interface Widget<O extends OutputManager<?>>
processEvent
in class AbstractWidget<O extends OutputManager<?>>
event
- Event to process.public boolean wasVisible()
wasVisible
in interface LabeledWidget<O extends OutputManager<?>>
true
if the widget was visible,
false
otherwise.public void setWasVisible()
setWasVisible
in interface LabeledWidget<O extends OutputManager<?>>
public boolean manageSystemActions()
manageSystemActions
in class AbstractWidget<O extends OutputManager<?>>
true
as the widget has its own event management.public void processSystemKey(KeyInput key)
This must be called only in the context of widget-level event processing.
processSystemKey
in class AbstractWidget<O extends OutputManager<?>>
key
- The key to be processed.public void postprocessConfig()
postprocessConfig
in interface Widget<O extends OutputManager<?>>
postprocessConfig
in class AbstractWidget<O extends OutputManager<?>>
public void destroy()
destroy
in interface Widget<O extends OutputManager<?>>
destroy
in class AbstractWidget<O extends OutputManager<?>>
public int getScrollPaneId()
public MnemonicInfo getMnemonic()
The implementors should simply return the value of the mnemonic class field. No additional processing logic is advised.
getMnemonic
in interface MnemonicTrait<O extends OutputManager<?>>
public void setMnemonic(MnemonicInfo mnemonic)
The implementors should simply assign the parameter value to the mnemonic class field. No additional processing logic is advised.
setMnemonic
in interface MnemonicTrait<O extends OutputManager<?>>
public MnemonicInfo getColumnMnemonic()
MnemonicInfo
instance getter.
The implementors should simply return the value of the mnemonic class field. No additional processing logic in the implemented method is advised.
The method will return a valid value when the implementing widget supports column label.
getColumnMnemonic
in interface MnemonicTrait<O extends OutputManager<?>>
public void setColumnMnemonic(MnemonicInfo mnemonic)
MnemonicInfo
instance setter.
The implementors should simply assign the parameter value to the mnemonic class field. No additional processing logic in the implemented method is advised.
setColumnMnemonic
in interface MnemonicTrait<O extends OutputManager<?>>
protected boolean isDropDownActive()
true
when drop-down is visible.public boolean isFormatHonored()