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 new ColorIcon(16, 12, color, true); } } } catch (Exception e) { throw new EvaluateException(e.getMessage(), e); } } return null; }
@Override public void renderElement(LookupElementPresentation presentation) { boolean qualify = myHelper != null && !myHelper.willBeImported(); PsiVariable variable = getObject(); String name = variable.getName(); if (qualify && variable instanceof PsiField && ((PsiField)variable).getContainingClass() != null) { name = ((PsiField)variable).getContainingClass().getName() + "." + name; } presentation.setItemText(name); presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal())); presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this)); if (myHelper != null) { myHelper.renderElement(presentation, qualify, true, getSubstitutor()); } if (myColor != null) { presentation.setTypeText("", new ColorIcon(12, myColor)); } else { presentation.setTypeText(getType().getPresentableText()); } }
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 = new ColorIcon(8, color); final Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element)); } } catch (Exception ignored) { } }
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) { final Color color = new Color(((IntegerValue)rgbValue).value(), true); return new ColorIcon(16, 12, color, true); } } } catch (Exception e) { throw new EvaluateException(e.getMessage(), e); } } return null; }
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 = ColorSampleLookupValue.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText)); if (hexCode != null) { color = ColorUtil.fromHex(hexCode); } } if (color != null) { final ColorIcon icon = new ColorIcon(8, color); final Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element)); } } catch (Exception ignored) { } }
@NotNull private static Result renderColorInt(int value) { int alpha = value >>> 24; boolean hasAlpha = alpha != 0; //noinspection UseJBColor final Color color = new Color(value, hasAlpha); String result = String.format(Locale.US, "0x%1$08x {a=%2$02d r=%3$02d g=%4$02d b=%5$02d}", value, color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue()); return new Result(result, new ColorIcon(16, 12, color, true)); }
@Nonnull @Override public LookupElementBuilder createLookupBuilder(@Nonnull VcsRef item) { LookupElementBuilder lookupBuilder = super.createLookupBuilder(item); if (myColorManager.isMultipleRoots()) { lookupBuilder = lookupBuilder .withTypeText(getTypeText(item), new ColorIcon(15, VcsLogGraphTable.getRootBackgroundColor(item.getRoot(), myColorManager)), true); } return lookupBuilder; }
@NotNull @Override public List<LookupElement> getLookupElements(String value) { List<LookupElement> list = new ArrayList<LookupElement>(); for(Map.Entry<String, String> entry : myDefaultColors.entrySet()) { LookupElementBuilder builder = LookupElementBuilder.create(entry.getKey()); builder = builder.withIcon(new ColorIcon(12, ColorUtil.fromHex(entry.getValue()))); builder = builder.withTypeText(entry.getValue(), true); list.add(builder); } return list; }
@Override public void renderElement(LookupElementPresentation presentation) { boolean qualify = myHelper != null && !myHelper.willBeImported(); PsiVariable variable = getObject(); String name = variable.getName(); if(qualify && variable instanceof PsiField && ((PsiField) variable).getContainingClass() != null) { name = ((PsiField) variable).getContainingClass().getName() + "." + name; } presentation.setItemText(name); presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal())); presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this)); if(myHelper != null) { myHelper.renderElement(presentation, qualify, true, getSubstitutor()); } if(myColor != null) { presentation.setTypeText("", JBUI.scale(new ColorIcon(12, myColor))); } else { presentation.setTypeText(getType().getPresentableText()); } if(myTailText != null && StringUtil.isEmpty(presentation.getTailText())) { if(myTailText.startsWith(EQ)) { presentation.appendTailTextItalic(" (" + myTailText + ")", true); } else { presentation.setTailText(myTailText, true); } } }
@Override 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 new ColorIcon(16, 12, color, true); } } } catch(Exception e) { throw new EvaluateException(e.getMessage(), e); } } return null; }
public static Icon getIcon(@NotNull HighlightDisplayLevel level) { Icon icon = level.getIcon(); return icon instanceof HighlightDisplayLevel.ColoredIcon ? new ColorIcon(icon.getIconWidth(), ((HighlightDisplayLevel.ColoredIcon)icon).getColor()) : icon; }
@Override Icon getIcon(FileColorConfiguration configuration) { Color color = myManager.getColor(configuration.getColorName()); return color == null ? EmptyIcon.ICON_16 : new ColorIcon(16, 13, color, true); }
@NotNull @Override public Icon getIcon() { final Color color = getCurrentColor(); return color == null ? EmptyIcon.create(ICON_SIZE) : new ColorIcon(ICON_SIZE, color); }
public ColorIconRenderer(ColorIcon icon, PsiElement element) { myIcon = icon; myElement = element; }
public JComponent setValue(@NotNull final Color value) { setText("r:" + value.getRed() + ", g:" + value.getGreen() + ", b:" + value.getBlue()); setIcon(new ColorIcon(13, 11, value, true)); return this; }
public static Icon getIcon(@Nonnull HighlightDisplayLevel level) { Icon icon = level.getIcon(); return icon instanceof HighlightDisplayLevel.ColoredIcon ? new ColorIcon(icon.getIconWidth(), ((HighlightDisplayLevel.ColoredIcon)icon).getColor()) : icon; }