Beispiel #1
0
  /**
   * Loads the menu with the available look and feels for the application
   *
   * @return l and f menu
   */
  JMenu buildLookAndFeelMenu() {
    String activeLookAndFeelName = UIManager.getLookAndFeel().getName();

    // ButtonGroup buttonGroup = new ButtonGroup();
    JMenu lfMenu = new JMenu();

    lfMenu.setText(rb.getString("Menu.LookAndFeel.Name"));
    lfMenu.setMnemonic(jgnash.ui.util.Resource.getMnemonic("Menu.LookAndFeel.Mnemonic"));

    lfMenu.add(buildSubstanceMenu());

    List<String> lookAndFeels = new ArrayList<>();

    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
      if (isLookAndFeelAvailable(info.getClassName())) {
        lookAndFeels.add(info.getClassName());
      }
    }

    for (String lookAndFeel : KNOWN) {
      if (isLookAndFeelAvailable(lookAndFeel)) {
        lookAndFeels.add(lookAndFeel);
      }
    }

    Collections.sort(lookAndFeels);

    for (String lookAndFeel : lookAndFeels) {
      try {
        Class<?> lnfClass = Class.forName(lookAndFeel);
        LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance();

        JRadioButtonMenuItem button = new JRadioButtonMenuItem();

        button.setText(newLAF.getName());
        button.setActionCommand(lookAndFeel);
        button.setName(newLAF.getName());

        button.addActionListener(
            e -> {
              Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
              pref.put(LF, e.getActionCommand());

              restartUI();
            });

        lfButtonGroup.add(button);

        lfMenu.add(button);

        if (newLAF.getName().equals(activeLookAndFeelName)) {
          button.setSelected(true);
        }
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
      }
    }

    return lfMenu;
  }
Beispiel #2
0
  JMenu buildThemeMenu() {

    Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
    String currentTheme = pref.get(THEME, DEFAULT_THEME);

    themesMenu = new JMenu();
    themesMenu.setText(rb.getString("Menu.Themes.Name"));
    themesMenu.setMnemonic(jgnash.ui.util.Resource.getMnemonic("Menu.Themes.Mnemonic"));

    ButtonGroup themeButtonGroup = new ButtonGroup();
    buildThemeList();

    JRadioButtonMenuItem button;

    for (Object aThemeList : themeList) {
      MetalTheme theme = (MetalTheme) aThemeList;
      button = new JRadioButtonMenuItem();
      button.setText(theme.getName());
      button.setActionCommand(theme.getClass().getName());
      button.addActionListener(
          e -> {
            Preferences pref1 = Preferences.userNodeForPackage(ThemeManager.class);
            pref1.put(THEME, e.getActionCommand());

            restartUI();
          });

      themeButtonGroup.add(button);
      themesMenu.add(button);
      if (aThemeList.getClass().getName().equals(currentTheme)) {
        button.setSelected(true);
      }
    }
    refreshThemesState();
    return themesMenu;
  }