3131
3232/**
3333 * Vaadin ComboBox extension that allows to choose between multiple locales.
34- *
34+ *
3535 * @author Tomas Peiretti / Flowing Code
3636 */
3737@ SuppressWarnings ("serial" )
@@ -46,47 +46,43 @@ public class LocaleComboBox extends ComboBox<Locale> {
4646
4747 /**
4848 * Represents the built-in display modes for locale names in the {@link LocaleComboBox} component.
49- * <p>
50- * These enums can be used in {@link #setDisplayMode(DisplayMode)} to easily switch between the
49+ *
50+ * <p> These enums can be used in {@link #setDisplayMode(DisplayMode)} to easily switch between the
5151 * built-in display modes.
5252 */
5353 public enum DisplayMode {
5454
5555 /**
5656 * Default display mode.
57- * <p>
58- * In this mode, the Locale names are displayed using the default locale's display format.
57+ *
58+ * <p> In this mode, the Locale names are displayed using the default locale's display format.
5959 */
6060 DEFAULT ,
6161
6262 /**
6363 * Selected display mode.
64- * <p>
65- * In this mode, the Locale names are displayed using the formatting of the currently selected
66- * locale.
64+ *
65+ * <p> In this mode, the Locale names are displayed using the formatting of the currently
66+ * selected locale.
6767 */
6868 SELECTED ,
6969
7070 /**
7171 * Custom display mode.
72- * <p>
73- * In this mode, the Locale names are displayed using the formatting of the specific locale set
74- * by {@link #setDisplayLocale(Locale)}.
72+ *
73+ * <p> In this mode, the Locale names are displayed using the formatting of the specific locale
74+ * set by {@link #setDisplayLocale(Locale)}.
7575 */
7676 CUSTOM ;
7777 }
7878
7979 private DisplayMode displayMode = DisplayMode .DEFAULT ;
8080 private Locale customDisplayLocale ;
8181
82- /**
83- * Indicates whether the flags should be displayed alongside the locale names.
84- */
82+ /** Indicates whether the flags should be displayed alongside the locale names. */
8583 private boolean hasFlags = true ;
8684
87- /**
88- * Creates a new instance of {@code LocaleComboBox}.
89- */
85+ /** Creates a new instance of {@code LocaleComboBox}. */
9086 public LocaleComboBox () {
9187 setItemLabelGenerator (item -> item .getDisplayName (getLocaleForDisplay ()));
9288 setRenderer (getLocaleRenderer ());
@@ -95,7 +91,7 @@ public LocaleComboBox() {
9591
9692 /**
9793 * Creates a new instance of {@code LocaleComboBox} with the desired locales
98- *
94+ *
9995 * @param locales the {@code Collection} of {@code Locale} to include in the combobox
10096 */
10197 public LocaleComboBox (Collection <Locale > locales ) {
@@ -105,9 +101,8 @@ public LocaleComboBox(Collection<Locale> locales) {
105101
106102 /**
107103 * Sets the display mode of the LocaleComboBox.
108- *
104+ *
109105 * @param displayMode the display mode to use
110- *
111106 * @see DisplayMode
112107 */
113108 public void setDisplayMode (DisplayMode displayMode ) {
@@ -117,11 +112,11 @@ public void setDisplayMode(DisplayMode displayMode) {
117112 /**
118113 * Sets the locale used for formatting Locale names when {@link DisplayMode#CUSTOM} mode is
119114 * active.
120- * <p>
121- * This locale determines how Locale names are formatted when {@link DisplayMode#CUSTOM} is
115+ *
116+ * <p> This locale determines how Locale names are formatted when {@link DisplayMode#CUSTOM} is
122117 * selected as the display mode. If the display mode is any other than {@link DisplayMode#CUSTOM},
123118 * this setting is ignored.
124- *
119+ *
125120 * @param displayLocale the {@code Locale} to use for formatting.
126121 */
127122 public void setDisplayLocale (Locale displayLocale ) {
@@ -139,10 +134,10 @@ public boolean hasFlags() {
139134
140135 /**
141136 * Sets whether flags should be displayed alongside locale names.
142- * <p>
143- * This method updates the internal state to reflect whether flags should be displayed and updates
144- * the rendering based on the new state.
145- *
137+ *
138+ * <p> This method updates the internal state to reflect whether flags should be displayed and
139+ * updates the rendering based on the new state.
140+ *
146141 * @param hasFlags A {@code boolean} indicating whether flags should be displayed or not.
147142 */
148143 public void setHasFlags (boolean hasFlags ) {
@@ -152,8 +147,7 @@ public void setHasFlags(boolean hasFlags) {
152147 }
153148
154149 private LitRenderer <Locale > getLocaleRenderer () {
155- return LitRenderer
156- .<Locale >of (
150+ return LitRenderer .<Locale >of (
157151 """
158152 <vaadin-horizontal-layout class="${item.layoutClass}">
159153 <span class="fi fi-${item.countryCode} ${item.flagClass} alt="${item.countryName}'s flag"></span>
@@ -167,17 +161,18 @@ private LitRenderer<Locale> getLocaleRenderer() {
167161 }
168162
169163 private LitRenderer <Locale > getLocaleRendererWithoutFlags () {
170- return LitRenderer .<Locale >of ("""
164+ return LitRenderer .<Locale >of (
165+ """
171166 <vaadin-horizontal-layout class="${item.layoutClass}">
172167 <span>${item.displayName}</span>
173- </vaadin-horizontal-layout>""" ).withProperty ("layoutClass" , loc -> ITEM_LAYOUT_CLASS_NAME )
168+ </vaadin-horizontal-layout>""" )
169+ .withProperty ("layoutClass" , loc -> ITEM_LAYOUT_CLASS_NAME )
174170 .withProperty ("displayName" , loc -> loc .getDisplayName (getLocaleForDisplay ()));
175171 }
176172
177173 private Locale getLocaleForDisplay () {
178174
179175 switch (displayMode ) {
180-
181176 case CUSTOM :
182177 return Optional .ofNullable (customDisplayLocale ).orElseGet (this ::getLocale );
183178
@@ -191,7 +186,8 @@ private Locale getLocaleForDisplay() {
191186
192187 private String getFlagCode (Locale locale ) {
193188 String countryCode = locale .getCountry ();
194- return LocaleCountryConverter .convertToISO3166Code (countryCode ).map (String ::toLowerCase )
189+ return LocaleCountryConverter .convertToISO3166Code (countryCode )
190+ .map (String ::toLowerCase )
195191 .orElse (DEFAULT_FLAG_CODE );
196192 }
197193
@@ -215,5 +211,4 @@ private void setPrefixFlag(Locale locale) {
215211 flagIcon .addClassNames ("fi" , "fi-" + this .getFlagCode (locale ));
216212 setPrefixComponent (flagIcon );
217213 }
218-
219214}
0 commit comments