mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
combo box UI
This commit is contained in:
@@ -158,6 +158,7 @@ public final class DarculaLaf extends BasicLookAndFeel {
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
private static void loadDefaults(UIDefaults defaults) {
|
||||
final Properties properties = new Properties();
|
||||
final String osSuffix = SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux";
|
||||
@@ -210,6 +211,7 @@ public final class DarculaLaf extends BasicLookAndFeel {
|
||||
} else {
|
||||
final Color color = ColorUtil.fromHex(value, null);
|
||||
final Integer invVal = getInteger(value);
|
||||
final Boolean boolVal = "true".equals(value) ? Boolean.TRUE : "false".equals(value) ? Boolean.FALSE : null;
|
||||
Icon icon = value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
|
||||
if (color != null) {
|
||||
return new ColorUIResource(color);
|
||||
@@ -217,6 +219,8 @@ public final class DarculaLaf extends BasicLookAndFeel {
|
||||
return invVal;
|
||||
} else if (icon != null) {
|
||||
return new IconUIResource(icon);
|
||||
} else if (boolVal != null) {
|
||||
return boolVal;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -14,7 +14,6 @@ EditorPane.inactiveBackground=535353
|
||||
EditorPane.inactiveForeground=eeeeee
|
||||
EditorPaneUI=com.intellij.ide.ui.laf.darcula.ui.DarculaEditorPaneUI
|
||||
|
||||
|
||||
control=535353
|
||||
|
||||
ScrollBarUI=com.intellij.ide.ui.laf.darcula.ui.DarculaScrollBarUI
|
||||
@@ -34,9 +33,10 @@ TextField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder
|
||||
PasswordField.background=aaaaaa
|
||||
|
||||
CheckBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI
|
||||
#ComboBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI
|
||||
ComboBox.background=eeeeee
|
||||
ComboBox.foreground=000000
|
||||
ComboBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI
|
||||
ComboBox.squareButton=false
|
||||
#ComboBox.background=eeeeee
|
||||
#ComboBox.foreground=000000
|
||||
RadioButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaRadioButtonUI
|
||||
|
||||
StatusBar.topColor=2c2c2c
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.ui.laf.darcula.ui;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicButtonUI;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class DarculaComboBoxButton extends JButton {
|
||||
private final JComboBox myComboBox;
|
||||
|
||||
public DarculaComboBoxButton(JComboBox comboBox) {
|
||||
myComboBox = comboBox;
|
||||
setUI(new BasicButtonUI() {
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
final Icon i;
|
||||
if (myComboBox.isEditable()) {
|
||||
g.drawLine(0,0,0,c.getHeight());
|
||||
i = AllIcons.Mac.Tree_white_down_arrow;
|
||||
} else {
|
||||
i = AllIcons.Ide.Statusbar_arrows;
|
||||
}
|
||||
i.paintIcon(c, g, (c.getWidth() - i.getIconWidth()) / 2, (c.getHeight() - i.getIconHeight()) / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return super.getPreferredSize(c);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
+127
-44
@@ -15,74 +15,157 @@
|
||||
*/
|
||||
package com.intellij.ide.ui.laf.darcula.ui;
|
||||
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
|
||||
import com.intellij.openapi.ui.GraphicsConfig;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
import javax.swing.plaf.basic.BasicComboBoxEditor;
|
||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class DarculaComboBoxUI extends BasicComboBoxUI {
|
||||
public class DarculaComboBoxUI extends BasicComboBoxUI implements Border {
|
||||
private final JComboBox myComboBox;
|
||||
private JBInsets myComboBoxInsets = new JBInsets(4, 7, 4, 3);
|
||||
|
||||
public DarculaComboBoxUI(JComboBox c) {
|
||||
myComboBox = c;
|
||||
c.setBorder(null);
|
||||
public DarculaComboBoxUI(JComboBox comboBox) {
|
||||
myComboBox = comboBox;
|
||||
myComboBox.setBorder(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
public static ComponentUI createUI(final JComponent c) {
|
||||
return new DarculaComboBoxUI(((JComboBox)c));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutManager createLayoutManager() {
|
||||
return new DarculaComboBoxLayoutManager();
|
||||
}
|
||||
protected ComboBoxEditor createEditor() {
|
||||
final ComboBoxEditor ed = new BasicComboBoxEditor.UIResource(){
|
||||
@Override
|
||||
protected JTextField createEditorComponent() {
|
||||
return super.createEditorComponent();
|
||||
}
|
||||
};
|
||||
if (ed != null) {
|
||||
ed.getEditorComponent().addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
myComboBox.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) {
|
||||
super.paintCurrentValueBackground(g, bounds, false);
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
myComboBox.repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return ed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
super.paint(g, c);
|
||||
hasFocus = comboBox.hasFocus();
|
||||
final GraphicsConfig config = new GraphicsConfig(g);
|
||||
if ( !comboBox.isEditable() ) {
|
||||
Rectangle r = rectangleForCurrentValue();
|
||||
paintCurrentValueBackground(g,r,hasFocus);
|
||||
paintCurrentValue(g,r,hasFocus);
|
||||
g.setColor(ColorUtil.fromHex("939393").darker());
|
||||
final int xxx = c.getWidth() - c.getBorder().getBorderInsets(c).right - arrowButton.getWidth();
|
||||
g.drawLine(xxx, hasFocus ? 2 : 1, xxx, c.getHeight() - (hasFocus ? 3 : 0));
|
||||
} else {
|
||||
g.setColor(editor.getBackground());
|
||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
g.fillRoundRect(1, 1, c.getWidth() - 2, c.getHeight() - 2, 5, 5);
|
||||
g.setColor(ColorUtil.fromHex("939393"));
|
||||
final int xxx = editor.getWidth() + c.getBorder().getBorderInsets(c).left;
|
||||
g.drawLine(xxx, hasFocus ? 3 : 1, xxx, c.getHeight() - (hasFocus ? 2 : 0));
|
||||
|
||||
editor.repaint();
|
||||
}
|
||||
config.restore();
|
||||
}
|
||||
|
||||
protected JButton createArrowButton() {
|
||||
final Color bg = myComboBox.getBackground();
|
||||
final Color fg = myComboBox.getForeground();
|
||||
JButton button = new BasicArrowButton(SwingConstants.SOUTH, bg, fg, fg, fg) {
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g2) {
|
||||
final Graphics2D g = (Graphics2D)g2;
|
||||
final GraphicsConfig config = new GraphicsConfig(g);
|
||||
|
||||
final int w = getWidth();
|
||||
final int h = getHeight();
|
||||
g.setColor(myComboBox.isEditable() ? UIUtil.getControlColor() : UIUtil.getControlColor());
|
||||
g.fillRect(0, 0, w, h);
|
||||
g.setColor(getForeground());
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||
final int xU = w / 4;
|
||||
final int yU = h / 4;
|
||||
final Path2D.Double path = new Path2D.Double();
|
||||
path.moveTo(xU+1, yU + 2);
|
||||
path.lineTo(3 * xU + 1, yU + 2);
|
||||
path.lineTo(2*xU+1, 3*yU );
|
||||
path.lineTo(xU+1, yU + 2);
|
||||
path.closePath();
|
||||
g.fill(path);
|
||||
g.setColor(ColorUtil.fromHex("939393").darker());
|
||||
g.drawLine(0, -1, 0 , h);
|
||||
//paintTriangle(g, w / 2, h / 2, 5, SOUTH, myComboBox.isEnabled());
|
||||
//g.setColor(ColorUtil.fromHex("939393"));
|
||||
//g.drawLine(0,0, 0,h);
|
||||
config.restore();
|
||||
}
|
||||
};
|
||||
button.setBorder(BorderFactory.createEmptyBorder());
|
||||
button.setOpaque(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JButton createArrowButton() {
|
||||
return new DarculaComboBoxButton(myComboBox);
|
||||
protected Insets getInsets() {
|
||||
return myComboBoxInsets;
|
||||
}
|
||||
|
||||
class DarculaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
|
||||
public void layoutContainer(final Container parent) {
|
||||
if (arrowButton != null && !comboBox.isEditable()) {
|
||||
final Insets insets = comboBox.getInsets();
|
||||
final int width = comboBox.getWidth();
|
||||
final int height = comboBox.getHeight();
|
||||
arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom));
|
||||
return;
|
||||
}
|
||||
|
||||
final JComboBox cb = (JComboBox)parent;
|
||||
final int width = cb.getWidth();
|
||||
final int height = cb.getHeight();
|
||||
|
||||
final Insets insets = getInsets();
|
||||
final int buttonHeight = height - (insets.top + insets.bottom);
|
||||
final int buttonWidth = 20;
|
||||
|
||||
if (arrowButton != null) {
|
||||
arrowButton.setBounds(width - (insets.right + buttonWidth), insets.top, buttonWidth, buttonHeight);
|
||||
}
|
||||
|
||||
if (editor != null) {
|
||||
final Rectangle editorRect = rectangleForCurrentValue();
|
||||
editorRect.width += 4;
|
||||
editor.setBounds(editorRect);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void paintBorder(Component c, Graphics g2, int x, int y, int width, int height) {
|
||||
final Graphics2D g = (Graphics2D)g2;
|
||||
if (hasFocus || (editor != null && editor.hasFocus())) {
|
||||
DarculaUIUtil.paintFocusRing(g, 2, 2, width - 4, height - 4);
|
||||
} else {
|
||||
g.setColor(ColorUtil.fromHex("939393"));
|
||||
final GraphicsConfig config = new GraphicsConfig(g);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
g.drawRoundRect(1, 1, width - 2, height - 2, 5,5);
|
||||
config.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets(Component c) {
|
||||
return myComboBoxInsets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBorderOpaque() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user