Java Code Examples for com.intellij.openapi.editor.colors.TextAttributesKey
The following examples show how to use
com.intellij.openapi.editor.colors.TextAttributesKey. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Custom-Syntax-Highlighter Source File: JavaAnnotator.java License: MIT License | 6 votes |
@Override protected TextAttributesKey getKeywordKind(@NotNull final PsiElement element) { TextAttributesKey kind = null; switch (element.getText()) { case "private": case "public": case "protected": kind = MODIFIER; break; case "static": case "final": kind = STATIC_FINAL; break; case "this": case "super": kind = THIS_SUPER; break; } return kind; }
Example 2
Source Project: intellij-sdk-docs Source File: SimpleSyntaxHighlighter.java License: Apache License 2.0 | 6 votes |
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { if (tokenType.equals(SimpleTypes.SEPARATOR)) { return SEPARATOR_KEYS; } else if (tokenType.equals(SimpleTypes.KEY)) { return KEY_KEYS; } else if (tokenType.equals(SimpleTypes.VALUE)) { return VALUE_KEYS; } else if (tokenType.equals(SimpleTypes.COMMENT)) { return COMMENT_KEYS; } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { return BAD_CHAR_KEYS; } else { return EMPTY_KEYS; } }
Example 3
Source Project: idea-php-typo3-plugin Source File: TypoScriptSyntaxHighlighter.java License: MIT License | 6 votes |
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { if (tokenType.equals(TypoScriptTypes.DOT)) { return SEPARATOR_KEYS; } else if (tokenType.equals(TypoScriptTypes.IDENTIFIER)) { return KEY_KEYS; } else if (tokenType.equals(TypoScriptTypes.VALUE)) { return VALUE_KEYS; } else if (tokenType.equals(TypoScriptTypes.COMMENT)) { return COMMENT_KEYS; } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { return BAD_CHAR_KEYS; } else { return EMPTY_KEYS; } }
Example 4
Source Project: idea-php-dotenv-plugin Source File: DotEnvSyntaxHighlighter.java License: MIT License | 6 votes |
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { if (tokenType.equals(DotEnvTypes.SEPARATOR)) { return SEPARATOR_KEYS; } else if (tokenType.equals(DotEnvTypes.KEY_CHARS)) { return KEY_KEYS; } else if (tokenType.equals(DotEnvTypes.VALUE_CHARS)) { return VALUE_KEYS; } else if (tokenType.equals(DotEnvTypes.COMMENT) || tokenType.equals(DotEnvTypes.EXPORT)) { return COMMENT_KEYS; } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { return BAD_CHAR_KEYS; } else { return EMPTY_KEYS; } }
Example 5
Source Project: intellij-csv-validator Source File: CsvColorSettings.java License: Apache License 2.0 | 6 votes |
public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserDataHolder userDataHolder) { List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY); if (textAttributeList == null) { EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); textAttributeList = new ArrayList<>(); int maxIndex = 0; for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_HIGHLIGHT_COLORS; ++colorDescriptorIndex) { TextAttributesKey textAttributesKey = COLUMN_HIGHLIGHT_ATTRIBUTES.get(colorDescriptorIndex); TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey); textAttributeList.add(textAttributes); if (!textAttributesKey.getDefaultAttributes().equals(textAttributes)) { maxIndex = colorDescriptorIndex; } } textAttributeList = textAttributeList.subList(0, maxIndex + 1); userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList); } return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size()); }
Example 6
Source Project: consulo Source File: DiffOptionsPanel.java License: Apache License 2.0 | 6 votes |
@Override public void updateOptionsList() { myOptionsModel.clear(); myDescriptions.clear(); Map<TextAttributesKey, TextDiffType> typesByKey = ContainerUtil.newMapFromValues(TextDiffType.MERGE_TYPES.iterator(), TextDiffType.ATTRIBUTES_KEY); for (int i = 0; i < myOptions.getCurrentDescriptions().length; i++) { EditorSchemeAttributeDescriptor description = myOptions.getCurrentDescriptions()[i]; TextAttributesKey type = TextAttributesKey.find(description.getType()); if (description.getGroup() == ColorAndFontOptions.DIFF_GROUP && typesByKey.keySet().contains(type)) { myOptionsModel.add(typesByKey.get(type)); myDescriptions.put(type.getExternalName(), (MyColorAndFontDescription)description); } } ScrollingUtil.ensureSelectionExists(myOptionsList); }
Example 7
Source Project: buck Source File: BcfgSyntaxHighlighter.java License: Apache License 2.0 | 6 votes |
@NotNull @Override public TextAttributesKey[] getTokenHighlights(@Nullable IElementType tokenType) { if (BcfgTypes.COMMENT.equals(tokenType)) { return COMMENT_KEYS; } else if (BcfgTypes.L_BRACKET.equals(tokenType) || BcfgTypes.R_BRACKET.equals(tokenType) || BcfgTypes.REQUIRED_FILE.equals(tokenType) || BcfgTypes.OPTIONAL_FILE.equals(tokenType) || BcfgTypes.END_INLINE.equals(tokenType) || BcfgTypes.ASSIGN.equals(tokenType)) { return PUNCTUATION_KEYS; } else if (BcfgTypes.PROPERTY_VALUE_FRAGMENT.equals(tokenType)) { return VALUE_KEYS; } else if (BcfgTypes.SECTION_NAME.equals(tokenType)) { return SECTION_KEYS; } else if (BcfgTypes.PROPERTY_NAME.equals(tokenType)) { return PROPERTY_KEYS; } else if (BcfgTypes.FILE_PATH.equals(tokenType)) { return FILE_PATH_KEYS; } else if (TokenType.BAD_CHARACTER.equals(tokenType)) { return BAD_CHAR_KEYS; } else { return EMPTY_KEYS; } }
Example 8
Source Project: consulo Source File: EditorColorsSchemeImpl.java License: Apache License 2.0 | 6 votes |
@Override public TextAttributes getAttributes(TextAttributesKey key) { if (key != null) { TextAttributesKey fallbackKey = key.getFallbackAttributeKey(); TextAttributes attributes = myAttributesMap.get(key); if (fallbackKey == null) { if (attributes != null) return attributes; } else { if (attributes != null && !attributes.isFallbackEnabled()) return attributes; attributes = getFallbackAttributes(fallbackKey); if (attributes != null) return attributes; } } return myParentScheme.getAttributes(key); }
Example 9
Source Project: consulo Source File: ColorAndFontOptions.java License: Apache License 2.0 | 6 votes |
private SchemeTextAttributesDescription(String name, String group, @Nonnull TextAttributesKey key, @Nonnull MyColorScheme scheme, Image icon, String toolTip) { super(name, group, getInitialAttributes(scheme, key).clone(), key, scheme, icon, toolTip); this.key = key; myAttributesToApply = getInitialAttributes(scheme, key); TextAttributesKey fallbackKey = key.getFallbackAttributeKey(); if (fallbackKey != null) { myFallbackAttributes = scheme.getAttributes(fallbackKey); myBaseAttributeDescriptor = ColorSettingsPages.getInstance().getAttributeDescriptor(fallbackKey); if (myBaseAttributeDescriptor == null) { myBaseAttributeDescriptor = new Pair<>(null, new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey)); } } myIsInheritedInitial = isInherited(scheme); setInherited(myIsInheritedInitial); initCheckedStatus(); }
Example 10
Source Project: HighlightBracketPair Source File: BraceHighlighter.java License: Apache License 2.0 | 5 votes |
public Pair<RangeHighlighter, RangeHighlighter> highlightPair(BracePair bracePair) { final Brace leftBrace = bracePair.getLeftBrace(); final Brace rightBrace = bracePair.getRightBrace(); final int leftBraceOffset = leftBrace.getOffset(); final int rightBraceOffset = rightBrace.getOffset(); final String leftBraceText = leftBrace.getText(); final String rightBraceText = rightBrace.getText(); if (leftBraceOffset == NON_OFFSET || rightBraceOffset == NON_OFFSET) return null; // try to get the text attr by element type TextAttributesKey textAttributesKey = HighlightBracketPairSettingsPage.getTextAttributesKeyByToken(leftBrace.getElementType()); // if not found, get the text attr by brace text if (textAttributesKey == null) { textAttributesKey = HighlightBracketPairSettingsPage.getTextAttributesKeyByText(leftBraceText); } final TextAttributes textAttributes = editor.getColorsScheme().getAttributes(textAttributesKey); RangeHighlighter leftHighlighter = markupModelEx.addRangeHighlighter( leftBraceOffset, leftBraceOffset + leftBraceText.length(), HighlighterLayer.SELECTION + HIGHLIGHT_LAYER_WEIGHT, textAttributes, HighlighterTargetArea.EXACT_RANGE); RangeHighlighter rightHighlighter = markupModelEx.addRangeHighlighter( rightBraceOffset, rightBraceOffset + rightBraceText.length(), HighlighterLayer.SELECTION + HIGHLIGHT_LAYER_WEIGHT, textAttributes, HighlighterTargetArea.EXACT_RANGE); return new Pair<>(leftHighlighter, rightHighlighter); }
Example 11
Source Project: consulo Source File: TextDiffTypeFactory.java License: Apache License 2.0 | 5 votes |
@Nonnull public synchronized TextDiffType createTextDiffType(@NonNls @Nonnull TextAttributesKey key, @Nonnull String name) { TextDiffType type = new TextDiffTypeImpl(key, name); myTypes.add(type); return type; }
Example 12
Source Project: consulo Source File: SyntaxHighlighterOverEditorHighlighter.java License: Apache License 2.0 | 5 votes |
@Nonnull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { final SyntaxHighlighter activeSyntaxHighlighter = layeredHighlighterIterator != null ? layeredHighlighterIterator.getActiveSyntaxHighlighter() : highlighter; return activeSyntaxHighlighter.getTokenHighlights(tokenType); }
Example 13
Source Project: Custom-Syntax-Highlighter Source File: TSColorSettings.java License: MIT License | 5 votes |
private static Map<String, TextAttributesKey> createAdditionalHlAttrs() { final Map<String, TextAttributesKey> descriptors = new THashMap<>(); descriptors.put("private", PRIVATE); descriptors.put("class", DefaultLanguageHighlighterColors.CLASS_NAME); return descriptors; }
Example 14
Source Project: Custom-Syntax-Highlighter Source File: JSColorSettings.java License: MIT License | 5 votes |
private static Map<String, TextAttributesKey> createAdditionalHlAttrs() { final Map<String, TextAttributesKey> descriptors = new THashMap<>(); descriptors.put("keyword", JSColorSettings.JSKEYWORD); descriptors.put("function", JSColorSettings.FUNCTION); descriptors.put("function_name", JSColorSettings.FUNCTION_NAME); descriptors.put("val", JSColorSettings.VAL); descriptors.put("local_variable", JSColorSettings.VARIABLE); descriptors.put("this", JSColorSettings.THIS_SUPER); descriptors.put("null", JSColorSettings.NULL); descriptors.put("debugger", JSColorSettings.DEBUGGER); descriptors.put("import", JSColorSettings.MODULE); return descriptors; }
Example 15
Source Project: consulo Source File: NodeRenderer.java License: Apache License 2.0 | 5 votes |
public static SimpleTextAttributes getSimpleTextAttributes(@Nullable final ItemPresentation presentation, @Nonnull EditorColorsScheme colorsScheme) { if (presentation instanceof ColoredItemPresentation) { final TextAttributesKey textAttributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey(); if (textAttributesKey == null) return SimpleTextAttributes.REGULAR_ATTRIBUTES; final TextAttributes textAttributes = colorsScheme.getAttributes(textAttributesKey); return textAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.fromTextAttributes(textAttributes); } return SimpleTextAttributes.REGULAR_ATTRIBUTES; }
Example 16
Source Project: consulo Source File: FileTemplateConfigurable.java License: Apache License 2.0 | 5 votes |
@Override @Nonnull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { if (tokenType == FileTemplateTokenType.MACRO || tokenType == FileTemplateTokenType.DIRECTIVE) { return pack(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES); } return EMPTY; }
Example 17
Source Project: consulo-csharp Source File: CSharpHighlightUtil.java License: Apache License 2.0 | 5 votes |
@Nullable @RequiredReadAction public static HighlightInfo highlightNamed(@Nonnull HighlightInfoHolder holder, @Nullable PsiElement element, @Nullable PsiElement target, @Nullable PsiElement owner) { if(target == null || element == null) { return null; } IElementType elementType = target.getNode().getElementType(); if(CSharpTokenSets.KEYWORDS.contains(elementType)) // don't highlight keywords { return null; } if(isMethodRef(owner, element)) { HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CSharpHighlightKey.METHOD_REF).create(); holder.add(highlightInfo); } TextAttributesKey defaultTextAttributeKey = getDefaultTextAttributeKey(element, target); if(defaultTextAttributeKey == null) { return null; } HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(defaultTextAttributeKey).create(); holder.add(info); if(!(target instanceof CSharpIdentifier) && DotNetAttributeUtil.hasAttribute(element, DotNetTypes.System.ObsoleteAttribute)) { holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).create()); } return info; }
Example 18
Source Project: consulo Source File: HighlightDisplayLevel.java License: Apache License 2.0 | 5 votes |
public static void registerSeverity(@Nonnull HighlightSeverity severity, final TextAttributesKey key, @javax.annotation.Nullable Icon icon) { Icon severityIcon = icon != null ? icon : createBoxIcon(key); final HighlightDisplayLevel level = ourMap.get(severity); if (level == null) { new HighlightDisplayLevel(severity, severityIcon); } else { level.myIcon = severityIcon; } }
Example 19
Source Project: consulo Source File: SyntaxHighlighterBase.java License: Apache License 2.0 | 5 votes |
/** * Tries to update the map by associating given keys with a given value. * Throws error if the map already contains different mapping for one of given keys. */ protected static void safeMap( @Nonnull final Map<IElementType, TextAttributesKey> map, @Nonnull final TokenSet keys, @Nonnull final TextAttributesKey value) { for (final IElementType type : keys.getTypes()) { safeMap(map, type, value); } }
Example 20
Source Project: jetbrains-plugin-sample Source File: SampleSyntaxHighlighter.java License: BSD 2-Clause "Simplified" License | 5 votes |
@NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { if ( !(tokenType instanceof TokenIElementType) ) return EMPTY_KEYS; TokenIElementType myType = (TokenIElementType)tokenType; int ttype = myType.getANTLRTokenType(); TextAttributesKey attrKey; switch ( ttype ) { case SampleLanguageLexer.ID : attrKey = ID; break; case SampleLanguageLexer.VAR : case SampleLanguageLexer.WHILE : case SampleLanguageLexer.IF : case SampleLanguageLexer.ELSE : case SampleLanguageLexer.RETURN : case SampleLanguageLexer.PRINT : case SampleLanguageLexer.FUNC : case SampleLanguageLexer.TYPEINT : case SampleLanguageLexer.TYPEFLOAT : case SampleLanguageLexer.TYPESTRING : case SampleLanguageLexer.TYPEBOOLEAN : case SampleLanguageLexer.TRUE : case SampleLanguageLexer.FALSE : attrKey = KEYWORD; break; case SampleLanguageLexer.STRING : attrKey = STRING; break; case SampleLanguageLexer.COMMENT : attrKey = LINE_COMMENT; break; case SampleLanguageLexer.LINE_COMMENT : attrKey = BLOCK_COMMENT; break; default : return EMPTY_KEYS; } return new TextAttributesKey[] {attrKey}; }
Example 21
Source Project: flutter-intellij Source File: FlutterLogView.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private void computeTextAttributesByLogLevelCache() { final EditorColorsScheme globalEditorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); textAttributesByLogLevelCache.clear(); for (Level level : FlutterLog.Level.values()) { try { final TextAttributesKey key = LOG_LEVEL_TEXT_ATTRIBUTES_KEY_MAP.get(level); final TextAttributes attributes = globalEditorColorsScheme.getAttributes(key); int fontType = attributes.getFontType(); final Color effectColor = attributes.getEffectColor(); final Integer textStyle = EFFECT_TYPE_TEXT_STYLE_MAP.get(attributes.getEffectType()); // TextStyle can exist even when unchecked in settings page. // only effectColor is null when setting effect is unchecked in setting page. // So, we have to check that both effectColor & textStyle are not null. if (effectColor != null && textStyle != null) { fontType = fontType | textStyle; } final SimpleTextAttributes textAttributes = new SimpleTextAttributes( attributes.getBackgroundColor(), attributes.getForegroundColor(), effectColor, fontType ); textAttributesByLogLevelCache.put(level, textAttributes); } catch (Exception e) { // Should never go here. FlutterUtils.warn(LOG, "Error when get text attributes by log level", e); } } }
Example 22
Source Project: react-templates-plugin Source File: RTSyntaxHighlighterFactory.java License: MIT License | 5 votes |
@NotNull public TextAttributesKey[] getTokenHighlights(final IElementType tokenType) { if (myKeysMap.containsKey(tokenType)) { return pack(myKeysMap.get(tokenType)); } return super.getTokenHighlights(tokenType); }
Example 23
Source Project: consulo Source File: SandHighlighter.java License: Apache License 2.0 | 5 votes |
@Nonnull @Override public TextAttributesKey[] getTokenHighlights(LanguageVersion languageVersion, IElementType tokenType) { BaseSandLanguageVersion sandLanguageVersion = (BaseSandLanguageVersion) languageVersion; if(sandLanguageVersion.getHighlightKeywords().contains(tokenType)) { return pack(SandHighlighterKeys.KEYWORD); } else if(sandLanguageVersion.getCommentTokens().contains(tokenType)) { return pack(SandHighlighterKeys.LINE_COMMENT); } return EMPTY; }
Example 24
Source Project: consulo Source File: SyntaxHighlighterBase.java License: Apache License 2.0 | 5 votes |
/** * Tries to update the map by associating given key with a given value. * Throws error if the map already contains different mapping for given key. */ protected static void safeMap( @Nonnull final Map<IElementType, TextAttributesKey> map, @Nonnull final IElementType type, @Nonnull final TextAttributesKey value) { final TextAttributesKey oldVal = map.put(type, value); if (oldVal != null && !oldVal.equals(value)) { LOG.error("Remapping highlighting for \"" + type + "\" val: old=" + oldVal + " new=" + value); } }
Example 25
Source Project: consulo Source File: SimpleEditorPreview.java License: Apache License 2.0 | 5 votes |
@Nullable private static String selectItem(HighlighterIterator itr, SyntaxHighlighter highlighter) { IElementType tokenType = itr.getTokenType(); if (tokenType == null) return null; TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType); String s = null; for (int i = highlights.length - 1; i >= 0; i--) { if (highlights[i] != HighlighterColors.TEXT) { s = highlights[i].getExternalName(); break; } } return s == null ? HighlighterColors.TEXT.getExternalName() : s; }
Example 26
Source Project: consulo Source File: PsiElementListCellRenderer.java License: Apache License 2.0 | 5 votes |
@Nullable protected TextAttributes getNavigationItemAttributes(Object value) { TextAttributes attributes = null; if (value instanceof NavigationItem) { TextAttributesKey attributesKey = null; final ItemPresentation presentation = ((NavigationItem)value).getPresentation(); if (presentation instanceof ColoredItemPresentation) attributesKey = ((ColoredItemPresentation)presentation).getTextAttributesKey(); if (attributesKey != null) { attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey); } } return attributes; }
Example 27
Source Project: consulo Source File: DiffOptionsPanel.java License: Apache License 2.0 | 5 votes |
@Override public void apply(EditorColorsScheme scheme) { TextAttributesKey key = myDiffType.getAttributesKey(); TextAttributes attrs = new TextAttributes(null, myBackgroundColor, null, EffectType.BOXED, Font.PLAIN); attrs.setErrorStripeColor(myStripebarColor); scheme.setAttributes(key, attrs); }
Example 28
Source Project: buck Source File: BcfgColorSettingsPage.java License: Apache License 2.0 | 4 votes |
@Nullable @Override public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() { return null; }
Example 29
Source Project: HighlightBracketPair Source File: HighlightBracketPairSettingsPage.java License: Apache License 2.0 | 4 votes |
@Nullable @Override public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() { return TAGS; }
Example 30
Source Project: consulo Source File: PresentationData.java License: Apache License 2.0 | 4 votes |
@Override public TextAttributesKey getTextAttributesKey() { return myAttributesKey; }