1 package be
.nikiroo
.utils
.ui
;
3 import java
.awt
.Component
;
4 import java
.util
.Locale
;
6 import javax
.swing
.DefaultListCellRenderer
;
7 import javax
.swing
.JComboBox
;
8 import javax
.swing
.JComponent
;
9 import javax
.swing
.JList
;
11 import be
.nikiroo
.utils
.resources
.MetaInfo
;
13 class ConfigItemLocale
<E
extends Enum
<E
>> extends ConfigItemCombobox
<E
> {
14 private static final long serialVersionUID
= 1L;
17 * Create a new {@link ConfigItemLocale} for the given {@link MetaInfo}.
20 * the {@link MetaInfo}
22 public ConfigItemLocale(MetaInfo
<E
> info
) {
26 // rawtypes for Java 1.6 (and 1.7 ?) support
27 @SuppressWarnings({ "unchecked", "rawtypes" })
29 protected JComponent
createField(int item
) {
30 JComboBox field
= (JComboBox
) super.createField(item
);
31 field
.setRenderer(new DefaultListCellRenderer() {
32 private static final long serialVersionUID
= 1L;
35 public Component
getListCellRendererComponent(JList
<?
> list
,
36 Object value
, int index
, boolean isSelected
,
37 boolean cellHasFocus
) {
39 String svalue
= value
== null ?
"" : value
.toString();
40 String
[] tab
= svalue
.split("-");
42 if (tab
.length
== 1) {
43 locale
= new Locale(tab
[0]);
44 } else if (tab
.length
== 2) {
45 locale
= new Locale(tab
[0], tab
[1]);
46 } else if (tab
.length
== 3) {
47 locale
= new Locale(tab
[0], tab
[1], tab
[2]);
50 String displayValue
= svalue
;
52 displayValue
= locale
.getDisplayName();
55 return super.getListCellRendererComponent(list
, displayValue
,
56 index
, isSelected
, cellHasFocus
);