Example #1
0
  private JMenu buildSubstanceMenu() {
    LookAndFeel lf = UIManager.getLookAndFeel();

    JMenu substanceMenu = new JMenu(rb.getString("Menu.SubstanceThemes.Name"));

    for (SkinInfo info : SubstanceLookAndFeel.getAllSkins().values()) {
      JRadioButtonMenuItem button = new JRadioButtonMenuItem();
      button.setText(info.getDisplayName());
      button.setActionCommand(info.getClassName());

      // add the button to the global look and feel
      lfButtonGroup.add(button);

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

            restartUI();
          });

      substanceMenu.add(button);

      // select the button as the active L&F if it is the current skin
      if (lf instanceof SubstanceLookAndFeel) {
        if (SubstanceLookAndFeel.getCurrentSkin()
            .getClass()
            .getName()
            .equals(info.getClassName())) {
          button.setSelected(true);
        }
      }
    }

    return substanceMenu;
  }
  private void initComponents() {
    okButton = new JButton();
    cancelButton = new JButton();
    resetButton = new JButton();

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(translate("advancedSettings.dialog.title"));
    setModal(true);
    setPreferredSize(new Dimension(800, 500));

    okButton.setText(AppStrings.translate("button.ok"));
    okButton.addActionListener(this::okButtonActionPerformed);

    cancelButton.setText(AppStrings.translate("button.cancel"));
    cancelButton.addActionListener(this::cancelButtonActionPerformed);

    resetButton.setText(AppStrings.translate("button.reset"));
    resetButton.addActionListener(this::resetButtonActionPerformed);

    Container cnt = getContentPane();
    cnt.setLayout(new BorderLayout());
    // cnt.add(new JScrollPane(configurationTable),BorderLayout.CENTER);

    JPanel buttonsPanel = new JPanel(new BorderLayout());

    JPanel buttonsLeftPanel = new JPanel(new FlowLayout());
    buttonsLeftPanel.add(resetButton, BorderLayout.WEST);

    buttonsPanel.add(buttonsLeftPanel, BorderLayout.WEST);

    JPanel buttonsRightPanel = new JPanel(new FlowLayout());
    buttonsRightPanel.add(cancelButton);
    buttonsRightPanel.add(okButton);
    buttonsPanel.add(buttonsRightPanel, BorderLayout.EAST);

    cnt.add(buttonsPanel, BorderLayout.SOUTH);

    JTabbedPane tabPane = new JTabbedPane();

    JComboBox<SkinSelect> skinComboBox = new JComboBox<>();
    skinComboBox.setRenderer(
        new SubstanceDefaultListCellRenderer() {

          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            SubstanceDefaultListCellRenderer cmp =
                (SubstanceDefaultListCellRenderer)
                    super.getListCellRendererComponent(
                        list,
                        value,
                        index,
                        isSelected,
                        cellHasFocus); // To change body of generated methods, choose Tools |
                                       // Templates.
            final SkinSelect ss = (SkinSelect) value;
            cmp.setIcon(
                new Icon() {

                  @Override
                  public void paintIcon(Component c, Graphics g, int x, int y) {
                    Graphics2D g2 = (Graphics2D) g;
                    g2.setRenderingHint(
                        RenderingHints.KEY_INTERPOLATION,
                        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                    g2.setRenderingHint(
                        RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                    g2.setRenderingHint(
                        RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    try {
                      Class<?> act = Class.forName(ss.getClassName());
                      SubstanceSkin skin = (SubstanceSkin) act.newInstance();
                      Color fill =
                          skin.getColorScheme(
                                  DecorationAreaType.GENERAL,
                                  ColorSchemeAssociationKind.FILL,
                                  ComponentState.ENABLED)
                              .getBackgroundFillColor();
                      Color hilight =
                          skin.getColorScheme(
                                  DecorationAreaType.GENERAL,
                                  ColorSchemeAssociationKind.FILL,
                                  ComponentState.ROLLOVER_SELECTED)
                              .getBackgroundFillColor();
                      Color border =
                          skin.getColorScheme(
                                  DecorationAreaType.GENERAL,
                                  ColorSchemeAssociationKind.BORDER,
                                  ComponentState.ENABLED)
                              .getDarkColor();
                      g2.setColor(fill);
                      g2.fillOval(0, 0, 16, 16);
                      g2.setColor(hilight);
                      g2.fillArc(0, 0, 16, 16, -45, 90);
                      g2.setColor(border);
                      g2.drawOval(0, 0, 16, 16);

                    } catch (ClassNotFoundException
                        | InstantiationException
                        | IllegalAccessException ex) {
                      // no icon
                    }
                  }

                  @Override
                  public int getIconWidth() {
                    return 16;
                  }

                  @Override
                  public int getIconHeight() {
                    return 16;
                  }
                });
            return cmp;
          }
        });
    skinComboBox.addItem(new SkinSelect(OceanicSkin.NAME, OceanicSkin.class.getName()));
    Map<String, SkinInfo> skins = SubstanceLookAndFeel.getAllSkins();
    for (String skinKey : skins.keySet()) {
      SkinInfo skin = skins.get(skinKey);
      skinComboBox.addItem(new SkinSelect(skin.getDisplayName(), skin.getClassName()));
      if (skin.getClassName().equals(Configuration.guiSkin.get())) {
        skinComboBox.setSelectedIndex(skinComboBox.getItemCount() - 1);
      }
    }

    Map<String, Component> tabs = new HashMap<>();
    getCategories(componentsMap, tabs, skinComboBox, getResourceBundle());

    String catOrder[] =
        new String[] {
          "ui",
          "display",
          "decompilation",
          "script",
          "format",
          "export",
          "import",
          "limit",
          "update",
          "debug",
          "other"
        };

    for (String cat : catOrder) {
      if (!tabs.containsKey(cat)) {
        continue;
      }

      tabPane.add(translate("config.group.name." + cat), tabs.get(cat));
      tabPane.setToolTipTextAt(
          tabPane.getTabCount() - 1, translate("config.group.description." + cat));
    }

    cnt.add(tabPane, BorderLayout.CENTER);
    pack();
  }