Search in sources :

Example 16 with JBColor

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

the class DarculaSpinnerBorder method paintBorder.

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    final JSpinner spinner = (JSpinner) c;
    final JFormattedTextField editor = UIUtil.findComponentOfType(spinner, JFormattedTextField.class);
    final int x1 = x + 1;
    final int y1 = y + 3;
    final int width1 = width - 2;
    final int height1 = height - 6;
    final boolean focused = c.isEnabled() && c.isVisible() && editor != null && editor.hasFocus();
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    if (c.isOpaque()) {
        g.setColor(UIUtil.getPanelBackground());
        g.fillRect(x, y, width, height);
    }
    g.setColor(UIUtil.getTextFieldBackground());
    g.fillRoundRect(x1, y1, width1, height1, 5, 5);
    g.setColor(UIManager.getColor(spinner.isEnabled() ? "Spinner.darcula.enabledButtonColor" : "Spinner.darcula.disabledButtonColor"));
    if (editor != null) {
        final int off = editor.getBounds().x + editor.getWidth() + ((JSpinner) c).getInsets().left + 1;
        final Area rect = new Area(new RoundRectangle2D.Double(x1, y1, width1, height1, 5, 5));
        final Area blueRect = new Area(new Rectangle(off, y1, 22, height1));
        rect.intersect(blueRect);
        ((Graphics2D) g).fill(rect);
        if (UIUtil.isUnderDarcula()) {
            g.setColor(Gray._100);
            g.drawLine(off, y1, off, height1 + 2);
        }
    }
    if (!c.isEnabled()) {
        ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    }
    if (focused) {
        DarculaUIUtil.paintFocusRing(g, new Rectangle(x1 + 2, y1, width1 - 3, height1));
    } else {
        g.setColor(new JBColor(Gray._149, Gray._100));
        g.drawRoundRect(x1, y1, width1, height1, 5, 5);
    }
    config.restore();
}
Also used : Area(java.awt.geom.Area) RoundRectangle2D(java.awt.geom.RoundRectangle2D) JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig)

Example 17 with JBColor

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

the class DarculaSpinnerUI method createArrow.

private JButton createArrow(@MagicConstant(intValues = { SwingConstants.NORTH, SwingConstants.SOUTH }) int direction) {
    final Color shadow = UIUtil.getPanelBackground();
    final Color enabledColor = new JBColor(Gray._255, UIUtil.getLabelForeground());
    final Color disabledColor = new JBColor(Gray._200, UIUtil.getLabelForeground().darker());
    BasicArrowButton b = new BasicArrowButton(direction, shadow, shadow, enabledColor, shadow) {

        @Override
        public void paint(Graphics g) {
            paintArrowButton(g, this, direction);
        }

        @Override
        public boolean isOpaque() {
            return false;
        }

        @Override
        public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
            final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
            int mid;
            final int w = 8;
            final int h = 6;
            mid = w / 2;
            g.setColor(isEnabled ? enabledColor : disabledColor);
            g.translate(x, y);
            switch(direction) {
                case SOUTH:
                    g.fillPolygon(new int[] { 0, w, mid }, new int[] { 1, 1, h }, 3);
                    break;
                case NORTH:
                    g.fillPolygon(new int[] { 0, w, mid }, new int[] { h - 1, h - 1, 0 }, 3);
                    break;
                case WEST:
                case EAST:
            }
            g.translate(-x, -y);
            config.restore();
        }
    };
    Border buttonBorder = UIManager.getBorder("Spinner.arrowButtonBorder");
    if (buttonBorder instanceof UIResource) {
        // Wrap the border to avoid having the UIResource be replaced by
        // the ButtonUI. This is the opposite of using BorderUIResource.
        b.setBorder(new CompoundBorder(buttonBorder, null));
    } else {
        b.setBorder(buttonBorder);
    }
    b.setInheritsPopupMenu(true);
    return b;
}
Also used : BasicArrowButton(javax.swing.plaf.basic.BasicArrowButton) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) CompoundBorder(javax.swing.border.CompoundBorder) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) UIResource(javax.swing.plaf.UIResource)

Example 18 with JBColor

use of com.intellij.ui.JBColor 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 19 with JBColor

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

the class DefaultColorGenerator method getColor.

@NotNull
@Override
public JBColor getColor(int branchNumber) {
    JBColor color = ourColorMap.get(branchNumber);
    if (color == null) {
        color = calcColor(branchNumber);
        ourColorMap.put(branchNumber, color);
    }
    return color;
}
Also used : JBColor(com.intellij.ui.JBColor) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with JBColor

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

the class UseJBColorInspection method checkNewExpression.

@Nullable
private static ProblemDescriptor checkNewExpression(PsiNewExpression expression, InspectionManager manager, boolean isOnTheFly) {
    final Project project = manager.getProject();
    final PsiType type = expression.getType();
    final PsiExpressionList arguments = expression.getArgumentList();
    if (type != null && arguments != null && type.equalsToText("java.awt.Color")) {
        final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
        final PsiClass jbColorClass = facade.findClass(JBColor.class.getName(), GlobalSearchScope.allScope(project));
        if (jbColorClass != null && facade.getResolveHelper().isAccessible(jbColorClass, expression, jbColorClass)) {
            final PsiElement parent = expression.getParent();
            if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiNewExpression) {
                final PsiType parentType = ((PsiNewExpression) parent.getParent()).getType();
                if (parentType == null || JBColor.class.getName().equals(parentType.getCanonicalText()))
                    return null;
            }
            return manager.createProblemDescriptor(expression, "Replace with JBColor", new ConvertToJBColorQuickFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) ConvertToJBColorQuickFix(org.jetbrains.idea.devkit.inspections.quickfix.ConvertToJBColorQuickFix) JBColor(com.intellij.ui.JBColor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JBColor (com.intellij.ui.JBColor)51 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)8 NotNull (org.jetbrains.annotations.NotNull)8 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 Rectangle2D (java.awt.geom.Rectangle2D)4 UIUtil (com.intellij.util.ui.UIUtil)3 Project (com.intellij.openapi.project.Project)2 BalloonLayout (com.intellij.ui.BalloonLayout)2 BalloonLayoutData (com.intellij.ui.BalloonLayoutData)2 StudyStatus (com.jetbrains.edu.learning.courseFormat.StudyStatus)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 BasicArrowButton (javax.swing.plaf.basic.BasicArrowButton)2 Nullable (org.jetbrains.annotations.Nullable)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 LegendComponent (com.android.tools.adtui.LegendComponent)1 LegendRenderData (com.android.tools.adtui.LegendRenderData)1 TimelineComponent (com.android.tools.adtui.TimelineComponent)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 MergedManifest (com.android.tools.idea.model.MergedManifest)1