public LookupCellRenderer(LookupImpl lookup) { EditorColorsScheme scheme = lookup.getEditor().getColorsScheme(); myNormalFont = scheme.getFont(EditorFontType.PLAIN); myBoldFont = scheme.getFont(EditorFontType.BOLD); myLookup = lookup; myNameComponent = new MySimpleColoredComponent(); myNameComponent.setIpad(new Insets(0, 0, 0, 0)); myTailComponent = new MySimpleColoredComponent(); myTailComponent.setIpad(new Insets(0, 0, 0, 0)); myTypeLabel = new MySimpleColoredComponent(); myTypeLabel.setIpad(new Insets(0, 0, 0, 0)); myPanel = new LookupPanel(); myPanel.add(myNameComponent, BorderLayout.WEST); myPanel.add(myTailComponent, BorderLayout.CENTER); myTailComponent.setBorder(new EmptyBorder(0, 0, 0, AFTER_TAIL)); myPanel.add(myTypeLabel, BorderLayout.EAST); myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, AFTER_TYPE)); myNormalMetrics = myLookup.getEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getEditor().getComponent().getFontMetrics(myBoldFont); }
public static Color getBackgroundColor(Editor editor) { EditorColorsScheme colorsScheme = editor.getColorsScheme(); Color color = colorsScheme.getColor(EditorColors.CARET_ROW_COLOR); if (color == null) { color = colorsScheme.getDefaultBackground(); } return color; }
private MarkupIterator( @NotNull CharSequence charSequence, @NotNull RangeIterator rangeIterator, @NotNull EditorColorsScheme colorsScheme) { myRangeIterator = rangeIterator; mySegmentIterator = new SegmentIterator( charSequence, colorsScheme.getEditorFontName(), colorsScheme.getEditorFontSize()); }
void updateGlobalScheme() { if (myColorsManager != null) { EditorColorsScheme globalScheme = myColorsManager.getGlobalScheme(); globalScheme.setEditorFontSize(getFontSize()); globalScheme.setEditorFontName(getFontFamily()); globalScheme.setLineSpacing(((float) getLineSpacing())); EditorFactory.getInstance().refreshAllEditors(); } }
// iterators have priority corresponding to their order in the parameter list - rightmost having // the largest priority public CompositeRangeIterator( @NotNull EditorColorsScheme colorsScheme, RangeIterator... iterators) { myDefaultForeground = colorsScheme.getDefaultForeground(); myDefaultBackground = colorsScheme.getDefaultBackground(); myIterators = new IteratorWrapper[iterators.length]; for (int i = 0; i < iterators.length; i++) { myIterators[i] = new IteratorWrapper(iterators[i], i); } }
private void highlightInjectedSyntax(final PsiFile injectedPsi, HighlightInfoHolder holder) { List<Trinity<IElementType, PsiLanguageInjectionHost, TextRange>> tokens = InjectedLanguageUtil.getHighlightTokens(injectedPsi); if (tokens == null) return; final Language injectedLanguage = injectedPsi.getLanguage(); Project project = injectedPsi.getProject(); SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter( injectedLanguage, project, injectedPsi.getVirtualFile()); final TextAttributes defaultAttrs = myGlobalScheme.getAttributes(HighlighterColors.TEXT); for (Trinity<IElementType, PsiLanguageInjectionHost, TextRange> token : tokens) { ProgressManager.checkCanceled(); IElementType tokenType = token.getFirst(); PsiLanguageInjectionHost injectionHost = token.getSecond(); TextRange textRange = token.getThird(); TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(tokenType); if (textRange.getLength() == 0) continue; TextRange annRange = textRange.shiftRight(injectionHost.getTextRange().getStartOffset()); // force attribute colors to override host' ones TextAttributes attributes = null; for (TextAttributesKey key : keys) { TextAttributes attrs2 = myGlobalScheme.getAttributes(key); if (attrs2 != null) { attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2); } } TextAttributes forcedAttributes; if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) { forcedAttributes = TextAttributes.ERASE_MARKER; } else { Color back = attributes.getBackgroundColor() == null ? myGlobalScheme.getDefaultBackground() : attributes.getBackgroundColor(); Color fore = attributes.getForegroundColor() == null ? myGlobalScheme.getDefaultForeground() : attributes.getForegroundColor(); forcedAttributes = new TextAttributes( fore, back, attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType()); } HighlightInfo info = HighlightInfo.createHighlightInfo( HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, annRange, null, null, forcedAttributes); holder.add(info); } }
protected TextAttributes convertAttributes(@NotNull TextAttributesKey[] keys) { TextAttributes attrs = myScheme.getAttributes(HighlighterColors.TEXT); for (TextAttributesKey key : keys) { TextAttributes attrs2 = myScheme.getAttributes(key); if (attrs2 != null) { attrs = TextAttributes.merge(attrs, attrs2); } } return attrs; }
public void apply(@NotNull EditorColorsScheme scheme) { scheme.setFontPreferences(getFontPreferences()); scheme.setLineSpacing(myLineSpacing); scheme.setQuickDocFontSize(getQuickDocFontSize()); scheme.setConsoleFontPreferences(getConsoleFontPreferences()); scheme.setConsoleLineSpacing(getConsoleLineSpacing()); for (EditorSchemeAttributeDescriptor descriptor : myDescriptors) { descriptor.apply(scheme); } }
@Override public void setSelected(AnActionEvent e, boolean state) { if (!state) { mySettingsPanel.setVisible(false); return; } EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); setFontSizeSliderSize(scheme.getQuickDocFontSize()); mySettingsPanel.setVisible(true); }
Context( @NotNull CharSequence charSequence, @NotNull EditorColorsScheme scheme, int indentSymbolsToStrip) { myText = charSequence; myDefaultForeground = scheme.getDefaultForeground(); myDefaultBackground = scheme.getDefaultBackground(); builder = new SyntaxInfo.Builder( myDefaultForeground, myDefaultBackground, scheme.getEditorFontSize()); myIndentSymbolsToStrip = indentSymbolsToStrip; }
private static void highlightElement(@NotNull PsiElement element) { final Project project = element.getProject(); final FileEditorManager editorManager = FileEditorManager.getInstance(project); final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final Editor editor = editorManager.getSelectedTextEditor(); final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final PsiElement[] elements = new PsiElement[] {element}; highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null); StatusBar.Info.set( IntentionPowerPackBundle.message("status.bar.escape.highlighting.message"), project); }
@Nullable private static Color getErrorStripeColor(@NotNull Range range, @Nullable Editor editor) { final EditorColorsScheme scheme = getColorScheme(editor); switch (range.getType()) { case Range.INSERTED: return scheme.getAttributes(DiffColors.DIFF_INSERTED).getErrorStripeColor(); case Range.DELETED: return scheme.getAttributes(DiffColors.DIFF_DELETED).getErrorStripeColor(); case Range.MODIFIED: return scheme.getAttributes(DiffColors.DIFF_MODIFIED).getErrorStripeColor(); default: assert false; return null; } }
@Nullable private static Color getGutterColor(@NotNull Range range, @Nullable Editor editor) { final EditorColorsScheme scheme = getColorScheme(editor); switch (range.getType()) { case Range.INSERTED: return scheme.getColor(EditorColors.ADDED_LINES_COLOR); case Range.DELETED: return scheme.getColor(EditorColors.DELETED_LINES_COLOR); case Range.MODIFIED: return scheme.getColor(EditorColors.MODIFIED_LINES_COLOR); default: assert false; return null; } }
public MyListCellRenderer() { myPanel = new JPanel(new BorderLayout()); myPanel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); myNameLabel = new JLabel(); myPanel.add(myNameLabel, BorderLayout.WEST); myPanel.add(new JLabel(" ")); myNSLabel = new JLabel(); myPanel.add(myNSLabel, BorderLayout.EAST); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font font = scheme.getFont(EditorFontType.PLAIN); myNameLabel.setFont(font); myNSLabel.setFont(font); }
@Nullable public TextAttributes getTextAttributes( @Nullable final PsiElement element, @Nullable final EditorColorsScheme editorColorsScheme) { if (forcedTextAttributes != null) { return forcedTextAttributes; } EditorColorsScheme colorsScheme = getColorsScheme(editorColorsScheme); if (forcedTextAttributesKey != null) { return colorsScheme.getAttributes(forcedTextAttributesKey); } return getAttributesByType(element, type, colorsScheme); }
private void writeAttributes(Element attrElements) throws WriteExternalException { List<TextAttributesKey> list = new ArrayList<TextAttributesKey>(myAttributesMap.keySet()); Collections.sort(list); for (TextAttributesKey key : list) { TextAttributes defaultAttr = myParentScheme != null ? myParentScheme.getAttributes(key) : new TextAttributes(); TextAttributesKey baseKey = key.getFallbackAttributeKey(); TextAttributes defaultFallbackAttr = baseKey != null && myParentScheme instanceof AbstractColorsScheme ? ((AbstractColorsScheme) myParentScheme).getFallbackAttributes(baseKey) : null; TextAttributes value = myAttributesMap.get(key); if (!value.equals(defaultAttr) || defaultAttr == defaultFallbackAttr) { Element element = new Element(OPTION_ELEMENT); element.setAttribute(NAME_ATTR, key.getExternalName()); if (baseKey == null || !value.isFallbackEnabled()) { Element valueElement = new Element(VALUE_ELEMENT); value.writeExternal(valueElement); element.addContent(valueElement); attrElements.addContent(element); } else if (defaultAttr != defaultFallbackAttr) { element.setAttribute(BASE_ATTRIBUTES_ATTR, baseKey.getExternalName()); attrElements.addContent(element); } } } }
private void setupStyle() { Document document = myHTMLViewer.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument) document; EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); Style style = styledDocument.addStyle("active", null); StyleConstants.setFontFamily(style, scheme.getEditorFontName()); StyleConstants.setFontSize(style, scheme.getEditorFontSize()); styledDocument.setCharacterAttributes(0, document.getLength(), style, false); }
public void addImportedScheme(@NotNull final EditorColorsScheme imported) { MyColorScheme newScheme = new MyColorScheme(imported); initScheme(newScheme); mySchemes.put(imported.getName(), newScheme); selectScheme(newScheme.getName()); resetSchemesCombo(null); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value == ChooseByNameBase.NON_PREFIX_SEPARATOR) { Object previousElement = index > 0 ? list.getModel().getElementAt(index - 1) : null; return ChooseByNameBase.renderNonPrefixSeparatorComponent( getBackgroundColor(previousElement)); } else { Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font editorFont = new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize()); setFont(editorFont); return component; } }
public static Editor createEditor(boolean isReadOnly, final CharSequence text) { EditorFactory editorFactory = EditorFactory.getInstance(); Document doc = editorFactory.createDocument(text); Editor editor = (isReadOnly ? editorFactory.createViewer(doc) : editorFactory.createEditor(doc)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); EditorColorsScheme scheme = editor.getColorsScheme(); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); return editor; }
public void saveSchemeAs(String name) { MyColorScheme scheme = mySelectedScheme; if (scheme == null) return; EditorColorsScheme clone = (EditorColorsScheme) scheme.getOriginalScheme().clone(); scheme.apply(clone); clone.setName(name); MyColorScheme newScheme = new MyColorScheme(clone); initScheme(newScheme); newScheme.setIsNew(); mySchemes.put(name, newScheme); selectScheme(newScheme.getName()); resetSchemesCombo(null); }
private MarkupModelRangeIterator( @Nullable MarkupModel markupModel, @NotNull EditorColorsScheme colorsScheme, int startOffset, int endOffset) { myStartOffset = startOffset; myEndOffset = endOffset; myColorsScheme = colorsScheme; myDefaultForeground = colorsScheme.getDefaultForeground(); myDefaultBackground = colorsScheme.getDefaultBackground(); myUnsupportedModel = !(markupModel instanceof MarkupModelEx); if (myUnsupportedModel) { myIterator = null; return; } myIterator = ((MarkupModelEx) markupModel).overlappingIterator(startOffset, endOffset); findNextSuitableRange(); }
private void applyFontSize() { Document document = myEditorPane.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument) document; if (myFontSizeStyle == null) { myFontSizeStyle = styledDocument.addStyle("active", null); } EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); StyleConstants.setFontSize(myFontSizeStyle, scheme.getQuickDocFontSize().getSize()); if (Registry.is("documentation.component.editor.font")) { StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName()); } styledDocument.setCharacterAttributes(0, document.getLength(), myFontSizeStyle, false); }
protected void updateImpl(PresentationData data) { super.updateImpl(data); String newName; if (myBuilder.getTodoTreeStructure().isPackagesShown()) { newName = getValue().getName(); } else { newName = mySingleFileMode ? getValue().getName() : getValue().getVirtualFile().getPresentableUrl(); } int nameEndOffset = newName.length(); int todoItemCount; try { todoItemCount = myBuilder.getTodoTreeStructure().getTodoItemCount(getValue()); } catch (IndexNotReadyException e) { return; } if (mySingleFileMode) { if (todoItemCount == 0) { newName = IdeBundle.message("node.todo.no.items.found", newName); } else { newName = IdeBundle.message("node.todo.found.items", newName, todoItemCount); } } else { newName = IdeBundle.message("node.todo.items", newName, todoItemCount); } myHighlightedRegions.clear(); TextAttributes textAttributes = new TextAttributes(); textAttributes.setForegroundColor(myColor); myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes)); EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); myHighlightedRegions.add( new HighlightedRegion( nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES))); }
@Nullable @Override public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) { if (myDaemonSettings.SHOW_METHOD_SEPARATORS) { if (element instanceof DartMethodDeclaration || element instanceof DartFunctionDeclarationWithBody || element instanceof DartFunctionDeclarationWithBodyOrNative || element instanceof DartGetterDeclaration || element instanceof DartSetterDeclaration || element instanceof DartFactoryConstructorDeclaration || element instanceof AbstractDartMethodDeclarationImpl || element instanceof DartNamedConstructorDeclaration || element instanceof DartIncompleteDeclaration) { PsiElement markerLocation = element; while (markerLocation.getPrevSibling() != null && (markerLocation.getPrevSibling() instanceof PsiComment || (markerLocation.getPrevSibling() instanceof PsiWhiteSpace && markerLocation.getPrevSibling().getPrevSibling() != null && markerLocation.getPrevSibling().getPrevSibling() instanceof PsiComment))) { markerLocation = markerLocation.getPrevSibling(); } LineMarkerInfo info = new LineMarkerInfo<PsiElement>( markerLocation, markerLocation.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT); EditorColorsScheme scheme = myColorsManager.getGlobalScheme(); info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR); info.separatorPlacement = SeparatorPlacement.TOP; return info; } } return null; }
@Nullable protected static RangeHighlighter createHighlighter( @NotNull Project project, @NotNull Document document, int lineIndex) { if (lineIndex < 0 || lineIndex >= document.getLineCount()) { return null; } EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); RangeHighlighter highlighter = ((MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true)) .addPersistentLineHighlighter( lineIndex, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes); if (highlighter == null || !highlighter.isValid()) { return null; } highlighter.putUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY, Boolean.TRUE); highlighter.setErrorStripeTooltip( DebuggerBundle.message("breakpoint.tooltip.text", lineIndex + 1)); return highlighter; }
@Override public void apply() throws ConfigurationException { if (myApplyCompleted) { return; } try { EditorColorsManager myColorsManager = EditorColorsManager.getInstance(); myColorsManager.removeAllSchemes(); for (MyColorScheme scheme : mySchemes.values()) { if (!scheme.isDefault()) { scheme.apply(); myColorsManager.addColorsScheme(scheme.getOriginalScheme()); } } EditorColorsScheme originalScheme = mySelectedScheme.getOriginalScheme(); myColorsManager.setGlobalScheme(originalScheme); if (originalScheme != null && DarculaLaf.NAME.equals(originalScheme.getName()) && !UIUtil.isUnderDarcula()) { int ok = Messages.showYesNoDialog( "Darcula color scheme has been set for editors. Would you like to set Darcula as default Look and Feel?", "Darcula Look and Feel", Messages.getQuestionIcon()); if (ok == Messages.YES) { LafManager.getInstance().setCurrentLookAndFeel(new DarculaLookAndFeelInfo()); DarculaInstaller.install(); } } applyChangesToEditors(); reset(); } finally { myApplyCompleted = true; } }
public static TextAttributes getAttributesByType( @Nullable final PsiElement element, @NotNull HighlightInfoType type, @NotNull EditorColorsScheme colorsScheme) { final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(element != null ? element.getProject() : null); final TextAttributes textAttributes = severityRegistrar.getTextAttributesBySeverity(type.getSeverity(element)); if (textAttributes != null) { return textAttributes; } TextAttributesKey key = type.getAttributesKey(); return colorsScheme.getAttributes(key); }
private Editor createEditor() { EditorFactory editorFactory = EditorFactory.getInstance(); Document doc = myFile == null ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText()) : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile); Editor editor = myProject == null ? editorFactory.createEditor(doc) : editorFactory.createEditor(doc, myProject); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); editorSettings.setAdditionalColumnsCount(3); editorSettings.setAdditionalLinesCount(3); EditorColorsScheme scheme = editor.getColorsScheme(); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); editor .getDocument() .addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onTextChanged(); } }); ((EditorEx) editor).setHighlighter(createHighlighter()); mySplitter.setFirstComponent(editor.getComponent()); return editor; }
private void findNextSuitableRange() { myNextAttributes = null; while (myIterator.hasNext()) { RangeHighlighterEx highlighter = myIterator.next(); if (highlighter == null || !highlighter.isValid() || !isInterestedInLayer(highlighter.getLayer())) { continue; } // LINES_IN_RANGE highlighters are not supported currently myNextStart = Math.max(highlighter.getStartOffset(), myStartOffset); myNextEnd = Math.min(highlighter.getEndOffset(), myEndOffset); if (myNextStart >= myEndOffset) { break; } if (myNextStart < myCurrentEnd) { continue; // overlapping ranges withing document markup model are not supported currently } TextAttributes attributes = null; Object tooltip = highlighter.getErrorStripeTooltip(); if (tooltip instanceof HighlightInfo) { HighlightInfo info = (HighlightInfo) tooltip; TextAttributesKey key = info.forcedTextAttributesKey; if (key == null) { HighlightInfoType type = info.type; key = type.getAttributesKey(); } if (key != null) { attributes = myColorsScheme.getAttributes(key); } } if (attributes == null) { continue; } Color foreground = attributes.getForegroundColor(); Color background = attributes.getBackgroundColor(); if ((foreground == null || myDefaultForeground.equals(foreground)) && (background == null || myDefaultBackground.equals(background)) && attributes.getFontType() == Font.PLAIN) { continue; } myNextAttributes = attributes; break; } }