fixit
[nikiroo-utils.git] / src / be / nikiroo / utils / ui / ConfigItemLocale.java
CommitLineData
0f7de31e
NR
1package be.nikiroo.utils.ui;
2
3import java.awt.Component;
4import java.util.Locale;
5
6import javax.swing.DefaultListCellRenderer;
7import javax.swing.JComboBox;
8import javax.swing.JComponent;
9import javax.swing.JList;
10
11import be.nikiroo.utils.resources.MetaInfo;
12
13class ConfigItemLocale<E extends Enum<E>> extends ConfigItemCombobox<E> {
14 private static final long serialVersionUID = 1L;
15
16 /**
17 * Create a new {@link ConfigItemLocale} for the given {@link MetaInfo}.
18 *
19 * @param info
20 * the {@link MetaInfo}
21 */
22 public ConfigItemLocale(MetaInfo<E> info) {
23 super(info, true);
24 }
25
26 // rawtypes for Java 1.6 (and 1.7 ?) support
27 @SuppressWarnings({ "unchecked", "rawtypes" })
28 @Override
a0376372
NR
29 protected JComponent createEmptyField(int item) {
30 JComboBox field = (JComboBox) super.createEmptyField(item);
0f7de31e
NR
31 field.setRenderer(new DefaultListCellRenderer() {
32 private static final long serialVersionUID = 1L;
33
34 @Override
1b5197ed 35 public Component getListCellRendererComponent(JList list,
0f7de31e
NR
36 Object value, int index, boolean isSelected,
37 boolean cellHasFocus) {
38
39 String svalue = value == null ? "" : value.toString();
40 String[] tab = svalue.split("-");
41 Locale locale = null;
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]);
48 }
49
50 String displayValue = svalue;
51 if (locale != null) {
52 displayValue = locale.getDisplayName();
53 }
54
55 return super.getListCellRendererComponent(list, displayValue,
56 index, isSelected, cellHasFocus);
57 }
58 });
59
60 return field;
61 }
62}