Search in sources :

Example 1 with GraphicsConfig

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

the class StudyProgressBar method paintComponent.

protected void paintComponent(Graphics g) {
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    Graphics2D g2 = (Graphics2D) g;
    if (myFraction > 1) {
        myFraction = 1;
    }
    Dimension size = getSize();
    double width = size.getWidth() - 2 * myIndent;
    g2.setPaint(UIUtil.getTextFieldBackground());
    Rectangle2D rect = new Rectangle2D.Double(myIndent, 0, width, myHeight);
    g2.fill(rect);
    g2.setPaint(new JBColor(SHADOW1, JBColor.border()));
    rect.setRect(myIndent, 0, width, myHeight);
    int arcWidth = 5;
    int arcHeight = 5;
    g2.drawRoundRect(myIndent, 0, (int) width, myHeight, arcWidth, arcHeight);
    g2.setPaint(SHADOW2);
    int y_center = myHeight / 2;
    int y_steps = myHeight / 2 - 3;
    int alpha_step = y_steps > 0 ? (255 - 70) / y_steps : 255 - 70;
    int x_offset = 4;
    g.setClip(4 + myIndent, 3, (int) width - 6, myHeight - 4);
    int bricksToDraw = myFraction == 0 ? 0 : getBricksToDraw(myFraction);
    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, myHeight - 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 2 with GraphicsConfig

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

the class IdeaActionButtonLook method paintBackground.

void paintBackground(Graphics g, Dimension size, Color background, int state) {
    GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    try {
        Color bg = background == null ? JBColor.background() : background;
        if (UIUtil.isUnderAquaLookAndFeel() || (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF())) {
            if (state == ActionButtonComponent.PUSHED) {
                if (UIUtil.isUnderAquaLookAndFeel()) {
                    ((Graphics2D) g).setPaint(UIUtil.getGradientPaint(0, 0, ALPHA_40, size.width, size.height, ALPHA_20));
                    ((Graphics2D) g).fill(getShape(size));
                    g.setColor(ALPHA_30);
                    ((Graphics2D) g).draw(getShape(size));
                } else {
                    g.setColor(ColorUtil.darker(bg, 1));
                    ((Graphics2D) g).fill(getShape(size));
                    g.setColor(Gray.xC0);
                    ((Graphics2D) g).draw(getShape(size));
                }
            } else if (state == ActionButtonComponent.POPPED || state == ActionButtonComponent.SELECTED) {
                if (UIUtil.isUnderAquaLookAndFeel()) {
                    ((Graphics2D) g).setPaint(UIUtil.getGradientPaint(0, 0, bg, 0, size.height, ColorUtil.darker(bg, 2)));
                    ((Graphics2D) g).fill(getShape(size));
                } else {
                    ((Graphics2D) g).setPaint(ColorUtil.darker(bg, 1));
                    ((Graphics2D) g).fill(getShape(size));
                    g.setColor(Gray.xCC);
                    ((Graphics2D) g).draw(getShape(size));
                }
            }
        } else {
            final boolean dark = UIUtil.isUnderDarcula();
            final Color pushed = UIUtil.isUnderWin10LookAndFeel() ? Gray.xE6 : dark ? ColorUtil.shift(bg, 1.428D) : Gray.xD0;
            final Color dark_normal = Gray._255.withAlpha(40);
            g.setColor(state == ActionButtonComponent.PUSHED ? pushed : dark ? dark_normal : Gray.xD9);
            ((Graphics2D) g).fill(getShape(size));
        }
    } finally {
        config.restore();
    }
}
Also used : JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 3 with GraphicsConfig

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

the class TestTreeView method paintRowData.

private static void paintRowData(Tree tree, String duration, Rectangle bounds, Graphics2D g, boolean isSelected, boolean hasFocus) {
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.setFont(tree.getFont().deriveFont(Font.PLAIN, UIUtil.getFontSize(UIUtil.FontSize.SMALL)));
    final FontMetrics metrics = tree.getFontMetrics(g.getFont());
    int totalWidth = metrics.stringWidth(duration) + 2;
    int x = bounds.x + bounds.width - totalWidth;
    g.setColor(isSelected ? UIUtil.getTreeSelectionBackground(hasFocus) : UIUtil.getTreeBackground());
    final int leftOffset = 5;
    g.fillRect(x - leftOffset, bounds.y, totalWidth + leftOffset, bounds.height);
    g.translate(0, bounds.y - 1);
    if (isSelected) {
        if (!hasFocus && UIUtil.isUnderAquaBasedLookAndFeel()) {
            g.setColor(UIUtil.getTreeForeground());
        } else {
            g.setColor(UIUtil.getTreeSelectionForeground());
        }
    } else {
        g.setColor(new JBColor(0x808080, 0x808080));
    }
    g.drawString(duration, x, SimpleColoredComponent.getTextBaseLine(tree.getFontMetrics(tree.getFont()), bounds.height) + 1);
    g.translate(0, -bounds.y + 1);
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 4 with GraphicsConfig

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

the class UIUtil method drawHeader.

public static void drawHeader(Graphics g, int x, int width, int height, boolean active, boolean toolWindow, boolean drawTopLine, boolean drawBottomLine) {
    height++;
    GraphicsConfig config = GraphicsUtil.disableAAPainting(g);
    try {
        g.setColor(getPanelBackground());
        g.fillRect(x, 0, width, height);
        boolean jmHiDPI = isJreHiDPI((Graphics2D) g);
        if (jmHiDPI) {
            ((Graphics2D) g).setStroke(new BasicStroke(2f));
        }
        ((Graphics2D) g).setPaint(getGradientPaint(0, 0, Gray.x00.withAlpha(5), 0, height, Gray.x00.withAlpha(20)));
        g.fillRect(x, 0, width, height);
        if (active) {
            g.setColor(new Color(100, 150, 230, toolWindow ? 50 : 30));
            g.fillRect(x, 0, width, height);
        }
        g.setColor(SystemInfo.isMac && isUnderIntelliJLaF() ? Gray.xC9 : Gray.x00.withAlpha(toolWindow ? 90 : 50));
        if (drawTopLine)
            g.drawLine(x, 0, width, 0);
        if (drawBottomLine)
            g.drawLine(x, height - (jmHiDPI ? 1 : 2), width, height - (jmHiDPI ? 1 : 2));
        if (SystemInfo.isMac && isUnderIntelliJLaF()) {
            g.setColor(Gray.xC9);
        } else {
            g.setColor(isUnderDarcula() ? Gray._255.withAlpha(30) : Gray.xFF.withAlpha(100));
        }
        g.drawLine(x, 0, width, 0);
    } finally {
        config.restore();
    }
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 5 with GraphicsConfig

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

the class PluginHeaderPanel method createUIComponents.

private void createUIComponents() {
    myInstallButton = new JButton() {

        private final int TOP_BOTTOM_BORDER = JBUI.scale(2);

        private final int LEFT_RIGHT_BORDER = JBUI.scale(8);

        private final int H_GAP = JBUI.scale(4);

        private final int ICON_SIZE = getIcon().getIconWidth();

        {
            setOpaque(false);
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        @Override
        public Dimension getPreferredSize() {
            final FontMetrics metrics = getFontMetrics(getFont());
            final int textWidth = metrics.stringWidth(getText());
            final int width = LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP + textWidth + LEFT_RIGHT_BORDER;
            final int height = TOP_BOTTOM_BORDER + Math.max(ICON_SIZE, metrics.getHeight()) + TOP_BOTTOM_BORDER;
            return new Dimension(width, height);
        }

        @Override
        public void paint(Graphics g2) {
            final Graphics2D g = (Graphics2D) g2;
            final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
            final int w = g.getClipBounds().width;
            final int h = g.getClipBounds().height;
            int borderArc = JBUI.scale(7);
            int border = JBUI.scale(1);
            int buttonArc = borderArc - border;
            g.setPaint(getBackgroundBorderPaint());
            g.fillRoundRect(0, 0, w, h, borderArc, borderArc);
            g.setPaint(getBackgroundPaint());
            g.fillRoundRect(border, border, w - 2 * border, h - 2 * border, buttonArc, buttonArc);
            g.setColor(getButtonForeground());
            g.drawString(getText(), LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP, getBaseline(w, h));
            getIcon().paintIcon(this, g, LEFT_RIGHT_BORDER, (getHeight() - getIcon().getIconHeight()) / 2);
            config.restore();
        }

        private Color getButtonForeground() {
            switch(myActionId) {
                case UPDATE:
                    return new JBColor(Gray._240, Gray._210);
                case INSTALL:
                    return new JBColor(Gray._240, Gray._210);
                case RESTART:
                case UNINSTALL:
                    return new JBColor(Gray._0, Gray._210);
            }
            return new JBColor(Gray._80, Gray._60);
        }

        private Paint getBackgroundPaint() {
            switch(myActionId) {
                case UPDATE:
                    return new JBGradientPaint(this, new JBColor(0x629ee1, 0x629ee1), new JBColor(0x3a5bb5, 0x3a5bb5));
                case INSTALL:
                    return new JBGradientPaint(this, new JBColor(0x60cc69, 0x519557), new JBColor(0x326529, 0x28462f));
                case RESTART:
                case UNINSTALL:
                    return UIUtil.isUnderDarcula() ? new JBGradientPaint(this, UIManager.getColor("Button.darcula.color1"), UIManager.getColor("Button.darcula.color2")) : Gray._240;
            }
            return Gray._238;
        }

        private Paint getBackgroundBorderPaint() {
            switch(myActionId) {
                case UPDATE:
                    return new JBColor(new Color(0xa6b4cd), Gray._85);
                case INSTALL:
                    return new JBColor(new Color(201, 223, 201), Gray._70);
                case RESTART:
                case UNINSTALL:
                    return new JBColor(Gray._220, Gray._100.withAlpha(180));
            }
            return Gray._208;
        }

        @Override
        public String getText() {
            switch(myActionId) {
                case UPDATE:
                    return "Update";
                case INSTALL:
                    return "Install";
                case UNINSTALL:
                    return "Uninstall";
                case RESTART:
                    return "Restart " + ApplicationNamesInfo.getInstance().getFullProductName();
            }
            return super.getText();
        }

        @Override
        public Icon getIcon() {
            switch(myActionId) {
                case UPDATE:
                    return AllIcons.General.DownloadPlugin;
                case INSTALL:
                    return AllIcons.General.DownloadPlugin;
                case UNINSTALL:
                    return AllIcons.Actions.Delete;
                case RESTART:
                    return AllIcons.Actions.Restart;
            }
            return super.getIcon();
        }
    };
    myInstallButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            switch(myActionId) {
                case UPDATE:
                case INSTALL:
                    Runnable setPlugin = () -> setPlugin(myPlugin);
                    new InstallPluginAction(myManager.getAvailable(), myManager.getInstalled()).install(setPlugin, setPlugin, true);
                    break;
                case UNINSTALL:
                    UninstallPluginAction.uninstall(myManager.getInstalled(), true, myPlugin);
                    break;
                case RESTART:
                    if (myManager != null) {
                        myManager.apply();
                    }
                    final DialogWrapper dialog = DialogWrapper.findInstance(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
                    if (dialog != null && dialog.isModal()) {
                        dialog.close(DialogWrapper.OK_EXIT_CODE);
                    }
                    TransactionGuard.getInstance().submitTransactionLater(ApplicationManager.getApplication(), () -> {
                        DialogWrapper settings = DialogWrapper.findInstance(IdeFocusManager.findInstance().getFocusOwner());
                        if (settings instanceof SettingsDialog) {
                            ((SettingsDialog) settings).doOKAction();
                        }
                        ApplicationManager.getApplication().restart();
                    });
                    break;
            }
            setPlugin(myPlugin);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) JBGradientPaint(com.intellij.ui.JBGradientPaint) JBGradientPaint(com.intellij.ui.JBGradientPaint) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) SettingsDialog(com.intellij.openapi.options.newEditor.SettingsDialog) ActionListener(java.awt.event.ActionListener) JBGradientPaint(com.intellij.ui.JBGradientPaint) JBColor(com.intellij.ui.JBColor)

Aggregations

GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)39 JBColor (com.intellij.ui.JBColor)11 Border (javax.swing.border.Border)5 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 Path2D (java.awt.geom.Path2D)3 BasicArrowButton (javax.swing.plaf.basic.BasicArrowButton)3 JBGradientPaint (com.intellij.ui.JBGradientPaint)2 Rectangle2D (java.awt.geom.Rectangle2D)2 JTextComponent (javax.swing.text.JTextComponent)2 SettingsDialog (com.intellij.openapi.options.newEditor.SettingsDialog)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 JBInsets (com.intellij.util.ui.JBInsets)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1