private Font supportedLanguageFont;
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) {
Locale locale = (Locale)value;
String displayedValue = locale.getDisplayLanguage(locale);
if (FurnitureLibrary.DEFAULT_LANGUAGE.equals(displayedValue)) {
displayedValue = preferences.getLocalizedString(FurnitureLanguageComboBox.class, "defaultLanguage");
} else {
displayedValue = Character.toUpperCase(displayedValue.charAt(0)) + displayedValue.substring(1);
if (locale.getCountry().length() > 0) {
displayedValue += " - " + locale.getDisplayCountry(locale);
}
}
super.getListCellRendererComponent(list, displayedValue, index, isSelected,
cellHasFocus);
// Initialize fonts if not done
if (this.defaultFont == null) {
this.defaultFont = getFont();
this.supportedLanguageFont =
new Font(this.defaultFont.getFontName(), Font.BOLD, this.defaultFont.getSize());
}
setFont(library.getSupportedLanguages().contains(locale.toString())
? supportedLanguageFont : defaultFont);
return this;
}
});
final PropertyChangeListener furnitureLanguageChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
String furnitureLangauge = controller.getFurnitureLangauge();
int underscoreIndex = furnitureLangauge.indexOf('_');
if (underscoreIndex != -1) {
setSelectedItem(new Locale(furnitureLangauge.substring(0, underscoreIndex),
furnitureLangauge.substring(underscoreIndex + 1)));
} else {
setSelectedItem(new Locale(furnitureLangauge));
}
}
};
controller.addPropertyChangeListener(FurnitureLanguageController.Property.FURNITURE_LANGUAGE,
furnitureLanguageChangeListener);