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

java.lang.Object
org.tentackle.fx.component.config.PrefixSelectionFeature<T>
Type Parameters:
T - the control type

public class PrefixSelectionFeature<T extends javafx.scene.control.Control> extends 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.
The prefix selection is case-sensitive, if the first typed character is uppercase.
Author:
harald
  • Field Details

    • ENABLED

      public static final String ENABLED
      To disable this feature, invoke:
        control.getProperties().remove(PrefixSelectionFeature.ENABLED);
       
      See Also:
    • CAMEL_CASE

      public static final String CAMEL_CASE
      To enable camel case preselection, invoke:
         control.getProperties().put(PrefixSelectionFeature.ENABLED, PrefixSelectionFeature.CAMEL_CASE);
       
      See Also:
    • control

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

      protected final BooleanSupplier asYouTypeCondition
    • itemProvider

      protected final Supplier<Collection> itemProvider
    • itemConverter

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

      protected final Consumer<Integer> selector
    • prefixBuf

      protected final StringBuilder prefixBuf
  • Constructor Details

    • PrefixSelectionFeature

      public PrefixSelectionFeature(T control, BooleanSupplier asYouTypeCondition, Supplier<Collection> itemProvider, Supplier<javafx.util.StringConverter> itemConverter, Consumer<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 Details

    • 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
    • isCamelCaseEnabled

      protected boolean isCamelCaseEnabled()
      Returns whether preselection via camelcase is enabled.
      Returns:
      true if camelcase
    • 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.
    • getPrefix

      protected String getPrefix()
      Gets the prefix string to be used for isItemMatching(java.lang.String, java.lang.Object).
      Returns:
      the prefix string
    • isItemMatching

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