c.gridwidth = 3;
c.weighty = 1.0;
c.weightx = 1.0;
add(Box.createVerticalGlue(), c);
SwingWorker worker = new SwingWorker()
{
I18N i18n;
public Object construct()
{
i18n = new I18N();
return null;
}
//Runs on the event-dispatching thread.
public void finished()
{
cmbLanguage.setModel(new DefaultComboBoxModel(i18n.getLanguages()));
LocaleModel lm = new LocaleModel(i18n);
cmbLanguage.addActionListener(lm);
String languageCode = Preferences.getString("jeti","language",getDefaultLocale().getLanguage());
ComboBoxModel model = cmbLanguage.getModel();
boolean selected=false;
for(int i=0;i<model.getSize();i++)
{
if(((I18N.Language)model.getElementAt(i)).getLanguageCode().equals(languageCode))
{
cmbLanguage.setSelectedIndex(i);
selected=true;
break;
}
}
if(!selected)
{//language not found so set to default language
languageCode = Locale.getDefault().getLanguage();
for(int i=0;i<model.getSize();i++)
{
if(((I18N.Language)model.getElementAt(i)).getLanguageCode().equals(languageCode))
{
cmbLanguage.setSelectedIndex(i);
break;
}
}
}
String countryCode = Preferences.getString("jeti","country",getDefaultLocale().getCountry());
cmbCountry.setModel(lm);
model = cmbCountry.getModel();
selected=false;
for(int i=0;i<model.getSize();i++)
{
if(((I18N.Country)model.getElementAt(i)).getCountryCode().equals(countryCode))
{
cmbCountry.setSelectedIndex(i);
selected=true;
break;
}
}
if(!selected)
{//country not found so set to other
countryCode = "";
for(int i=0;i<model.getSize();i++)
{
if(((I18N.Country)model.getElementAt(i)).getCountryCode().equals(countryCode))
{
cmbCountry.setSelectedIndex(i);
break;
}
}
}
}
};
worker.start();
}