Exemple #1
0
  /** Gets current text values and reassigns them to the GUI components. */
  private void reassignTexts() {
    setTitle(Language.getText("welcome.welcome") + " - " + Consts.APPLICATION_NAME);

    welcomeLabel.setText(Language.getText("welcome.welcome") + '!');
    firstRunLabel.setText(Language.getText("welcome.firstRun", Consts.APPLICATION_NAME + "™"));
    chooseLabel.setText(Language.getText("welcome.selectLanguage"));
    thankYouLabel.setText(Language.getText("welcome.thankYou", Consts.APPLICATION_NAME + "™"));
    languageLabel.setText(Language.getText("welcome.language"));
    voiceLabel.setText(Language.getText("welcome.voice"));

    languageLabel.setPreferredSize(null);
    voiceLabel.setPreferredSize(null);
    final int maxWidth =
        Math.max(languageLabel.getPreferredSize().width, voiceLabel.getPreferredSize().width);
    languageLabel.setPreferredSize(
        new Dimension(maxWidth, languageLabel.getPreferredSize().height));
    voiceLabel.setPreferredSize(new Dimension(maxWidth, voiceLabel.getPreferredSize().height));

    GuiUtils.updateButtonText(okButton, "button.ok");
    GuiUtils.updateButtonText(cancelButton, "button.cancel");

    pack();
    SharedUtils.centerWindow(this);
  }
Exemple #2
0
  /** 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);
  }