From 3ba6665aa26302d8ee55eb148dbaa95eab32b858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Darri=20Sigur=C3=B0sson?= Date: Fri, 29 Nov 2024 11:38:31 +0000 Subject: [PATCH] ItemComboBoxBuilder.normalize() added --- changelog.md | 1 + .../combobox/DefaultItemComboBoxBuilder.java | 11 ++++++++++- .../ui/component/combobox/ItemComboBoxBuilder.java | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f9c63f6d58..1259c1867a 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ Codion Change Log - Completion.NORMALIZE configuration value added. - Completion.COMBO_BOX_COMPLETION_MODE renamed COMPLETION_MODE. - ComboBoxBuilder.normalize() added. +- ItemComboBoxBuilder.normalize() added. ## 0.18.21 ### is.codion.common.db diff --git a/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/DefaultItemComboBoxBuilder.java b/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/DefaultItemComboBoxBuilder.java index fbc38b0e88..9cc1d8aa36 100644 --- a/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/DefaultItemComboBoxBuilder.java +++ b/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/DefaultItemComboBoxBuilder.java @@ -50,6 +50,7 @@ final class DefaultItemComboBoxBuilder extends AbstractComponentBuilder completionMode(Completion.Mode completionMode) { return this; } + @Override + public ItemComboBoxBuilder normalize(Completion.Normalize normalize) { + this.normalize = requireNonNull(normalize); + return this; + } + @Override public ItemComboBoxBuilder mouseWheelScrolling(boolean mouseWheelScrolling) { this.mouseWheelScrolling = mouseWheelScrolling; @@ -153,7 +160,9 @@ public ItemComboBoxBuilder itemListener(ItemListener itemListener) { protected JComboBox> createComponent() { FilterComboBoxModel> itemComboBoxModel = comboBoxModel == null ? createItemComboBoxModel() : comboBoxModel; JComboBox> comboBox = new FocusableComboBox<>(itemComboBoxModel); - Completion.enable(comboBox, completionMode); + if (editor == null) { + Completion.enable(comboBox, completionMode, normalize); + } if (renderer != null) { comboBox.setRenderer(renderer); } diff --git a/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/ItemComboBoxBuilder.java b/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/ItemComboBoxBuilder.java index 509852dc11..abe14b83da 100644 --- a/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/ItemComboBoxBuilder.java +++ b/swing/common-ui/src/main/java/is/codion/swing/common/ui/component/combobox/ItemComboBoxBuilder.java @@ -63,6 +63,14 @@ public interface ItemComboBoxBuilder extends ComponentBuilder completionMode(Completion.Mode completionMode); + /** + * Specifies whether to normalize strings during auto completion + * @param normalize true if strings should be normalized during autocomplete + * @return this builder instance + * @see #completionMode(Completion.Mode) + */ + ItemComboBoxBuilder normalize(Completion.Normalize normalize); + /** * Enable mouse wheel scrolling on the combo box * @param mouseWheelScrolling true if mouse wheel scrolling should be enabled