/*
* Created on 7 mai 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package jsynoptic.installer;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.event.ChangeEvent;
import simtools.ui.ActionRadioButton;
import simtools.ui.CustomizedLocale;
import simtools.ui.ResourceFinder;
class LangPanel extends InstallerPanel {
public LangPanel(Installer installer) {
super(installer);
setLayout(new BorderLayout());
setBorder(BorderFactory.createTitledBorder(Installer.resources.getString("welcome")));
final ArrayList resList = new ArrayList();
final ArrayList locList = new ArrayList();
Locale defaultLocale = CustomizedLocale.get();
// Loop on all known locales => this string shall be present in all locales,
// including default one => just changing localization files is OK to add a new one,
// no need to change the code
StringTokenizer st = new StringTokenizer(Installer.resources.getString("knownLocales"), "\t ,;");
int numLocales = 0;
while (st.hasMoreTokens()) {
String code = st.nextToken();
// get the locales and associated resources one by one
Locale l = new Locale(code);
CustomizedLocale.set(l);
ResourceBundle r = ResourceFinder.get(Installer.class);
// put default locale first, all other after, in order
if ((defaultLocale.getVariant().equals("") && defaultLocale.getCountry().equals("") && defaultLocale.getLanguage().equals(l.getLanguage()))
|| (defaultLocale.getVariant().equals("") && (!defaultLocale.getCountry().equals("")) && defaultLocale.getLanguage().equals(l.getLanguage()) && defaultLocale.getCountry().equals(l.getCountry()))
|| defaultLocale.equals(l)) {
locList.add(0,l);
resList.add(0,r);
} else {
locList.add(l);
resList.add(r);
}
numLocales++;
}
// reset to default locale, just in case
CustomizedLocale.set(defaultLocale);
ButtonGroup bg = new ButtonGroup();
Box vbox = Box.createVerticalBox();
vbox.add(Box.createVerticalGlue());
// Add UI elements in localisation order
for (int i=0; i<numLocales; ++i) {
final ResourceBundle res = (ResourceBundle)resList.get(i);
final int counter = i;
// first one is true as this is the default locale
ActionRadioButton arb = new ActionRadioButton(res.getString("chooseThisLanguage"),i==0) {
public void stateChanged(ChangeEvent e) {
if (isSelected()) {
Installer.resources = res;
Locale l = (Locale)locList.get(counter);
CustomizedLocale.set(l);
LangPanel.this.update();
}
}
};
bg.add(arb);
Box hbox = Box.createHorizontalBox();
hbox.add(arb);
hbox.add(Box.createHorizontalGlue());
vbox.add(hbox);
arb.apply();
}
vbox.add(Box.createVerticalGlue());
add(vbox,BorderLayout.CENTER);
// That's all!
}
public void update() {
installer.next.setText(Installer.resources.getString("next"));
installer.cancel.setText(Installer.resources.getString("cancel"));
installer.previous.setText(Installer.resources.getString("previous"));
installer.setTitle(Installer.resources.getString("title"));
setBorder(BorderFactory.createTitledBorder(Installer.resources.getString("welcome")));
}
}