Search in sources :

Example 31 with GraphicsConfig

use of com.intellij.openapi.ui.GraphicsConfig 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)

Example 32 with GraphicsConfig

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

the class DarculaTextFieldUI method paintBackground.

@Override
protected void paintBackground(Graphics graphics) {
    Graphics2D g = (Graphics2D) graphics;
    final JTextComponent c = getComponent();
    final Container parent = c.getParent();
    final Rectangle r = getDrawingRect();
    if (c.isOpaque() && parent != null) {
        g.setColor(parent.getBackground());
        g.fillRect(0, 0, c.getWidth(), c.getHeight());
    }
    final GraphicsConfig config = new GraphicsConfig(g);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    final Border border = c.getBorder();
    if (isSearchField(c)) {
        paintSearchField(g, c, r);
    } else if (border instanceof DarculaTextBorder) {
        paintDarculaBackground(g, c, border);
    } else {
        super.paintBackground(g);
    }
    config.restore();
}
Also used : JTextComponent(javax.swing.text.JTextComponent) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) Border(javax.swing.border.Border)

Example 33 with GraphicsConfig

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

the class DarculaButtonUI method paintDecorations.

/**
   * Paints additional buttons decorations
   * @param g Graphics
   * @param c button component
   * @return <code>true</code> if it is allowed to continue painting,
   *         <code>false</code> if painting should be stopped
   */
protected boolean paintDecorations(Graphics2D g, JComponent c) {
    int w = c.getWidth();
    int h = c.getHeight();
    if (isHelpButton(c)) {
        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));
        return false;
    } 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)) {
                    g.setPaint(UIUtil.getGradientPaint(0, 0, getSelectedButtonColor1(), 0, h, getSelectedButtonColor2()));
                } else {
                    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();
        return true;
    }
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) Border(javax.swing.border.Border)

Example 34 with GraphicsConfig

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

the class Tree method paintFileColorGutter.

protected void paintFileColorGutter(final Graphics g) {
    final GraphicsConfig config = new GraphicsConfig(g);
    final Rectangle rect = getVisibleRect();
    final int firstVisibleRow = getClosestRowForLocation(rect.x, rect.y);
    final int lastVisibleRow = getClosestRowForLocation(rect.x, rect.y + rect.height);
    for (int row = firstVisibleRow; row <= lastVisibleRow; row++) {
        final TreePath path = getPathForRow(row);
        if (path != null) {
            final Rectangle bounds = getRowBounds(row);
            Object component = path.getLastPathComponent();
            final Object[] pathObjects = path.getPath();
            if (component instanceof LoadingNode && pathObjects.length > 1) {
                component = pathObjects[pathObjects.length - 2];
            }
            Color color = getFileColorFor((DefaultMutableTreeNode) component);
            if (color != null) {
                g.setColor(color);
                g.fillRect(0, bounds.y, getWidth(), bounds.height);
            }
        }
    }
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 35 with GraphicsConfig

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

the class Tree method paintNodeContent.

private void paintNodeContent(Graphics g) {
    if (!(getUI() instanceof BasicTreeUI))
        return;
    final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(this);
    if (builder == null || builder.isDisposed())
        return;
    GraphicsConfig config = new GraphicsConfig(g);
    config.setAntialiasing(true);
    final AbstractTreeStructure structure = builder.getTreeStructure();
    for (int eachRow = 0; eachRow < getRowCount(); eachRow++) {
        final TreePath path = getPathForRow(eachRow);
        PresentableNodeDescriptor node = toPresentableNode(path.getLastPathComponent());
        if (node == null)
            continue;
        if (!node.isContentHighlighted())
            continue;
        if (highlightSingleNode()) {
            if (node.isContentHighlighted()) {
                final TreePath nodePath = getPath(node);
                Rectangle rect;
                final Rectangle parentRect = getPathBounds(nodePath);
                if (isExpanded(nodePath)) {
                    final int[] max = getMax(node, structure);
                    rect = new Rectangle(parentRect.x, parentRect.y, Math.max((int) parentRect.getMaxX(), max[1]) - parentRect.x - 1, Math.max((int) parentRect.getMaxY(), max[0]) - parentRect.y - 1);
                } else {
                    rect = parentRect;
                }
                if (rect != null) {
                    final Color highlightColor = node.getHighlightColor();
                    g.setColor(highlightColor);
                    g.fillRoundRect(rect.x, rect.y, rect.width, rect.height, 4, 4);
                    g.setColor(highlightColor.darker());
                    g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 4, 4);
                }
            }
        } else {
            //todo: to investigate why it might happen under 1.6: http://www.productiveme.net:8080/browse/PM-217
            if (node.getParentDescriptor() == null)
                continue;
            final Object[] kids = structure.getChildElements(node);
            if (kids.length == 0)
                continue;
            PresentableNodeDescriptor first = null;
            PresentableNodeDescriptor last = null;
            int lastIndex = -1;
            for (int i = 0; i < kids.length; i++) {
                final Object kid = kids[i];
                if (kid instanceof PresentableNodeDescriptor) {
                    PresentableNodeDescriptor eachKid = (PresentableNodeDescriptor) kid;
                    if (!node.isHighlightableContentNode(eachKid))
                        continue;
                    if (first == null) {
                        first = eachKid;
                    }
                    last = eachKid;
                    lastIndex = i;
                }
            }
            if (first == null || last == null)
                continue;
            Rectangle firstBounds = getPathBounds(getPath(first));
            if (isExpanded(getPath(last))) {
                if (lastIndex + 1 < kids.length) {
                    final Object child = kids[lastIndex + 1];
                    if (child instanceof PresentableNodeDescriptor) {
                        PresentableNodeDescriptor nextKid = (PresentableNodeDescriptor) child;
                        int nextRow = getRowForPath(getPath(nextKid));
                        last = toPresentableNode(getPathForRow(nextRow - 1).getLastPathComponent());
                    }
                } else {
                    NodeDescriptor parentNode = node.getParentDescriptor();
                    if (parentNode instanceof PresentableNodeDescriptor) {
                        final PresentableNodeDescriptor ppd = (PresentableNodeDescriptor) parentNode;
                        int nodeIndex = node.getIndex();
                        if (nodeIndex + 1 < structure.getChildElements(ppd).length) {
                            PresentableNodeDescriptor nextChild = ppd.getChildToHighlightAt(nodeIndex + 1);
                            int nextRow = getRowForPath(getPath(nextChild));
                            TreePath prevPath = getPathForRow(nextRow - 1);
                            if (prevPath != null) {
                                last = toPresentableNode(prevPath.getLastPathComponent());
                            }
                        } else {
                            int lastRow = getRowForPath(getPath(last));
                            PresentableNodeDescriptor lastParent = last;
                            boolean lastWasFound = false;
                            for (int i = lastRow + 1; i < getRowCount(); i++) {
                                PresentableNodeDescriptor eachNode = toPresentableNode(getPathForRow(i).getLastPathComponent());
                                if (!node.isParentOf(eachNode)) {
                                    last = lastParent;
                                    lastWasFound = true;
                                    break;
                                }
                                lastParent = eachNode;
                            }
                            if (!lastWasFound) {
                                last = toPresentableNode(getPathForRow(getRowCount() - 1).getLastPathComponent());
                            }
                        }
                    }
                }
            }
            if (last == null)
                continue;
            Rectangle lastBounds = getPathBounds(getPath(last));
            if (firstBounds == null || lastBounds == null)
                continue;
            Rectangle toPaint = new Rectangle(firstBounds.x, firstBounds.y, 0, (int) lastBounds.getMaxY() - firstBounds.y - 1);
            toPaint.width = getWidth() - toPaint.x - 4;
            final Color highlightColor = first.getHighlightColor();
            g.setColor(highlightColor);
            g.fillRoundRect(toPaint.x, toPaint.y, toPaint.width, toPaint.height, 4, 4);
            g.setColor(highlightColor.darker());
            g.drawRoundRect(toPaint.x, toPaint.y, toPaint.width, toPaint.height, 4, 4);
        }
    }
    config.restore();
}
Also used : GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI)

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