001: package com.xoetrope.langmgr;
002:
003: import java.util.Enumeration;
004: import java.util.Hashtable;
005: import java.util.Properties;
006:
007: import com.xoetrope.awt.XGraphicButton;
008: import net.xoetrope.awt.XComboBox;
009: import net.xoetrope.awt.XDialog;
010: import net.xoetrope.xui.XProjectManager;
011:
012: /**
013: * <p>A dialog for choosing languages. See the Localization chapter of the
014: * <i>XuiPro User Guide</i> for more detail.</p>
015: * <p>XUI uses standard property files for localization. These localization files can be set
016: * for an individual page (by setting the 'resource' attribute of the XPage
017: * element or for the component factory. The project's resource manager
018: * is used to identify the current locale and the name of the property file by default.</p>
019: *
020: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
021: * the GNU Public License (GPL), please see license.txt for more details. If
022: * you make commercial use of this software you must purchase a commercial
023: * license from Xoetrope.</p>
024: * <p> $Revision: 1.8 $</p>
025: */
026: public class LanguageChooserDialog extends XDialog {
027: XComboBox languageList;
028: Hashtable languages;
029: private String selectedLanguage;
030: private String defLangCode;
031:
032: /**
033: * Create a new instance of the lanuage dialog
034: * @param langCode the ISO language code
035: */
036: public LanguageChooserDialog(String langCode) {
037: super (true, 10);
038: defLangCode = langCode;
039:
040: pageHelper.componentFactory.setResourceBundle(XProjectManager
041: .getCurrentProject().getStartupParam("Language"));
042:
043: setCaption(pageHelper.componentFactory
044: .translate("CAROUSEL_SELECT_LANGUAGE"));
045:
046: XGraphicButton cancelBtn, okBtn;
047: languages = new Hashtable();
048:
049: languageList = (XComboBox) pageHelper.componentFactory
050: .addComponent(COMBO, 0, 0, 240, 20, null, null);
051:
052: cancelBtn = new XGraphicButton(pageHelper.componentFactory
053: .translate("CAROUSEL_CANCEL"),
054: XGraphicButton.SOLID_STYLE);
055: cancelBtn.setBounds(30, 40, 82, 20);
056: cancelBtn.setCentered(true);
057: cancelBtn.setDrawArrow(false);
058: contentPanel.add(cancelBtn, 0);
059:
060: okBtn = new XGraphicButton(pageHelper.componentFactory
061: .translate("CAROUSEL_OK"), XGraphicButton.SOLID_STYLE);
062: okBtn.setBounds(149, 40, 82, 20);
063: okBtn.setCentered(true);
064: okBtn.setDrawArrow(false);
065: contentPanel.add(okBtn, 0);
066:
067: getEventHandler().addHandler(this , cancelBtn, "ActionHandler",
068: "cancel");
069: getEventHandler()
070: .addHandler(this , okBtn, "ActionHandler", "ok");
071:
072: fillLanguageList();
073: }
074:
075: /**
076: * Dismiss the dialog
077: */
078: public void cancel() {
079: if (wasMouseClicked()) {
080: selectedLanguage = null;
081: closeDlg();
082: }
083: }
084:
085: /**
086: * Dismiss the dialog and choose the selected language
087: */
088: public void ok() {
089: if (wasMouseClicked()) {
090: selectedLanguage = (String) languages.get(languageList
091: .getSelectedItem());
092: closeDlg();
093: }
094: }
095:
096: /**
097: * Get the name of the selected language
098: * @return the language name/code
099: */
100: public String getSelectedLanguage() {
101: return selectedLanguage;
102: }
103:
104: /**
105: * Read the language file and fill the language list
106: */
107: private void fillLanguageList() {
108: try {
109: Properties props = new Properties();
110: String selectedLanguageName = null;
111: props.load(XProjectManager.getCurrentProject()
112: .getInputStream("LanguageList.properties"));
113: Enumeration propNames = props.propertyNames();
114: while (propNames.hasMoreElements()) {
115: String languageName = (String) propNames.nextElement();
116: String languageCode = (String) props.get(languageName);
117: if (languageCode.equals(defLangCode))
118: selectedLanguageName = languageName;
119: languages.put(languageName, languageCode);
120: languageList.add(languageName);
121: }
122: if (selectedLanguageName != null)
123: languageList.select((Object) selectedLanguageName);
124: } catch (Exception ex) {
125: }
126: }
127: }
|