/** Cancels the language selection. */ private void cancel() { dispose(); // Cancel was pressed, revert to the default language Language.loadAndActivateLanguage(Settings.DEFAULT_APP_LANGUAGE); Settings.remove(Settings.KEY_SETTINGS_VOICE); synchronized (WelcomeFrame.this) { Sounds.playSoundSample(Sounds.SAMPLE_THANK_YOU, false); WelcomeFrame.this.notify(); // Notify the main thread to continue starting the application } }
/** Creates a new WelcomeFrame and makes it visible. */ public WelcomeFrame() { setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent event) { cancel(); }; }); setIconImage(Icons.SC2GEARS.getImage()); final Box box = Box.createVerticalBox(); box.add(Box.createVerticalStrut(5)); box.add(GuiUtils.wrapInPanel(SharedUtils.createAnimatedLogoLabel())); box.add(Box.createVerticalStrut(10)); GuiUtils.changeFontToBold(welcomeLabel); box.add(Box.createVerticalStrut(15)); box.add(GuiUtils.wrapInPanel(welcomeLabel)); box.add(Box.createVerticalStrut(15)); box.add(GuiUtils.wrapInPanel(firstRunLabel)); box.add(GuiUtils.wrapInPanel(chooseLabel)); box.add(Box.createVerticalStrut(15)); box.add(GuiUtils.wrapInPanel(thankYouLabel)); box.add(Box.createVerticalStrut(15)); final JPanel languagePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 1)); languagePanel.add(languageLabel); final JComboBox<String> languagesComboBox = new JComboBox<>(Language.getAvailableLanguages()); languagesComboBox.setMaximumRowCount( languagesComboBox.getModel().getSize()); // Display all languages languagesComboBox.setRenderer( new BaseLabelListCellRenderer<String>() { @Override public Icon getIcon(final String value) { return Icons.getLanguageIcon(value); } }); languagesComboBox.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { final String language = (String) languagesComboBox.getSelectedItem(); Language.loadAndActivateLanguage(language); reassignTexts(); } }); languagePanel.add(languagesComboBox); box.add(languagePanel); final JPanel voicePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 1)); voicePanel.add(voiceLabel); final JComboBox<VoiceDescription> voiceComboBox = new JComboBox<>(Sounds.VOICE_DESCRIPTIONS); voiceComboBox.setMaximumRowCount(15); // Not too many languages, display them all voiceComboBox.setRenderer( new BaseLabelListCellRenderer<VoiceDescription>() { @Override public Icon getIcon(final VoiceDescription value) { return Icons.getLanguageIcon(value.language); } }); voiceComboBox.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { final VoiceDescription voiceDescription = (VoiceDescription) voiceComboBox.getSelectedItem(); Settings.set(Settings.KEY_SETTINGS_VOICE, voiceDescription.name); Sounds.playSoundSample(Sounds.SAMPLE_WELCOME, false); } }); voicePanel.add(voiceComboBox); box.add(voicePanel); int maxWidth = Math.max( languagesComboBox.getPreferredSize().width, voiceComboBox.getPreferredSize().width); maxWidth += 5; languagesComboBox.setPreferredSize( new Dimension(maxWidth, languagesComboBox.getPreferredSize().height)); voiceComboBox.setPreferredSize( new Dimension(maxWidth, voiceComboBox.getPreferredSize().height)); box.add(Box.createVerticalStrut(15)); final JPanel buttonsPanel = new JPanel(); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { dispose(); Settings.set( Settings.KEY_SETTINGS_LANGUAGE, (String) languagesComboBox.getSelectedItem()); Settings.saveProperties(); synchronized (WelcomeFrame.this) { Sounds.playSoundSample(Sounds.SAMPLE_THANK_YOU, false); WelcomeFrame.this .notify(); // Notify the main thread to continue starting the application } } }); buttonsPanel.add(okButton); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { cancel(); } }); buttonsPanel.add(cancelButton); box.add(buttonsPanel); box.add(Box.createVerticalStrut(15)); final JPanel panel = new JPanel(); panel.add(Box.createHorizontalStrut(15)); panel.add(box); panel.add(Box.createHorizontalStrut(15)); getContentPane().add(panel); setResizable(false); reassignTexts(); setVisible(true); okButton.requestFocusInWindow(); Sounds.playSoundSample(Sounds.SAMPLE_WELCOME, false); }