Package snap.view

Class ComboBox<T>

All Implemented Interfaces:
PropChange.DoChange, Selectable<T>, XMLArchiver.Archivable

public class ComboBox<T> extends ParentView implements Selectable<T>
A View that combines a TextField, Button and List to allow selection of list items in the space of a TextField and/or button. The default form just shows a button that triggers a popup list. The ShowTextField option adds a TextField for editing. This form can also be attached to any ListView to conveniently find items in a long list.
  • Constructor Details

    • ComboBox

      public ComboBox()
      Constructor.
  • Method Details

    • getItemTextFunction

      public Function<T,String> getItemTextFunction()
      Returns function for deteriming text for an item.
    • setItemTextFunction

      public void setItemTextFunction(Function<T,String> aFunc)
      Sets function for deteriming text for an item.
    • getCellConfigure

      public Consumer<ListCell<T>> getCellConfigure()
      Returns method to configure list cells.
    • setCellConfigure

      public void setCellConfigure(Consumer<ListCell<T>> aCC)
      Sets method to configure list cells.
    • getTextField

      public TextField getTextField()
      Returns the TextField.
    • getButton

      public Button getButton()
      Returns the button.
    • getListView

      public ListView<T> getListView()
      Returns the ListView.
    • setListView

      public void setListView(ListView<T> aListView)
      Sets the ListView.
    • createListView

      protected ListView<T> createListView()
      Creates a ListView for this ComboBox (PopupList by default).
    • isShowTextField

      public boolean isShowTextField()
      Returns whether to show TextField.
    • setShowTextField

      public void setShowTextField(boolean aValue)
      Sets whether to show TextField.
    • isShowButton

      public boolean isShowButton()
      Returns whether to show button.
    • setShowButton

      public void setShowButton(boolean aValue)
      Sets whether to show button.
    • isFilterList

      public boolean isFilterList()
      Returns Whether text entered in TextField should filter ListView items.
    • setFilterList

      public void setFilterList(boolean aValue)
      Returns Whether text entered in TextField should filter ListView items.
    • getPrefixFunction

      public Function<String,List<T>> getPrefixFunction()
      Returns the function to return filtered items from a prefix
    • setPrefixFunction

      public void setPrefixFunction(Function<String,List<T>> aFunc)
      Sets the function to return filtered items from a prefix
    • comboChanged

      protected void comboChanged()
      Called when Button/TextField changes.
    • isPopup

      public boolean isPopup()
      Returns whether ComboBox shows a PopupList.
    • isPopupShowing

      public boolean isPopupShowing()
      Returns whether ComboBox popup is showing on screen.
    • getPopupList

      public PopupList<T> getPopupList()
      Returns ComboBox PopupList.
    • showPopup

      public void showPopup()
      Makes combobox popup visible.
    • getItemCount

      public int getItemCount()
      Returns the number of items.
    • getItem

      public T getItem(int anIndex)
      Returns the individual item at given index.
    • getItemsList

      public List<T> getItemsList()
      Returns the items.
      Specified by:
      getItemsList in interface Selectable<T>
    • setItemsList

      public void setItemsList(List<T> theItems)
      Sets the items.
      Specified by:
      setItemsList in interface Selectable<T>
    • setItems

      public void setItems(T[] theItems)
      Sets the items.
      Specified by:
      setItems in interface Selectable<T>
    • getSelIndex

      public int getSelIndex()
      Returns the selected index.
      Specified by:
      getSelIndex in interface Selectable<T>
    • setSelIndex

      public void setSelIndex(int anIndex)
      Sets the selected index.
      Specified by:
      setSelIndex in interface Selectable<T>
    • getSelItem

      public T getSelItem()
      Returns the selected item.
      Specified by:
      getSelItem in interface Selectable<T>
    • setSelItem

      public void setSelItem(T anItem)
      Sets the selected index.
      Specified by:
      setSelItem in interface Selectable<T>
    • getText

      public String getText()
      Return combo box text.
      Overrides:
      getText in class View
    • setText

      public void setText(String aString)
      Set combo box text.
      Overrides:
      setText in class View
    • getText

      public String getText(T anItem)
      Returns text for item.
    • textFieldFocusChanged

      protected void textFieldFocusChanged()
      Called when TextField focus changed.
    • textFieldKeyPressed

      protected void textFieldKeyPressed(ViewEvent anEvent)
      Called before TextField has KeyPress.
    • textFieldKeyTyped

      protected void textFieldKeyTyped(ViewEvent anEvent)
      Called after TextField has KeyType.
    • getItemsForPrefix

      protected List<T> getItemsForPrefix(String aStr)
      Called to return items for prefix.
    • textFieldFiredAction

      protected void textFieldFiredAction()
      Called when TextField fires action.
    • listViewFiredAction

      protected void listViewFiredAction()
      Called when ListView fires action.
    • listViewSelectionChanged

      protected void listViewSelectionChanged()
      Called when referenced PopupList selection changes.
    • setAlign

      public void setAlign(Pos aPos)
      Override to send to text/button.
      Overrides:
      setAlign in class View
    • setDisabled

      public void setDisabled(boolean aValue)
      Override to send to button.
      Overrides:
      setDisabled in class View
    • getValuePropName

      public String getValuePropName()
      Returns Value property name.
      Overrides:
      getValuePropName in class View
    • getPrefWidthImpl

      protected double getPrefWidthImpl(double aH)
      Returns the preferred width.
      Overrides:
      getPrefWidthImpl in class View
    • getPrefHeightImpl

      protected double getPrefHeightImpl(double aW)
      Returns the preferred height.
      Overrides:
      getPrefHeightImpl in class View
    • layoutImpl

      protected void layoutImpl()
      Layout children.
      Overrides:
      layoutImpl in class ParentView
    • requestFocus

      public void requestFocus()
      Override to focus text or button.
      Overrides:
      requestFocus in class View
    • toXMLView

      public XMLElement toXMLView(XMLArchiver anArchiver)
      XML archival.
      Overrides:
      toXMLView in class ParentView
    • fromXMLView

      public void fromXMLView(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Overrides:
      fromXMLView in class ParentView
    • getArrowImage

      public static Image getArrowImage()
      Returns an Icon of a down arrow.