Search in sources :

Example 1 with ColorIcon

use of com.intellij.util.ui.ColorIcon in project android by JetBrains.

the class AndroidColorAnnotatorTest method checkAnnotationColor.

private static void checkAnnotationColor(Annotation annotation, Color expectedColor) {
    GutterIconRenderer renderer = annotation.getGutterIconRenderer();
    assertThat(renderer).isNotNull();
    Icon icon = renderer.getIcon();
    assertThat(icon).isInstanceOf(ColorIcon.class);
    ColorIcon colorIcon = (ColorIcon) icon;
    Color color = colorIcon.getIconColor();
    assertThat(color).isEqualTo(expectedColor);
}
Also used : ColorIcon(com.intellij.util.ui.ColorIcon) ColorIcon(com.intellij.util.ui.ColorIcon) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Example 2 with ColorIcon

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

the class ColorObjectRenderer method calcValueIcon.

public Icon calcValueIcon(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener) throws EvaluateException {
    final Value value = descriptor.getValue();
    if (value instanceof ObjectReference) {
        try {
            final ObjectReference objRef = (ObjectReference) value;
            final ReferenceType refType = objRef.referenceType();
            final Field valueField = refType.fieldByName("value");
            if (valueField != null) {
                final Value rgbValue = objRef.getValue(valueField);
                if (rgbValue instanceof IntegerValue) {
                    @SuppressWarnings("UseJBColor") final Color color = new Color(((IntegerValue) rgbValue).value(), true);
                    return JBUI.scale(new ColorIcon(16, 12, color, true));
                }
            }
        } catch (Exception e) {
            throw new EvaluateException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ColorIcon(com.intellij.util.ui.ColorIcon) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 3 with ColorIcon

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

the class JavaFxAnnotator method attachColorIcon.

private static void attachColorIcon(final PsiElement element, AnnotationHolder holder, String attributeValueText) {
    try {
        Color color = null;
        if (attributeValueText.startsWith("#")) {
            color = ColorUtil.fromHex(attributeValueText.substring(1));
        } else {
            final String hexCode = ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText));
            if (hexCode != null) {
                color = ColorUtil.fromHex(hexCode);
            }
        }
        if (color != null) {
            final ColorIcon icon = JBUI.scale(new ColorIcon(8, color));
            final Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element));
        }
    } catch (Exception ignored) {
    }
}
Also used : ColorIcon(com.intellij.util.ui.ColorIcon) Annotation(com.intellij.lang.annotation.Annotation)

Aggregations

ColorIcon (com.intellij.util.ui.ColorIcon)3 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 Annotation (com.intellij.lang.annotation.Annotation)1 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)1