summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/openapi/options/newEditor/PreferencesDialog.java
blob: 8ed3527e090aa0500103cdd694f210e4b24948c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Copyright 2000-2013 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.openapi.options.newEditor;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.options.ConfigurableGroup;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.Gray;
import com.intellij.ui.SearchTextField;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;

/**
 * @author Konstantin Bulenkov
 */
public class PreferencesDialog extends DialogWrapper {
  private JPanel myRoot;
  private JPanel myTopPanel;
  private JPanel myCenterPanel;
  private SearchTextField mySearchTextField;

  public PreferencesDialog(@Nullable Project project, ConfigurableGroup[] groups) {
    super(project);
    init();
    ((JDialog)getPeer().getWindow()).setUndecorated(true);
    if (SystemInfo.isMac) {
      ((JComponent)((JDialog)getPeer().getWindow()).getContentPane()).setBorder(new EmptyBorder(0, 0, 0, 0));
    }
    else {
      ((JComponent)((JDialog)getPeer().getWindow()).getContentPane()).setBorder(new LineBorder(Gray._140, 1));
    }

    setTitle("Preferences");
  }

  @Nullable
  @Override
  protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(null);
    panel.add(createApplicationSettings());
    panel.add(createProjectSettings());
    panel.add(createEditorSettings());
    panel.add(createOtherSettings());
    panel.setPreferredSize(new Dimension(700, 370));
    myCenterPanel.add(panel, BorderLayout.CENTER);
    return myRoot;
  }

  @Nullable
  @Override
  public JComponent getPreferredFocusedComponent() {
    return mySearchTextField.getTextEditor();
  }

  private static JComponent createEditorSettings() {
    final LabeledButtonsPanel panel = new LabeledButtonsPanel("Editor");
    panel.addButton(new PreferenceButton("Editor", AllIcons.Preferences.Editor));
    panel.addButton(new PreferenceButton("Code Style", AllIcons.Preferences.CodeStyle));
    panel.setBackground(Gray._229);
    panel.setBorder(new CustomLineBorder(Gray._223, 0, 0, 1, 0));
    return panel;
  }

  private static JComponent createProjectSettings() {
    final LabeledButtonsPanel panel = new LabeledButtonsPanel("Project");
    panel.addButton(new PreferenceButton("Compiler", AllIcons.Preferences.Compiler));
    panel.addButton(new PreferenceButton("Version Control", AllIcons.Preferences.VersionControl));
    panel.addButton(new PreferenceButton("File Colors", AllIcons.Preferences.FileColors));
    panel.addButton(new PreferenceButton("Scopes", AllIcons.Preferences.Editor));
    panel.setBackground(Gray._236);
    panel.setBorder(new CustomLineBorder(Gray._223, 0, 0, 1, 0));
    return panel;
  }

  private static JComponent createApplicationSettings() {
    final LabeledButtonsPanel panel = new LabeledButtonsPanel("IDE");
    panel.addButton(new PreferenceButton("Appearance", AllIcons.Preferences.Appearance));
    panel.addButton(new PreferenceButton("General", AllIcons.Preferences.General));
    panel.addButton(new PreferenceButton("Keymap", AllIcons.Preferences.Keymap));
    panel.addButton(new PreferenceButton("File Types", AllIcons.Preferences.FileTypes));
    panel.setBackground(Gray._229);
    panel.setBorder(new CustomLineBorder(Gray._223, 0, 0, 1, 0));
    return panel;
  }

  private static JComponent createOtherSettings() {
    final LabeledButtonsPanel panel = new LabeledButtonsPanel("Other");
    panel.addButton(new PreferenceButton("Plugins", AllIcons.Preferences.Plugins));
    panel.addButton(new PreferenceButton("Updates", AllIcons.Preferences.Updates));
    panel.setBackground(Gray._236);
    panel.setBorder(new CustomLineBorder(Gray._223, 0, 0, 1, 0));
    return panel;
  }


  @Nullable
  @Override
  protected JComponent createSouthPanel() {
    if (SystemInfo.isMac) {
      return null;
    }
    final JComponent panel = super.createSouthPanel();
    if (panel != null) {
      panel.setBorder(new EmptyBorder(5, 5, 10, 20));
    }
    return panel;
  }

  private void createUIComponents() {
    myTopPanel = new JPanel(new BorderLayout()) {
      @Override
      protected void paintComponent(Graphics g) {
        ((Graphics2D)g).setPaint(new GradientPaint(0, 0, Gray._206, 0, getHeight() - 1, Gray._172));
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Gray._145);
        g.drawLine(0, getHeight() - 2, getWidth(), getHeight() - 2);
        g.setColor(Gray._103);
        g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
      }
    };
    final JLabel title = new JLabel("Preferences");
    if (!SystemInfo.isMac) {
      title.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD, 14));
    }
    else {
      title.setFont(new Font("Lucuda Grande", Font.PLAIN, 12));
    }
    title.setHorizontalTextPosition(SwingConstants.CENTER);
    title.setHorizontalAlignment(SwingConstants.CENTER);
    title.setVerticalAlignment(SwingConstants.TOP);
    myTopPanel.add(title, BorderLayout.NORTH);
    mySearchTextField = new SearchTextField();
    mySearchTextField.setOpaque(false);
    myTopPanel.add(mySearchTextField, BorderLayout.EAST);
  }
}