Class PrefixSelectionFeature<T extends javafx.scene.control.Control>

  • Type Parameters:
    T - the control type

    public class PrefixSelectionFeature<T extends javafx.scene.control.Control>
    extends java.lang.Object
    Select items according to a prefix.
    Useful for ComboBox and ChoiceBox but can be applied to any control providing a list of items that can be selected.
    Author:
    harald
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.function.BooleanSupplier asYouTypeCondition  
      protected T control  
      static java.lang.String ENABLED
      To disable this feature, invoke:
      protected java.util.function.Supplier<javafx.util.StringConverter> itemConverter  
      protected java.util.function.Supplier<java.util.Collection> itemProvider  
      protected java.lang.StringBuilder prefixBuf  
      protected java.util.function.Consumer<java.lang.Integer> selector  
    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixSelectionFeature​(T control, java.util.function.BooleanSupplier asYouTypeCondition, java.util.function.Supplier<java.util.Collection> itemProvider, java.util.function.Supplier<javafx.util.StringConverter> itemConverter, java.util.function.Consumer<java.lang.Integer> selector)
      Creates a prefix selection feature.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void configure()
      Configures the control to support this feature.
      protected javafx.event.EventHandler<javafx.scene.input.KeyEvent> createHandler()
      Creates the handler to catch the key events.
      protected java.lang.String getPrefix()
      Gets the prefix string to be used for isItemMatching(java.lang.String, java.lang.Object).
      protected boolean isEnabled()
      Returns whether this feature is enabled for the control.
      protected boolean isItemMatching​(java.lang.String prefix, java.lang.Object item)
      Returns whether item is matching prefix string.
      protected boolean isSelectionByKeyEnabled()
      Returns whether selection by key is enabled.
      protected void scrollToIndexInDropDown()
      Scrolls to the selected index in the dropdown.
      protected void select()
      Select an item according to the current prefix.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENABLED

        public static final java.lang.String ENABLED
        To disable this feature, invoke:
          control.getProperties().remove(PrefixSelectionFeature.ENABLED);
         
        See Also:
        Constant Field Values
      • control

        protected final T extends javafx.scene.control.Control control
      • asYouTypeCondition

        protected final java.util.function.BooleanSupplier asYouTypeCondition
      • itemProvider

        protected final java.util.function.Supplier<java.util.Collection> itemProvider
      • itemConverter

        protected final java.util.function.Supplier<javafx.util.StringConverter> itemConverter
      • selector

        protected final java.util.function.Consumer<java.lang.Integer> selector
      • prefixBuf

        protected final java.lang.StringBuilder prefixBuf
    • Constructor Detail

      • PrefixSelectionFeature

        public PrefixSelectionFeature​(T control,
                                      java.util.function.BooleanSupplier asYouTypeCondition,
                                      java.util.function.Supplier<java.util.Collection> itemProvider,
                                      java.util.function.Supplier<javafx.util.StringConverter> itemConverter,
                                      java.util.function.Consumer<java.lang.Integer> selector)
        Creates a prefix selection feature.
        Parameters:
        control - the control to add this feature to
        asYouTypeCondition - the condition to activate preselection by keystrokes
        itemProvider - the items that can be selected
        itemConverter - the item to string converter
        selector - the selector to select an item by its index
    • Method Detail

      • configure

        public void configure()
        Configures the control to support this feature.
      • scrollToIndexInDropDown

        protected void scrollToIndexInDropDown()
        Scrolls to the selected index in the dropdown.
      • createHandler

        protected javafx.event.EventHandler<javafx.scene.input.KeyEvent> createHandler()
        Creates the handler to catch the key events.
        Returns:
        the handler
      • isEnabled

        protected boolean isEnabled()
        Returns whether this feature is enabled for the control.
        Returns:
        true if enabled
      • isSelectionByKeyEnabled

        protected boolean isSelectionByKeyEnabled()
        Returns whether selection by key is enabled.
        Returns:
        true if enabled
      • select

        protected void select()
        Select an item according to the current prefix.
      • isItemMatching

        protected boolean isItemMatching​(java.lang.String prefix,
                                         java.lang.Object item)
        Returns whether item is matching prefix string.
        Parameters:
        prefix - the prefix string
        item - the item
        Returns:
        true if matching