diff --git a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java index adbc4bb..a1d6a4e 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java +++ b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java @@ -43,27 +43,37 @@ public class LocaleComboBox extends ComboBox { private static final String ITEM_FLAG_CLASS_NAME = "fc-locale-combo-box-item-flag"; /** - * Constant for the default display mode. + * Display mode representing the built-in display modes in LocaleComboBox *

- * In this mode, the Locale names are displayed using the default locale's display format. + * These enums can be used in {@link #setDisplayMode(DisplayMode)} to easily switch between the + * built-in display modes. */ - public static final int DISPLAY_DEFAULT = 0; - /** - * Constant for the locale-specific display mode. - *

- * In this mode, the Locale names are displayed using the formatting of the specific locale set by - * {@link #setDisplayLocale(Locale)}. - */ - public static final int DISPLAY_CUSTOM = 1; - /** - * Constant for the selected display mode. - *

- * In this mode, the Locale names are displayed using the formatting of the currently selected - * locale. - */ - public static final int DISPLAY_SELECTED = 2; - - private int displayMode = DISPLAY_DEFAULT; + public enum DisplayMode { + + /** + * Default display mode. + *

+ * In this mode, the Locale names are displayed using the default locale's display format. + */ + DEFAULT, + + /** + * Selected display mode. + *

+ * In this mode, the Locale names are displayed using the formatting of the currently selected + * locale. + */ + SELECTED, + + /** + * Custom display mode. + *

+ * In this mode, the Locale names are displayed using the formatting of the specific locale set + * by {@link #setDisplayLocale(Locale)}. + */ + CUSTOM; + } + private DisplayMode displayMode = DisplayMode.DEFAULT; private Locale customDisplayLocale = Locale.getDefault(); /** @@ -80,29 +90,22 @@ public LocaleComboBox() { /** * Sets the display mode of the LocaleComboBox. - *

- * The display mode determines how the Locale names are presented in the combo box: - *

* - * @param displayMode the display mode to use; must be one of {@link #DISPLAY_DEFAULT}, - * {@link #DISPLAY_CUSTOM}, or {@link #DISPLAY_SELECTED}. + * @param displayMode the display mode to use + * + * @see DisplayMode */ - public void setDisplayMode(int displayMode) { + public void setDisplayMode(DisplayMode displayMode) { this.displayMode = displayMode; } /** - * Sets the locale used for formatting Locale names when {@link #DISPLAY_LOCALE} mode is active. + * Sets the locale used for formatting Locale names when {@link DisplayMode#CUSTOM} mode is + * active. *

- * This locale determines how Locale names are formatted when {@link #DISPLAY_LOCALE} is selected - * as the display mode. If the display mode is {@link #DISPLAY_DEFAULT}, this setting is ignored. + * This locale determines how Locale names are formatted when {@link DisplayMode#CUSTOM} is + * selected as the display mode. If the display mode is any other than {@link DisplayMode#CUSTOM}, + * this setting is ignored. * * @param displayLocale the locale to use for formatting. */ @@ -129,10 +132,10 @@ private Locale getLocaleForDisplay() { switch (displayMode) { - case DISPLAY_CUSTOM: + case CUSTOM: return customDisplayLocale; - case DISPLAY_SELECTED: + case SELECTED: return this.getValue() == null ? Locale.getDefault() : this.getValue(); default: diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java index fcdf70b..b8877e9 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java @@ -46,10 +46,10 @@ public LocaleComboBoxDemo() { defaultDisplayLocale.setValue(Locale.ITALY); koreanLocaleCombo.setDisplayLocale(Locale.KOREA); - koreanLocaleCombo.setDisplayMode(LocaleComboBox.DISPLAY_CUSTOM); + koreanLocaleCombo.setDisplayMode(LocaleComboBox.DisplayMode.CUSTOM); koreanLocaleCombo.setValue(Locale.ITALY); - selectedLocaleCombo.setDisplayMode(LocaleComboBox.DISPLAY_SELECTED); + selectedLocaleCombo.setDisplayMode(LocaleComboBox.DisplayMode.SELECTED); selectedLocaleCombo.setValue(Locale.ITALY); // #if vaadin eq 0