Search in sources :

Example 1 with JBGradientPaint

use of com.intellij.ui.JBGradientPaint 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 2 with JBGradientPaint

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

the class DarculaRadioButtonUI method paintIcon.

protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) {
    Insets i = c.getInsets();
    viewRect.x += i.left;
    viewRect.y += i.top;
    viewRect.width -= (i.right + viewRect.x);
    viewRect.height -= (i.bottom + viewRect.y);
    int rad = JBUI.scale(5);
    // Paint the radio button
    final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int w = iconRect.width - rad;
    final int h = iconRect.height - rad;
    g.translate(x, y);
    //noinspection UseJBColor
    final JBGradientPaint ijGradient = new JBGradientPaint(c, new Color(0x4985e4), new Color(0x4074c9));
    //setup AA for lines
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    final boolean focus = c.hasFocus();
    final boolean selected = ((AbstractButton) c).isSelected();
    if (UIUtil.isUnderDarcula() || !selected) {
        g.setPaint(UIUtil.getGradientPaint(0, 0, ColorUtil.shift(c.getBackground(), 1.5), 0, c.getHeight(), ColorUtil.shift(c.getBackground(), 1.2)));
    } else {
        g.setPaint(ijGradient);
    }
    if (!UIUtil.isUnderDarcula() && selected) {
        final GraphicsConfig fillOvalConf = new GraphicsConfig(g);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g.fillOval(0, JBUI.scale(1), w, h);
        fillOvalConf.restore();
    } else {
        if (focus) {
            g.fillOval(0, JBUI.scale(1), w, h);
        } else {
            g.fillOval(0, JBUI.scale(1), w - JBUI.scale(1), h - JBUI.scale(1));
        }
    }
    if (focus) {
        if (JBUI.isPixHiDPI(c)) {
            DarculaUIUtil.paintFocusOval(g, JBUI.scale(1), JBUI.scale(1) + 1, w - JBUI.scale(2), h - JBUI.scale(2));
        } else {
            DarculaUIUtil.paintFocusOval(g, 0, JBUI.scale(1), w, h);
        }
    } else {
        if (UIUtil.isUnderDarcula()) {
            g.setPaint(UIUtil.getGradientPaint(w / 2, 1, Gray._160.withAlpha(90), w / 2, h, Gray._100.withAlpha(90)));
            g.drawOval(0, JBUI.scale(1) + 1, w - 1, h - 1);
            g.setPaint(Gray._40.withAlpha(200));
            g.drawOval(0, JBUI.scale(1), w - 1, h - 1);
        } else {
            g.setPaint(selected ? ijGradient : c.isEnabled() ? Gray._30 : Gray._130);
            if (!selected) {
                g.drawOval(0, JBUI.scale(1), w - 1, h - 1);
            }
        }
    }
    if (selected) {
        final boolean enabled = c.isEnabled();
        // ? Gray._30 : Gray._60);
        g.setColor(UIManager.getColor(enabled ? "RadioButton.darcula.selectionEnabledShadowColor" : "RadioButton.darcula.selectionDisabledShadowColor"));
        final int yOff = 1 + JBUI.scale(1);
        g.fillOval(w / 2 - rad / 2, h / 2 - rad / 2 + yOff, rad, rad);
        //Gray._170 : Gray._120);
        g.setColor(UIManager.getColor(enabled ? "RadioButton.darcula.selectionEnabledColor" : "RadioButton.darcula.selectionDisabledColor"));
        g.fillOval(w / 2 - rad / 2, h / 2 - rad / 2 - 1 + yOff, rad, rad);
    }
    config.restore();
    g.translate(-x, -y);
}
Also used : JBGradientPaint(com.intellij.ui.JBGradientPaint) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) JBGradientPaint(com.intellij.ui.JBGradientPaint)

Aggregations

GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)2 JBGradientPaint (com.intellij.ui.JBGradientPaint)2 SettingsDialog (com.intellij.openapi.options.newEditor.SettingsDialog)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 JBColor (com.intellij.ui.JBColor)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1