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 @Override public Object[] getVariants() { final ColorSampleLookupValue[] lookupValues = ColorSampleLookupValue.getColors(); final Object[] vars = new Object[lookupValues.length + 1]; for (int i = 0; i < lookupValues.length; i++) { final ColorSampleLookupValue value = lookupValues[i]; vars[i] = new ColorSampleLookupValue(value.getName(), value.getValue(), true); } vars[lookupValues.length] = new UserColorLookup(); return vars; }
public static void addColorPreviewAndCodeToLookup(final PsiElement currentElement, final StringBuilder buf) { final Color colorFromElement = UserColorLookup.getColorFromElement(currentElement); if (colorFromElement != null) { ColorSampleLookupValue.addColorPreviewAndCodeToLookup(colorFromElement, buf); } }
@Nullable public static Color getColorFromElement(final PsiElement element) { if (!(element instanceof XmlToken)) return null; return ColorSampleLookupValue.getColor(element.getText()); }