mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
IDEA-100551 Database view/editor/switcher colors initial
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
package com.intellij.ui.tabs;
|
||||
|
||||
import com.intellij.notification.impl.ui.StickyButton;
|
||||
import com.intellij.notification.impl.ui.StickyButtonUI;
|
||||
import com.intellij.ui.ColorChooser;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.FileColorManager;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.plaf.ButtonUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author gregsh
|
||||
*/
|
||||
public class ColorSelectionComponent extends JPanel {
|
||||
private static final String CUSTOM_COLOR_NAME = "Custom";
|
||||
private Map<String, ColorButton> myColorToButtonMap = new LinkedHashMap<String, ColorButton>();
|
||||
private final ButtonGroup myButtonGroup = new ButtonGroup();
|
||||
private final JPanel myInnerPanel;
|
||||
private ChangeListener myChangeListener;
|
||||
|
||||
public ColorSelectionComponent() {
|
||||
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
|
||||
myInnerPanel = new JPanel();
|
||||
myInnerPanel.setLayout(new BoxLayout(myInnerPanel, BoxLayout.X_AXIS));
|
||||
myInnerPanel.setBorder(
|
||||
BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
if (!UIUtil.isUnderDarcula()) {
|
||||
myInnerPanel.setBackground(Color.WHITE);
|
||||
}
|
||||
add(myInnerPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public void setChangeListener(ChangeListener changeListener) {
|
||||
myChangeListener = changeListener;
|
||||
}
|
||||
|
||||
public void setSelectedColor(String colorName) {
|
||||
AbstractButton button = myColorToButtonMap.get(colorName);
|
||||
if (button != null) {
|
||||
button.setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<String> getColorNames() {
|
||||
return myColorToButtonMap.keySet();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getColorName(@Nullable Color color) {
|
||||
if (color == null) return null;
|
||||
for (String name : myColorToButtonMap.keySet()) {
|
||||
if (color.getRGB() == myColorToButtonMap.get(name).getColor().getRGB()) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addCustomColorButton() {
|
||||
CustomColorButton customButton = new CustomColorButton();
|
||||
myButtonGroup.add(customButton);
|
||||
myInnerPanel.add(customButton);
|
||||
myColorToButtonMap.put(customButton.getText(), customButton);
|
||||
myInnerPanel.add(Box.createHorizontalStrut(5));
|
||||
}
|
||||
|
||||
public void addColorButton(@NotNull String name, @NotNull Color color) {
|
||||
ColorButton colorButton = new ColorButton(name, color);
|
||||
myButtonGroup.add(colorButton);
|
||||
myInnerPanel.add(colorButton);
|
||||
myColorToButtonMap.put(name, colorButton);
|
||||
myInnerPanel.add(Box.createHorizontalStrut(5));
|
||||
}
|
||||
|
||||
public void setCustomButtonColor(@NotNull Color color) {
|
||||
CustomColorButton button = (CustomColorButton)myColorToButtonMap.get(CUSTOM_COLOR_NAME);
|
||||
button.setColor(color);
|
||||
button.setSelected(true);
|
||||
button.repaint();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ColorButton getSelectedButtonInner() {
|
||||
for (String name : myColorToButtonMap.keySet()) {
|
||||
ColorButton button = myColorToButtonMap.get(name);
|
||||
if (button.isSelected()) return button;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSelectedColorName() {
|
||||
ColorButton button = getSelectedButtonInner();
|
||||
return button == null? null : button instanceof CustomColorButton ? ColorUtil.toHex(button.getColor()) : button.getName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Color getSelectedColor() {
|
||||
ColorButton button = getSelectedButtonInner();
|
||||
return button == null? null : button.getColor();
|
||||
}
|
||||
|
||||
public void initDefault(@NotNull FileColorManager manager, @Nullable String selectedColorName) {
|
||||
for (String name : manager.getColorNames()) {
|
||||
addColorButton(name, ObjectUtils.assertNotNull(manager.getColor(name)));
|
||||
}
|
||||
addCustomColorButton();
|
||||
setSelectedColor(selectedColorName);
|
||||
}
|
||||
|
||||
private class ColorButton extends StickyButton {
|
||||
protected Color myColor;
|
||||
|
||||
protected ColorButton(final String text, final Color color) {
|
||||
super(FileColorManagerImpl.getAlias(text));
|
||||
setUI(new ColorButtonUI());
|
||||
myColor = color;
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doPerformAction(e);
|
||||
}
|
||||
});
|
||||
|
||||
setBackground(new JBColor(Color.WHITE, UIUtil.getControlColor()));
|
||||
setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
|
||||
}
|
||||
|
||||
protected void doPerformAction(ActionEvent e) {
|
||||
stateChanged();
|
||||
}
|
||||
|
||||
Color getColor() {
|
||||
return myColor;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getForeground() {
|
||||
if (getModel().isSelected()) {
|
||||
return JBColor.foreground();
|
||||
}
|
||||
else if (getModel().isRollover()) {
|
||||
return JBColor.GRAY;
|
||||
}
|
||||
else {
|
||||
return getColor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ButtonUI createUI() {
|
||||
return new ColorButtonUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void stateChanged() {
|
||||
if (myChangeListener != null) {
|
||||
myChangeListener.stateChanged(new ChangeEvent(this));
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomColorButton extends ColorButton {
|
||||
private CustomColorButton() {
|
||||
super(CUSTOM_COLOR_NAME, Color.WHITE);
|
||||
myColor = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPerformAction(ActionEvent e) {
|
||||
final Color color = ColorChooser.chooseColor(this, "Choose Color", myColor);
|
||||
if (color != null) {
|
||||
myColor = color;
|
||||
}
|
||||
setSelected(myColor != null);
|
||||
stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getForeground() {
|
||||
return getModel().isSelected() ? Color.BLACK : JBColor.GRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
Color getColor() {
|
||||
return myColor == null ? Color.WHITE : myColor;
|
||||
}
|
||||
}
|
||||
|
||||
private class ColorButtonUI extends StickyButtonUI<ColorButton> {
|
||||
|
||||
@Override
|
||||
protected Color getBackgroundColor(final ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getFocusColor(ColorButton button) {
|
||||
return button.getColor().darker();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getSelectionColor(ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getRolloverColor(ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getArcSize() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-168
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.intellij.ui.tabs;
|
||||
|
||||
import com.intellij.notification.impl.ui.StickyButton;
|
||||
import com.intellij.notification.impl.ui.StickyButtonUI;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -25,18 +23,16 @@ import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.ui.ColorChooser;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.FileColorManager;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ButtonUI;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -51,8 +47,8 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
private FileColorConfiguration myConfiguration;
|
||||
private JComboBox myScopeComboBox;
|
||||
private final FileColorManager myManager;
|
||||
private HashMap<String,AbstractButton> myColorToButtonMap;
|
||||
private static final String CUSTOM_COLOR_NAME = "Custom";
|
||||
private final ColorSelectionComponent myColorSelectionComponent;
|
||||
|
||||
private final Map<String, NamedScope> myScopeNames = new HashMap<String, NamedScope>();
|
||||
|
||||
public FileColorConfigurationEditDialog(@NotNull final FileColorManager manager, @Nullable final FileColorConfiguration configuration) {
|
||||
@@ -63,6 +59,14 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
|
||||
myManager = manager;
|
||||
myConfiguration = configuration;
|
||||
myColorSelectionComponent = new ColorSelectionComponent();
|
||||
myColorSelectionComponent.initDefault(manager, configuration == null ? null : configuration.getColorName());
|
||||
myColorSelectionComponent.setChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
updateOKButton();
|
||||
}
|
||||
});
|
||||
|
||||
init();
|
||||
updateCustomButton();
|
||||
@@ -128,7 +132,7 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
colorPanel.setLayout(new BoxLayout(colorPanel, BoxLayout.X_AXIS));
|
||||
final JLabel colorLabel = new JLabel("Color:");
|
||||
colorPanel.add(colorLabel);
|
||||
colorPanel.add(createColorButtonsPanel(myConfiguration));
|
||||
colorPanel.add(myColorSelectionComponent);
|
||||
colorPanel.add(Box.createHorizontalGlue());
|
||||
result.add(colorPanel);
|
||||
|
||||
@@ -139,17 +143,10 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
final Object item = myScopeComboBox.getSelectedItem();
|
||||
if (item instanceof String) {
|
||||
Color color = myConfiguration == null ? null : ColorUtil.fromHex(myConfiguration.getColorName(), null);
|
||||
final CustomColorButton button = (CustomColorButton)myColorToButtonMap.get(CUSTOM_COLOR_NAME);
|
||||
|
||||
if (color == null) {
|
||||
color = ColorUtil.getColor(myScopeNames.get(item).getClass());
|
||||
}
|
||||
|
||||
if (color != null) {
|
||||
button.setColor(color);
|
||||
button.setSelected(true);
|
||||
button.repaint();
|
||||
}
|
||||
if (color != null) myColorSelectionComponent.setCustomButtonColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,57 +166,9 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
return myConfiguration;
|
||||
}
|
||||
|
||||
private JComponent createColorButtonsPanel(final FileColorConfiguration configuration) {
|
||||
final JPanel result = new JPanel(new BorderLayout());
|
||||
result.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
|
||||
final JPanel inner = new JPanel();
|
||||
inner.setLayout(new BoxLayout(inner, BoxLayout.X_AXIS));
|
||||
inner.setBorder(
|
||||
BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
if (!UIUtil.isUnderDarcula()) {
|
||||
inner.setBackground(Color.WHITE);
|
||||
}
|
||||
result.add(inner, BorderLayout.CENTER);
|
||||
|
||||
final ButtonGroup group = new ButtonGroup();
|
||||
|
||||
myColorToButtonMap = new HashMap<String, AbstractButton>();
|
||||
|
||||
final Collection<String> names = myManager.getColorNames();
|
||||
for (final String name : names) {
|
||||
final ColorButton colorButton = new ColorButton(name, myManager.getColor(name));
|
||||
group.add(colorButton);
|
||||
inner.add(colorButton);
|
||||
myColorToButtonMap.put(name, colorButton);
|
||||
inner.add(Box.createHorizontalStrut(5));
|
||||
}
|
||||
final CustomColorButton customButton = new CustomColorButton();
|
||||
group.add(customButton);
|
||||
inner.add(customButton);
|
||||
myColorToButtonMap.put(customButton.getText(), customButton);
|
||||
inner.add(Box.createHorizontalStrut(5));
|
||||
|
||||
|
||||
if (configuration != null) {
|
||||
final AbstractButton button = myColorToButtonMap.get(configuration.getColorName());
|
||||
if (button != null) {
|
||||
button.setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getColorName() {
|
||||
for (String name : myColorToButtonMap.keySet()) {
|
||||
final AbstractButton button = myColorToButtonMap.get(name);
|
||||
if (button.isSelected()) {
|
||||
return button instanceof CustomColorButton ? ColorUtil.toHex(((CustomColorButton)button).getColor()) : name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return myColorSelectionComponent.getSelectedColorName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,106 +190,4 @@ public class FileColorConfigurationEditDialog extends DialogWrapper {
|
||||
protected JComponent createCenterPanel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ColorButton extends StickyButton {
|
||||
protected Color myColor;
|
||||
|
||||
protected ColorButton(final String text, final Color color) {
|
||||
super(FileColorManagerImpl.getAlias(text));
|
||||
setUI(new ColorButtonUI());
|
||||
myColor = color;
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doPerformAction(e);
|
||||
}
|
||||
});
|
||||
|
||||
setBackground(new JBColor(Color.WHITE, UIUtil.getControlColor()));
|
||||
setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
|
||||
}
|
||||
|
||||
protected void doPerformAction(ActionEvent e) {
|
||||
updateOKButton();
|
||||
}
|
||||
|
||||
Color getColor() {
|
||||
return myColor;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getForeground() {
|
||||
if (getModel().isSelected()) {
|
||||
return JBColor.foreground();
|
||||
} else if (getModel().isRollover()) {
|
||||
return JBColor.GRAY;
|
||||
} else {
|
||||
return getColor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ButtonUI createUI() {
|
||||
return new ColorButtonUI();
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomColorButton extends ColorButton {
|
||||
private CustomColorButton() {
|
||||
super(CUSTOM_COLOR_NAME, Color.WHITE);
|
||||
myColor = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPerformAction(ActionEvent e) {
|
||||
final Color color = ColorChooser.chooseColor(FileColorConfigurationEditDialog.this.getRootPane(), "Choose Color", myColor);
|
||||
if (color != null) {
|
||||
myColor = color;
|
||||
}
|
||||
setSelected(myColor != null);
|
||||
getOKAction().setEnabled(myColor != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getForeground() {
|
||||
return getModel().isSelected() ? Color.BLACK : JBColor.GRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
Color getColor() {
|
||||
return myColor == null ? Color.WHITE : myColor;
|
||||
}
|
||||
}
|
||||
|
||||
private class ColorButtonUI extends StickyButtonUI<ColorButton> {
|
||||
|
||||
@Override
|
||||
protected Color getBackgroundColor(final ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getFocusColor(ColorButton button) {
|
||||
return button.getColor().darker();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getSelectionColor(ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getRolloverColor(ColorButton button) {
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getArcSize() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.UniqueVFilePathBuilder;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorTabbedContainer;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWindow;
|
||||
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
@@ -1104,7 +1105,8 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null , null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
|
||||
append(name, SimpleTextAttributes.fromTextAttributes(attributes));
|
||||
|
||||
final Color color = FileColorManager.getInstance(myProject).getFileColor(virtualFile);
|
||||
// calc color the same way editor tabs do this, i.e. including extensions
|
||||
Color color = EditorTabbedContainer.calcTabColor(myProject, virtualFile);
|
||||
|
||||
if (!selected && color != null) {
|
||||
setBackground(color);
|
||||
|
||||
Reference in New Issue
Block a user