X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemLocale.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemLocale.java;h=eef8da0836292df9d52409eee55ecc1915d2c72d;hp=0000000000000000000000000000000000000000;hb=d46b7b96f94e88a776bcd2dfd756549ffb300cc9;hpb=c9994f27667bc421bcd448d39e55774fddf5c431 diff --git a/src/be/nikiroo/utils/ui/ConfigItemLocale.java b/src/be/nikiroo/utils/ui/ConfigItemLocale.java new file mode 100644 index 0000000..eef8da0 --- /dev/null +++ b/src/be/nikiroo/utils/ui/ConfigItemLocale.java @@ -0,0 +1,62 @@ +package be.nikiroo.utils.ui; + +import java.awt.Component; +import java.util.Locale; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JList; + +import be.nikiroo.utils.resources.MetaInfo; + +class ConfigItemLocale> extends ConfigItemCombobox { + private static final long serialVersionUID = 1L; + + /** + * Create a new {@link ConfigItemLocale} for the given {@link MetaInfo}. + * + * @param info + * the {@link MetaInfo} + */ + public ConfigItemLocale(MetaInfo info) { + super(info, true); + } + + // rawtypes for Java 1.6 (and 1.7 ?) support + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected JComponent createEmptyField(int item) { + JComboBox field = (JComboBox) super.createEmptyField(item); + field.setRenderer(new DefaultListCellRenderer() { + private static final long serialVersionUID = 1L; + + @Override + public Component getListCellRendererComponent(JList list, + Object value, int index, boolean isSelected, + boolean cellHasFocus) { + + String svalue = value == null ? "" : value.toString(); + String[] tab = svalue.split("-"); + Locale locale = null; + if (tab.length == 1) { + locale = new Locale(tab[0]); + } else if (tab.length == 2) { + locale = new Locale(tab[0], tab[1]); + } else if (tab.length == 3) { + locale = new Locale(tab[0], tab[1], tab[2]); + } + + String displayValue = svalue; + if (locale != null) { + displayValue = locale.getDisplayName(); + } + + return super.getListCellRendererComponent(list, displayValue, + index, isSelected, cellHasFocus); + } + }); + + return field; + } +}