mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
spinner ui for darcula
(cherry-picked from 8d24a66)
This commit is contained in:
+12
-6
@@ -16,7 +16,9 @@
|
||||
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.Gray;
|
||||
import com.intellij.util.ui.GraphicsUtil;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
@@ -29,7 +31,6 @@ import java.awt.*;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class DarculaSpinnerBorder implements Border, UIResource {
|
||||
private JBInsets myInsets = new JBInsets(6, 7, 6, 7);
|
||||
|
||||
@Override
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
@@ -39,30 +40,35 @@ public class DarculaSpinnerBorder implements Border, UIResource {
|
||||
final int y1 = y + 3;
|
||||
final int width1 = width - 8;
|
||||
final int height1 = height - 6;
|
||||
final boolean focused = c.isEnabled() && c.isVisible() && editor != null && editor.hasFocus();
|
||||
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
|
||||
|
||||
if (c.isOpaque()) {
|
||||
g.setColor(UIUtil.getPanelBackground());
|
||||
g.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
g.setColor(c.getBackground());
|
||||
g.fillRect(x1, y1, width1, height1);
|
||||
g.setColor(UIUtil.getTextFieldBackground());
|
||||
g.fillRoundRect(x1, y1, width1, height1, 5, 5);
|
||||
g.setColor(UIUtil.getPanelBackground());
|
||||
g.fillRect(x1 + width1 - 17, y1, 17, height1);
|
||||
|
||||
if (!c.isEnabled()) {
|
||||
((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
||||
}
|
||||
|
||||
if (c.isEnabled() && c.isVisible() && editor != null && editor.hasFocus()) {
|
||||
if (focused) {
|
||||
DarculaUIUtil.paintFocusRing(g, x1, y1, width1, height1);
|
||||
} else {
|
||||
g.setColor(Gray._100);
|
||||
g.drawRect(x1, y1, width1, height1);
|
||||
g.drawRoundRect(x1, y1, width1, height1, 5, 5);
|
||||
}
|
||||
config.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets(Component c) {
|
||||
return myInsets;
|
||||
return new JBInsets(6, 7, 6, 7);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+65
-4
@@ -15,9 +15,18 @@
|
||||
*/
|
||||
package com.intellij.ide.ui.laf.darcula.ui;
|
||||
|
||||
import com.intellij.openapi.ui.GraphicsConfig;
|
||||
import com.intellij.util.ui.GraphicsUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
import javax.swing.plaf.basic.BasicSpinnerUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusAdapter;
|
||||
@@ -69,15 +78,67 @@ public class DarculaSpinnerUI extends BasicSpinnerUI {
|
||||
|
||||
@Override
|
||||
protected Component createPreviousButton() {
|
||||
final JComponent button = (JComponent)super.createPreviousButton();
|
||||
button.setBorder(new EmptyBorder(1,1,1,1));
|
||||
JButton button = createArrow(SwingConstants.SOUTH);
|
||||
button.setName("Spinner.nextButton");
|
||||
button.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||
|
||||
installNextButtonListeners(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component createNextButton() {
|
||||
final JComponent button = (JComponent)super.createNextButton();
|
||||
button.setBorder(new EmptyBorder(1,1,1,1));
|
||||
JButton button = createArrow(SwingConstants.NORTH);
|
||||
button.setName("Spinner.nextButton");
|
||||
button.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||
|
||||
installNextButtonListeners(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
private static JButton createArrow(@MagicConstant(intValues = {SwingConstants.NORTH, SwingConstants.SOUTH}) int direction) {
|
||||
final Color shadow = UIUtil.getPanelBackground();
|
||||
final Color darkShadow = UIUtil.getLabelForeground();
|
||||
JButton b = new BasicArrowButton(direction, shadow, shadow, darkShadow, shadow) {
|
||||
@Override
|
||||
public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
|
||||
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
|
||||
int mid;
|
||||
x = 5;
|
||||
y = 2;
|
||||
final int w = getWidth() - 1 - x - 2;
|
||||
final int h = getHeight() - 1 - 1;
|
||||
mid = (w + 1) / 2;
|
||||
g.setColor(UIUtil.getPanelBackground());
|
||||
g.fillRect(1, 1, getWidth() - 1, getHeight() - 1);
|
||||
|
||||
g.setColor(isEnabled ? darkShadow : darkShadow.darker());
|
||||
|
||||
g.translate(x, y);
|
||||
switch (direction) {
|
||||
case SOUTH:
|
||||
g.fillPolygon(new int[]{0, w, mid}, new int[]{1, 1, h}, 3);
|
||||
break;
|
||||
case NORTH:
|
||||
g.fillPolygon(new int[]{0, w, mid}, new int[]{h - 1, h - 1, 0}, 3);
|
||||
break;
|
||||
case WEST:
|
||||
case EAST:
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
config.restore();
|
||||
}
|
||||
};
|
||||
Border buttonBorder = UIManager.getBorder("Spinner.arrowButtonBorder");
|
||||
if (buttonBorder instanceof UIResource) {
|
||||
// Wrap the border to avoid having the UIResource be replaced by
|
||||
// the ButtonUI. This is the opposite of using BorderUIResource.
|
||||
b.setBorder(new CompoundBorder(buttonBorder, null));
|
||||
}
|
||||
else {
|
||||
b.setBorder(buttonBorder);
|
||||
}
|
||||
b.setInheritsPopupMenu(true);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user