All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.ide.customize.CustomizeUIThemeStepPanel Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition platform-impl library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.customize;

import com.intellij.CommonBundle;
import com.intellij.ide.WelcomeWizardUtil;
import com.intellij.ide.ui.LafManager;
import com.intellij.ide.ui.laf.IntelliJLaf;
import com.intellij.ide.ui.laf.darcula.DarculaLaf;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.OptionsBundle;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.IconUtil;
import com.intellij.util.ui.UIUtil;

import javax.swing.*;
import java.awt.*;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
  public static class ThemeInfo {
    public final String name;
    public final String previewFileName;
    public final String laf;
    
    private Icon icon; 

    public ThemeInfo(String name, String previewFileName, String laf) {
      this.name = name;
      this.previewFileName = previewFileName;
      this.laf = laf;
    }

    private Icon getIcon() {
      if (icon == null) {
        String selector;
        if (SystemInfo.isMac) {
          selector = "OSX";
        }
        else if (SystemInfo.isWindows) {
          selector = "Windows";
        }
        else {
          selector = "Linux";
        }
        icon = IconLoader.getIcon("/lafs/" + selector + previewFileName + ".png");
      }
      return icon;
    }
    
    public void apply() {
    }
  }
  protected static final ThemeInfo AQUA = new ThemeInfo("Default", "Aqua", "com.apple.laf.AquaLookAndFeel");
  protected static final ThemeInfo DARCULA = new ThemeInfo("Darcula", "Darcula", DarculaLaf.class.getName());
  protected static final ThemeInfo INTELLIJ = new ThemeInfo("IntelliJ", "IntelliJ", IntelliJLaf.class.getName());
  protected static final ThemeInfo ALLOY = new ThemeInfo("Alloy. IDEA Theme", "Alloy", "com.incors.plaf.alloy.AlloyIdea");
  protected static final ThemeInfo GTK = new ThemeInfo("GTK+", "GTK", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel");

  private boolean myInitial = true;
  private boolean myColumnMode;
  private JLabel myPreviewLabel;
  private Set myThemes = new LinkedHashSet();

  public CustomizeUIThemeStepPanel() {
    setLayout(createSmallBorderLayout());
    IconLoader.activate();

    initThemes(myThemes);

    myColumnMode = myThemes.size() > 2;
    JPanel buttonsPanel = new JPanel(new GridLayout(myColumnMode ? myThemes.size() : 1, myColumnMode ? 1 : myThemes.size(), 5, 5));
    ButtonGroup group = new ButtonGroup();
    ThemeInfo myDefaultTheme = null;

    for (final ThemeInfo theme: myThemes) {
      final JRadioButton radioButton = new JRadioButton(theme.name, myDefaultTheme == null);
      radioButton.setOpaque(false);
      if (myDefaultTheme == null) {
        radioButton.setSelected(true);
        myDefaultTheme = theme;
      }
      final JPanel panel = createBigButtonPanel(createSmallBorderLayout(), radioButton, new Runnable() {
        @Override
        public void run() {
          applyLaf(theme, CustomizeUIThemeStepPanel.this);
          theme.apply();
        }
      });
      panel.setBorder(createSmallEmptyBorder());
      panel.add(radioButton, myColumnMode ? BorderLayout.WEST : BorderLayout.NORTH);
      Icon icon = theme.getIcon();
      final JLabel label = new JLabel(myColumnMode ? IconUtil.scale(IconUtil.cropIcon(icon, icon.getIconWidth() * 2 / 3, icon.getIconHeight() * 2 / 3), .5) : icon);
      label.setVerticalAlignment(SwingConstants.TOP);
      label.setHorizontalAlignment(SwingConstants.RIGHT);
      panel.add(label, BorderLayout.CENTER);

      group.add(radioButton);
      buttonsPanel.add(panel);
    }
    add(buttonsPanel, BorderLayout.CENTER);
    myPreviewLabel = new JLabel();
    myPreviewLabel.setHorizontalAlignment(myColumnMode ? SwingConstants.LEFT : SwingConstants.CENTER);
    myPreviewLabel.setVerticalAlignment(SwingConstants.CENTER);
    if (myColumnMode) {
      add(buttonsPanel, BorderLayout.WEST);
      JPanel wrapperPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
      wrapperPanel.add(myPreviewLabel);
      add(wrapperPanel, BorderLayout.CENTER);
    }
    applyLaf(myDefaultTheme, this);
    myInitial = false;
  }

  protected void initThemes(Collection result) {
    if (SystemInfo.isMac) {
      result.add(AQUA);
      result.add(DARCULA);
    }
    else if (SystemInfo.isWindows) {
      //if (PlatformUtils.isIdeaCommunity()) {
      result.add(INTELLIJ);
      //}
      //else {
      //  addLaf(ALLOY);
      //}
      result.add(DARCULA);
    }
    else {
      result.add(INTELLIJ);
      result.add(DARCULA);
      result.add(GTK);
    }
  }

  @Override
  public Dimension getPreferredSize() {
    Dimension size = super.getPreferredSize();
    size.width += 30;
    return size;
  }

  @Override
  public String getTitle() {
    return "UI Themes";
  }

  @Override
  public String getHTMLHeader() {
    return "

Set UI theme

 "; } @Override public String getHTMLFooter() { return "UI theme can be changed later in " + CommonBundle.settingsTitle() + " | " + OptionsBundle.message("configurable.group.appearance.settings.display.name") + " | " + "Appearance"; } private void applyLaf(ThemeInfo theme, Component component) { UIManager.LookAndFeelInfo info = new UIManager.LookAndFeelInfo(theme.name, theme.laf); if (info == null) return; try { UIManager.setLookAndFeel(info.getClassName()); String className = info.getClassName(); if (!myInitial) { WelcomeWizardUtil.setWizardLAF(className); } Window window = SwingUtilities.getWindowAncestor(component); if (window != null) { if (SystemInfo.isMac) { window.setBackground(new Color(UIUtil.getPanelBackground().getRGB())); } SwingUtilities.updateComponentTreeUI(window); } if (ApplicationManager.getApplication() != null) { LafManager.getInstance().setCurrentLookAndFeel(info); } if (myColumnMode) { myPreviewLabel.setIcon(theme.getIcon()); myPreviewLabel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Label.disabledForeground"))); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy