Search in sources :

Example 16 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig 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();
}
Also used : JBColor(com.intellij.ui.JBColor) Rectangle2D(java.awt.geom.Rectangle2D) JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 17 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig in project intellij-community by JetBrains.

the class RectanglePainter method paint.

public void paint(@NotNull Graphics2D g2, @NotNull String text, int paddingX, int paddingY, @NotNull Color color) {
    GraphicsConfig config = GraphicsUtil.setupAAPainting(g2);
    g2.setFont(getLabelFont());
    g2.setStroke(new BasicStroke(1.5f));
    FontMetrics fontMetrics = g2.getFontMetrics();
    int width = fontMetrics.stringWidth(text) + 2 * TEXT_PADDING_X;
    int height = fontMetrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;
    g2.setColor(color);
    if (mySquare) {
        g2.fillRect(paddingX, paddingY, width, height);
    } else {
        g2.fill(new RoundRectangle2D.Double(paddingX, paddingY, width, height, LABEL_ARC, LABEL_ARC));
    }
    g2.setColor(JBColor.BLACK);
    int x = paddingX + TEXT_PADDING_X;
    int y = paddingY + SimpleColoredComponent.getTextBaseLine(fontMetrics, height);
    g2.drawString(text, x, y);
    config.restore();
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 18 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig in project intellij-community by JetBrains.

the class ProgressStripeIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    Graphics2D g2 = (Graphics2D) g;
    int shift = myShift - getChunkWidth();
    while (shift < getIconWidth()) {
        paint(g2, x, y, shift);
        shift += getChunkWidth();
    }
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 19 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig in project android by JetBrains.

the class StatefulButtonUI method paint.

@Override
public void paint(Graphics g, JComponent c) {
    int w = c.getWidth();
    int h = c.getHeight();
    if (isHelpButton(c)) {
        ((Graphics2D) g).setPaint(UIUtil.getGradientPaint(0, 0, getButtonColor1(), 0, h, getButtonColor2()));
        int off = JBUI.scale(22);
        int x = (w - off) / 2;
        int y = (h - off) / 2;
        g.fillOval(x, y, off, off);
        AllIcons.Actions.Help.paintIcon(c, g, x + JBUI.scale(3), y + JBUI.scale(3));
    } else {
        final Border border = c.getBorder();
        final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
        final boolean square = isSquare(c);
        if (c.isEnabled() && border != null) {
            final Insets ins = border.getBorderInsets(c);
            final int yOff = (ins.top + ins.bottom) / 4;
            if (!square) {
                if (isDefaultButton(c)) {
                    ((Graphics2D) g).setPaint(UIUtil.getGradientPaint(0, 0, getSelectedButtonColor1(), 0, h, getSelectedButtonColor2()));
                } else {
                    ((Graphics2D) g).setPaint(UIUtil.getGradientPaint(0, 0, getButtonColor1(), 0, h, getButtonColor2()));
                }
            }
            int rad = JBUI.scale(square ? 3 : 5);
            g.fillRoundRect(JBUI.scale(square ? 2 : 4), yOff, w - 2 * JBUI.scale(4), h - 2 * yOff, rad, rad);
        }
        config.restore();
        super.paint(g, c);
    }
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) Border(javax.swing.border.Border)

Example 20 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig in project intellij-community by JetBrains.

the class DiffDividerDrawUtil method paintPolygons.

public static void paintPolygons(@NotNull Graphics2D gg, int width, boolean paintBorder, boolean curved, @NotNull Editor editor1, @NotNull Editor editor2, @NotNull DividerPaintable paintable) {
    List<DividerPolygon> polygons = createVisiblePolygons(editor1, editor2, paintable);
    GraphicsConfig config = GraphicsUtil.setupAAPainting(gg);
    for (DividerPolygon polygon : polygons) {
        polygon.paint(gg, width, paintBorder, curved);
    }
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Aggregations

GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)38 JBColor (com.intellij.ui.JBColor)10 Border (javax.swing.border.Border)5 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 JBGradientPaint (com.intellij.ui.JBGradientPaint)2 Path2D (java.awt.geom.Path2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BasicArrowButton (javax.swing.plaf.basic.BasicArrowButton)2 JTextComponent (javax.swing.text.JTextComponent)2 SettingsDialog (com.intellij.openapi.options.newEditor.SettingsDialog)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 JBInsets (com.intellij.util.ui.JBInsets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Area (java.awt.geom.Area)1 CompoundBorder (javax.swing.border.CompoundBorder)1 EmptyBorder (javax.swing.border.EmptyBorder)1 DimensionUIResource (javax.swing.plaf.DimensionUIResource)1 UIResource (javax.swing.plaf.UIResource)1 BasicTreeUI (javax.swing.plaf.basic.BasicTreeUI)1