Search in sources :

Example 6 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 7 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 8 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)

Example 9 with GraphicsConfig

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

the class DarculaTableHeaderUI method paint.

@Override
public void paint(Graphics g2, JComponent c) {
    final Graphics2D g = (Graphics2D) g2;
    final GraphicsConfig config = new GraphicsConfig(g);
    final Color bg = c.getBackground();
    g.setPaint(new GradientPaint(0, 0, ColorUtil.shift(bg, 1.4), 0, c.getHeight(), ColorUtil.shift(bg, 0.9)));
    final int h = c.getHeight();
    final int w = c.getWidth();
    g.fillRect(0, 0, w, h);
    g.setPaint(ColorUtil.shift(bg, 0.75));
    g.drawLine(0, h - 1, w, h - 1);
    g.drawLine(w - 1, 0, w - 1, h - 1);
    final Enumeration<TableColumn> columns = ((JTableHeader) c).getColumnModel().getColumns();
    final Color lineColor = ColorUtil.shift(bg, 0.7);
    final Color shadow = Gray._255.withAlpha(30);
    int offset = 0;
    while (columns.hasMoreElements()) {
        final TableColumn column = columns.nextElement();
        if (columns.hasMoreElements() && column.getWidth() > 0) {
            offset += column.getWidth();
            g.setColor(lineColor);
            g.drawLine(offset - 1, 1, offset - 1, h - 3);
            g.setColor(shadow);
            g.drawLine(offset, 1, offset, h - 3);
        }
    }
    config.restore();
    super.paint(g, c);
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) TableColumn(javax.swing.table.TableColumn)

Example 10 with GraphicsConfig

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

the class DarculaButtonPainter method paintBorder.

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    final Graphics2D g2d = (Graphics2D) g;
    final Insets ins = getBorderInsets(c);
    final int yOff = (ins.top + ins.bottom) / 4;
    final boolean square = DarculaButtonUI.isSquare(c);
    int offset = JBUI.scale(square ? 1 : getOffset());
    int w = c.getWidth();
    int h = c.getHeight();
    int diam = JBUI.scale(22);
    if (c.hasFocus()) {
        if (DarculaButtonUI.isHelpButton((JComponent) c)) {
            DarculaUIUtil.paintFocusOval(g2d, (w - diam) / 2, (h - diam) / 2, diam, diam);
        } else {
            DarculaUIUtil.paintFocusRing(g2d, new Rectangle(offset, yOff, width - 2 * offset, height - 2 * yOff));
        }
    } else {
        final GraphicsConfig config = new GraphicsConfig(g);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g2d.setPaint(UIUtil.getGradientPaint(width / 2, y + yOff + JBUI.scale(1), Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90)));
        //g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);
        ((Graphics2D) g).setPaint(getBorderColor());
        if (DarculaButtonUI.isHelpButton((JComponent) c)) {
            g.drawOval((w - diam) / 2, (h - diam) / 2, diam, diam);
        } else {
            g.translate(x, y);
            int r = JBUI.scale(square ? 3 : 5);
            g.drawRoundRect(offset, yOff, width - 2 * offset, height - 2 * yOff, r, r);
            g.translate(-x, -y);
        }
        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