001: /*
002: * $RCSfile: TuiLanguageStep.java,v $
003: * @modification $Date: 2001/06/08 10:03:04 $
004: * @version $Id: TuiLanguageStep.java,v 1.4 2001/06/08 10:03:04 vonarnim Exp $
005: *
006: */
007: package com.memoire.vainstall.tui;
008:
009: import com.memoire.vainstall.*;
010:
011: /**
012: * Language step for 'text' gui.
013: *
014: * @see com.memoire.vainstall.TuiDefaultStep
015: * @see com.memoire.vainstall.VALanguageStep
016: *
017: * @author Henrik Falk
018: * @version $Id: TuiLanguageStep.java,v 1.4 2001/06/08 10:03:04 vonarnim Exp $
019: *
020: */
021: public class TuiLanguageStep extends TuiDefaultStep implements
022: VALanguageStep {
023:
024: /**
025: * The language the user chooses.
026: * The default language is English.
027: */
028: private String language = "english";
029:
030: /**
031: * Constructs a TuiLanguageStep
032: */
033: public TuiLanguageStep() {
034:
035: TuiWizard.clear();
036: TuiWizard.title();
037: TuiWizard.println(VAGlobals.i18n("TuiLanguageStep_Language"));
038: TuiWizard.separator();
039: TuiWizard.println("");
040: TuiWizard.println(VAGlobals
041: .i18n("TuiLanguageStep_SelectLanguage"));
042:
043: String[] supportedLanguages = VAGlobals.getSupportedLanguages();
044:
045: // write languages to the console
046: for (int i = 0; i < supportedLanguages.length; i++) {
047: TuiWizard.println(" " + String.valueOf(i + 1) + ". "
048: + supportedLanguages[i]);
049: }
050:
051: // write empty lines
052: for (int i = 8; i <= (25 - supportedLanguages.length); i++) {
053: TuiWizard.println("");
054: }
055:
056: TuiWizard.separator();
057:
058: // get language selection from user as number
059: String selectedLanguage = TuiWizard.input();
060:
061: // convert to integral type
062: int selectedIndex = -1;
063: try {
064: selectedIndex = new Integer(selectedLanguage).intValue();
065: } catch (NumberFormatException exc) {
066: // selectedIndex = -1;
067: }
068:
069: // validate selectedIndex
070: if (selectedIndex < 1
071: || selectedIndex > supportedLanguages.length) {
072: selectedIndex = -1;
073: }
074:
075: // determine the language
076: if (selectedIndex != -1) {
077: for (int i = 0; i < VAGlobals.languages.length; i++) {
078: if (VAGlobals.languages[i][1]
079: .equals(supportedLanguages[selectedIndex - 1]) == true) {
080: language = VAGlobals.languages[i][0];
081: }
082: }
083: }
084:
085: // tell the user that we defaults to english
086: if (selectedIndex == -1) {
087: TuiWizard.println(VAGlobals
088: .i18n("TuiLanguageStep_DefaultToEnglish"));
089: }
090:
091: TuiWizard.println(VAGlobals.i18n("TuiLanguageStep_Continue"));
092: TuiWizard.info();
093: }
094:
095: /**
096: * Get the language which the user has choosen.
097: * @return String
098: */
099: public String getLanguage() {
100: return language;
101: }
102:
103: }
|