FileDocCategorySizeDatePackage
LanguagePanel.javaAPI DocAzureus 3.0.3.46143Thu Jul 13 09:17:26 BST 2006org.gudy.azureus2.ui.swt.config.wizard

LanguagePanel

public class LanguagePanel extends org.gudy.azureus2.ui.swt.wizard.AbstractWizardPanel
author
TuxPaper
created
Feb 28, 2006

Fields Summary
Constructors Summary
public LanguagePanel(org.gudy.azureus2.ui.swt.wizard.Wizard wizard, org.gudy.azureus2.ui.swt.wizard.IWizardPanel previousPanel)

param
wizard
param
previousPanel

		super(wizard, previousPanel);
	
Methods Summary
private java.lang.StringbuildName(java.util.Locale locale)

		StringBuffer sName = new StringBuffer();

		String sName1 = locale.getDisplayLanguage(locale);
		String sName2 = locale.getDisplayLanguage();
		sName.append(sName1);

		if (!sName1.equals(sName2)) {
			sName.append("/").append(sName2);
		}

		sName1 = locale.getDisplayCountry(locale);
		sName2 = locale.getDisplayCountry();
		if (sName1.length() > 0 || sName2.length() > 0) {
			sName.append(" (");
			if (sName1.length() > 0)
				sName.append(sName1);

			if (sName2.length() > 0 && !sName1.equals(sName2)) {
				sName.append("/").append(sName2);
			}

			sName1 = locale.getDisplayVariant(locale);
			sName2 = locale.getDisplayVariant();
			if (sName1.length() > 0 || sName2.length() > 0) {
				sName.append(", ");
				if (sName1.length() > 0)
					sName.append(sName1);

				if (sName2.length() > 0 && !sName1.equals(sName2)) {
					sName.append("/").append(sName2);
				}
			}

			sName.append(")");
		}

		return sName.toString();
	
public org.gudy.azureus2.ui.swt.wizard.IWizardPanelgetNextPanel()

		return new WelcomePanel(((ConfigureWizard) wizard), this);
	
public booleanisNextEnabled()

		return true;
	
private voidsetChooseLabel(Label lblChoose)

param
lblChoose

		String sLocaleChooseString = MessageText
				.getString("ConfigureWizard.language.choose");
		String sDefChooseString = MessageText
				.getDefaultLocaleString("ConfigureWizard.language.choose");
		if (sLocaleChooseString.equals(sDefChooseString)) {
			lblChoose.setText(sLocaleChooseString);
		} else {
			lblChoose.setText(sLocaleChooseString + "\n" + sDefChooseString);
		}
	
public voidshow()

		GridData gridData;

		wizard.setTitleAsResourceID("configureWizard.welcome.title");

		Composite rootPanel = wizard.getPanel();
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		rootPanel.setLayout(layout);

		final Label lblChoose = new Label(rootPanel, SWT.WRAP);
		setChooseLabel(lblChoose);
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		lblChoose.setLayoutData(gridData);

		final List lstLanguage = new List(rootPanel, SWT.BORDER | SWT.V_SCROLL
				| SWT.SINGLE);
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.heightHint = 200;
		lstLanguage.setLayoutData(gridData);

		final Locale[] locales = MessageText.getLocales();

		int iUsingLocale = -1;
		for (int i = 0; i < locales.length; i++) {
			Locale locale = locales[i];

			lstLanguage.add(buildName(locale));
			if (MessageText.isCurrentLocale(locale))
				iUsingLocale = i;
		}
		lstLanguage.select(iUsingLocale);

		lstLanguage.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				int index = lstLanguage.getSelectionIndex();
				if (index >= 0 && index < locales.length) {
					COConfigurationManager.setParameter("locale", locales[index]
							.toString());

					MessageText.loadBundle();
					DisplayFormatters.setUnits();
					DisplayFormatters.loadMessages();

					Shell shell = wizard.getWizardWindow();
					Messages.updateLanguageForControl(shell);
					setChooseLabel(lblChoose);

					shell.layout(true, true);

					lstLanguage.setRedraw(false);
					for (int i = 0; i < locales.length; i++) {
						lstLanguage.setItem(i, buildName(locales[i]));
					}
					lstLanguage.setRedraw(true);

					try {
						UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
						if (uiFunctions != null) {
							uiFunctions.refreshLanguage();
						}
					} catch (Exception ex) {
					}
				}
			}
		});

		FontData[] fontData = lstLanguage.getFont().getFontData();
		for (int i = 0; i < fontData.length; i++) {
			if (fontData[i].getHeight() < 10)
				fontData[i].setHeight(10);
		}
		final Font font = new Font(rootPanel.getDisplay(), fontData);
		lstLanguage.setFont(font);

		lstLanguage.getShell().addListener(SWT.Show, new Listener() {
			public void handleEvent(Event event) {
				lstLanguage.showSelection();
			}
		});

		lstLanguage.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				if (font != null && !font.isDisposed())
					font.dispose();
			}
		});