コード例 #1
0
ファイル: ThemeManager.java プロジェクト: laeubi/jgnash
  /**
   * 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;
  }
コード例 #2
0
  /**
   * @param className
   * @throws Exception
   */
  public static void setLookAndFeel(String className) throws Exception {
    LookAndFeel laf = null;

    if (!className.equals(DEFAULT_LAF)) {
      if (className.equals(SYSTEM_LAF)) {
        String systemLaf = UIManager.getSystemLookAndFeelClassName();
        log.debug("System Look And Feel is " + systemLaf);
        laf = (LookAndFeel) Class.forName(systemLaf).newInstance();
      } else if (className.equals(CROSS_PLATFORM_LAF)) {
        String crossPlatformLaf = UIManager.getCrossPlatformLookAndFeelClassName();
        log.debug("Cross Platform Look And Feel is " + crossPlatformLaf);
        laf = (LookAndFeel) Class.forName(crossPlatformLaf).newInstance();
      } else {
        laf = (LookAndFeel) Class.forName(className).newInstance();
      }
    }

    //  Now actually set the look and feel
    if (laf != null) {
      log.info("Setting look and feel " + laf.getName() + " (" + laf.getClass().getName() + ")");
      UIManager.setLookAndFeel(laf);
      UIManager.put("EditorPane.font", UIManager.getFont("TextArea.font"));
    }
  }
コード例 #3
0
 protected void addDefaultsTab() {
   LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
   JScrollPane scrollPane = new JScrollPane(createDefaultsTable());
   tabPane.addTab(lookAndFeel.getName() + " Defaults", scrollPane);
   defaultsTablesMap.put(lookAndFeel.getName(), scrollPane);
 }