use of com.intellij.ui.JBColor in project intellij-community by JetBrains.
the class DarculaSpinnerBorder method paintBorder.
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
final JSpinner spinner = (JSpinner) c;
final JFormattedTextField editor = UIUtil.findComponentOfType(spinner, JFormattedTextField.class);
final int x1 = x + 1;
final int y1 = y + 3;
final int width1 = width - 2;
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(UIUtil.getTextFieldBackground());
g.fillRoundRect(x1, y1, width1, height1, 5, 5);
g.setColor(UIManager.getColor(spinner.isEnabled() ? "Spinner.darcula.enabledButtonColor" : "Spinner.darcula.disabledButtonColor"));
if (editor != null) {
final int off = editor.getBounds().x + editor.getWidth() + ((JSpinner) c).getInsets().left + 1;
final Area rect = new Area(new RoundRectangle2D.Double(x1, y1, width1, height1, 5, 5));
final Area blueRect = new Area(new Rectangle(off, y1, 22, height1));
rect.intersect(blueRect);
((Graphics2D) g).fill(rect);
if (UIUtil.isUnderDarcula()) {
g.setColor(Gray._100);
g.drawLine(off, y1, off, height1 + 2);
}
}
if (!c.isEnabled()) {
((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
}
if (focused) {
DarculaUIUtil.paintFocusRing(g, new Rectangle(x1 + 2, y1, width1 - 3, height1));
} else {
g.setColor(new JBColor(Gray._149, Gray._100));
g.drawRoundRect(x1, y1, width1, height1, 5, 5);
}
config.restore();
}
use of com.intellij.ui.JBColor in project intellij-community by JetBrains.
the class DarculaSpinnerUI method createArrow.
private JButton createArrow(@MagicConstant(intValues = { SwingConstants.NORTH, SwingConstants.SOUTH }) int direction) {
final Color shadow = UIUtil.getPanelBackground();
final Color enabledColor = new JBColor(Gray._255, UIUtil.getLabelForeground());
final Color disabledColor = new JBColor(Gray._200, UIUtil.getLabelForeground().darker());
BasicArrowButton b = new BasicArrowButton(direction, shadow, shadow, enabledColor, shadow) {
@Override
public void paint(Graphics g) {
paintArrowButton(g, this, direction);
}
@Override
public boolean isOpaque() {
return false;
}
@Override
public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
int mid;
final int w = 8;
final int h = 6;
mid = w / 2;
g.setColor(isEnabled ? enabledColor : disabledColor);
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;
}
use of com.intellij.ui.JBColor in project intellij-community by JetBrains.
the class ColorProgressBar method paintComponent.
protected void paintComponent(Graphics g) {
super.paintComponent(g);
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
Graphics2D g2 = (Graphics2D) g;
if (myFraction > 1) {
myFraction = 1;
}
Dimension size = getSize();
g2.setPaint(UIUtil.getListBackground());
Rectangle2D rect = new Rectangle2D.Double(2, 2, size.width - 4, size.height - 4);
g2.fill(rect);
g2.setPaint(new JBColor(SHADOW1, UIUtil.getBorderColor()));
rect.setRect(1, 1, size.width - 2, size.height - 2);
g2.drawRoundRect(1, 1, size.width - 2, size.height - 2, 5, 5);
g2.setPaint(SHADOW2);
g2.drawRoundRect(0, 0, size.width - 2, size.height - 2, 5, 5);
int y_center = size.height / 2;
int y_steps = size.height / 2 - 3;
int alpha_step = y_steps > 0 ? (255 - 70) / y_steps : 255 - 70;
int x_offset = 4;
g.setClip(4, 3, size.width - 8, size.height - 6);
int bricksToDraw = myFraction == 0 ? 0 : getBricksToDraw(myFraction);
if (myIndeterminate) {
int startFrom = bricksToDraw < INDETERMINATE_BRICKS_DRAW ? 0 : bricksToDraw - INDETERMINATE_BRICKS_DRAW;
int endTo = bricksToDraw + INDETERMINATE_BRICKS_DRAW < getBricksToDraw(1) ? bricksToDraw + INDETERMINATE_BRICKS_DRAW : getBricksToDraw(1);
for (int i = startFrom; i <= endTo; i++) {
g2.setPaint(myColor);
int startXOffset = x_offset + (BRICK_WIDTH + BRICK_SPACE) * i;
UIUtil.drawLine(g2, startXOffset, y_center, startXOffset + BRICK_WIDTH - 1, y_center);
for (int j = 0; j < y_steps; j++) {
Color color = ColorUtil.toAlpha(myColor, 255 - alpha_step * (j + 1));
g2.setPaint(color);
UIUtil.drawLine(g2, startXOffset, y_center - 1 - j, startXOffset + BRICK_WIDTH - 1, y_center - 1 - j);
if (!(y_center % 2 != 0 && j == y_steps - 1)) {
UIUtil.drawLine(g2, startXOffset, y_center + 1 + j, startXOffset + BRICK_WIDTH - 1, y_center + 1 + j);
}
}
g2.setColor(ColorUtil.toAlpha(myColor, 255 - alpha_step * (y_steps / 2 + 1)));
g2.drawRect(startXOffset, y_center - y_steps, BRICK_WIDTH - 1, size.height - 7);
}
} else {
for (int i = 0; i < bricksToDraw; i++) {
g2.setPaint(myColor);
UIUtil.drawLine(g2, x_offset, y_center, x_offset + BRICK_WIDTH - 1, y_center);
for (int j = 0; j < y_steps; j++) {
Color color = ColorUtil.toAlpha(myColor, 255 - alpha_step * (j + 1));
g2.setPaint(color);
UIUtil.drawLine(g2, x_offset, y_center - 1 - j, x_offset + BRICK_WIDTH - 1, y_center - 1 - j);
if (!(y_center % 2 != 0 && j == y_steps - 1)) {
UIUtil.drawLine(g2, x_offset, y_center + 1 + j, x_offset + BRICK_WIDTH - 1, y_center + 1 + j);
}
}
g2.setColor(ColorUtil.toAlpha(myColor, 255 - alpha_step * (y_steps / 2 + 1)));
g2.drawRect(x_offset, y_center - y_steps, BRICK_WIDTH - 1, size.height - 7);
x_offset += BRICK_WIDTH + BRICK_SPACE;
}
}
config.restore();
}
use of com.intellij.ui.JBColor in project intellij-community by JetBrains.
the class DefaultColorGenerator method getColor.
@NotNull
@Override
public JBColor getColor(int branchNumber) {
JBColor color = ourColorMap.get(branchNumber);
if (color == null) {
color = calcColor(branchNumber);
ourColorMap.put(branchNumber, color);
}
return color;
}
use of com.intellij.ui.JBColor in project intellij-community by JetBrains.
the class UseJBColorInspection method checkNewExpression.
@Nullable
private static ProblemDescriptor checkNewExpression(PsiNewExpression expression, InspectionManager manager, boolean isOnTheFly) {
final Project project = manager.getProject();
final PsiType type = expression.getType();
final PsiExpressionList arguments = expression.getArgumentList();
if (type != null && arguments != null && type.equalsToText("java.awt.Color")) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final PsiClass jbColorClass = facade.findClass(JBColor.class.getName(), GlobalSearchScope.allScope(project));
if (jbColorClass != null && facade.getResolveHelper().isAccessible(jbColorClass, expression, jbColorClass)) {
final PsiElement parent = expression.getParent();
if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiNewExpression) {
final PsiType parentType = ((PsiNewExpression) parent.getParent()).getType();
if (parentType == null || JBColor.class.getName().equals(parentType.getCanonicalText()))
return null;
}
return manager.createProblemDescriptor(expression, "Replace with JBColor", new ConvertToJBColorQuickFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
}
}
return null;
}
Aggregations