@Override public JComponent createTaskInfoPanel(Project project) { myTaskTextPane = new JTextPane(); final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane); myTaskTextPane.setContentType(new HTMLEditorKit().getContentType()); final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); final String fontName = editorColorsScheme.getEditorFontName(); final Font font = new Font(fontName, Font.PLAIN, fontSize); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }" + "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" + "code {font-family: Courier; display: flex; float: left; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}"; ((HTMLDocument)myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule); myTaskTextPane.setEditable(false); if (!UIUtil.isUnderDarcula()) { myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()); } myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10)); myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE); return scrollPane; }
public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder, @NotNull final JBColor color) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null, EffectType.BOXED, Font.PLAIN); textAttributes.setEffectColor(color); int startOffset = placeholder.getOffset(); if (startOffset == -1) { return; } final int length = placeholder.isActive() ? placeholder.getRealLength() : placeholder.getVisibleLength(placeholder.getActiveSubtaskIndex()); Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument()); startOffset = offsets.first; int endOffset = offsets.second; if (placeholder.isActive()) { drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, PLACEHOLDERS_LAYER); } else if (!placeholder.getUseLength() && length != 0) { drawAnswerPlaceholderFromPrevStep(editor, startOffset, endOffset); } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { // Cells are by default rendered as a JLabel. JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); //Get the status for the current row. TranslationTableModel tableModel = (TranslationTableModel) table.getModel(); if (col != 0 && tableModel.getStatus(row, col) == TranslationTableModel.EMPTY) { l.setBackground(new JBColor(new Color(244, 128, 36, 60), new Color(244, 128, 36))); } else { if(isSelected) { l.setForeground(EditorColorsManager.getInstance().getSchemeForCurrentUITheme().getDefaultForeground()); } l.setBackground(EditorColorsManager.getInstance().getSchemeForCurrentUITheme().getDefaultBackground()); } return l; }
private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) { EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES); HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject()); Iterator iterator = ranges.iterator(); while (iterator.hasNext()) { TextRange range = (TextRange) iterator.next(); //highlightManager.addOccurrenceHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, 0, highlighters, (Color) null); highlightManager.addRangeHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, false, highlighters); } iterator = highlighters.iterator(); while (iterator.hasNext()) { RangeHighlighter highlighter = (RangeHighlighter) iterator.next(); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); } }
public static RemoveUnusedVariableUtil.RemoveMode showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) { if (sideEffects.isEmpty()) return RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL; if (ApplicationManager.getApplication().isUnitTestMode()) { return canCopeWithSideEffects ? RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT : RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL; } Project project = editor.getProject(); HighlightManager highlightManager = HighlightManager.getInstance(project); PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null); SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects); dialog.show(); int code = dialog.getExitCode(); return RemoveUnusedVariableUtil.RemoveMode.values()[code]; }
private static void highlightOccurrences(String filter, Project project, Editor editor) { final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorManager = EditorColorsManager.getInstance(); final TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); String documentText = editor.getDocument().getText(); int i = -1; while (true) { int nextOccurrence = StringUtil.indexOfIgnoreCase(documentText, filter, i + 1); if (nextOccurrence < 0) { break; } i = nextOccurrence; highlightManager.addOccurrenceHighlight(editor, i, i + filter.length(), attributes, HighlightManager.HIDE_BY_TEXT_CHANGE, null, null); } }
/** * @return List of highlighters */ public static List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor) { ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (occurrences.length > 1) { for (PsiElement occurrence : occurrences) { final RangeMarker rangeMarker = occurrence.getUserData(ElementToWorkOn.TEXT_RANGE); if (rangeMarker != null && rangeMarker.isValid()) { highlightManager .addRangeHighlight(editor, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), attributes, true, highlighters); } else { final TextRange textRange = occurrence.getTextRange(); highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters); } } } return highlighters; }
public void testScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); try { testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }
private static void paintLine(@NotNull Graphics g, @NotNull int[] xPoints, @NotNull int[] yPoints, int lineHeight, @Nullable EditorColorsScheme scheme) { int height = getHeight(lineHeight); if (scheme == null) scheme = EditorColorsManager.getInstance().getGlobalScheme(); Graphics2D gg = ((Graphics2D)g); AffineTransform oldTransform = gg.getTransform(); for (int i = 0; i < height; i++) { Color color = getTopBorderColor(i, lineHeight, scheme); if (color == null) color = getBottomBorderColor(i, lineHeight, scheme); if (color == null) color = getBackgroundColor(scheme); gg.setColor(color); gg.drawPolyline(xPoints, yPoints, xPoints.length); gg.translate(0, 1); } gg.setTransform(oldTransform); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(new JBColor(new NotNullProducer<Color>() { @NotNull @Override public Color produce() { //noinspection UseJBColor return !darkBackground() ? new Color(0xffffcc) : new Color(0x675133); } })); g.fillRect(x, y, getIconWidth(), getIconHeight()); g.setColor(JBColor.GRAY); g.drawRect(x, y, getIconWidth(), getIconHeight()); g.setColor(EditorColorsManager.getInstance().getGlobalScheme().getDefaultForeground()); final Font oldFont = g.getFont(); g.setFont(MNEMONIC_FONT); ((Graphics2D)g).drawString(Character.toString(myMnemonic), x + 3, y + getIconHeight() - 1.5F); g.setFont(oldFont); }
private EditorHighlighter createHighlighter() { if (myTemplate != null && myVelocityFileType != FileTypes.UNKNOWN) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, new LightVirtualFile("aaa." + myTemplate.getExtension() + ".ft")); } FileType fileType = null; if (myTemplate != null) { fileType = FileTypeManager.getInstance().getFileTypeByExtension(myTemplate.getExtension()); } if (fileType == null) { fileType = FileTypes.PLAIN_TEXT; } SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null); if (originalHighlighter == null) { originalHighlighter = new PlainSyntaxHighlighter(); } final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), scheme); highlighter.registerLayer(FileTemplateTokenType.TEXT, new LayerDescriptor(originalHighlighter, "")); return highlighter; }
private SimpleTextAttributes getAttribute(@NotNull final SimpleTextAttributes attrs, @Nullable HighlightDisplayLevel level) { if (level == null) { return attrs; } Map<SimpleTextAttributes, SimpleTextAttributes> highlightMap = myHighlightAttributes.get(level.getSeverity()); if (highlightMap == null) { highlightMap = new HashMap<SimpleTextAttributes, SimpleTextAttributes>(); myHighlightAttributes.put(level.getSeverity(), highlightMap); } SimpleTextAttributes result = highlightMap.get(attrs); if (result == null) { final TextAttributesKey attrKey = SeverityRegistrar.getSeverityRegistrar(myProject).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey(); TextAttributes textAttrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attrKey); textAttrs = TextAttributes.merge(attrs.toTextAttributes(), textAttrs); result = SimpleTextAttributes.fromTextAttributes(textAttrs); highlightMap.put(attrs, result); } return result; }
public GeneralHighlightingPass(@NotNull Project project, @NotNull PsiFile file, @NotNull Document document, int startOffset, int endOffset, boolean updateAll, @NotNull ProperTextRange priorityRange, @Nullable Editor editor, @NotNull HighlightInfoProcessor highlightInfoProcessor) { super(project, document, PRESENTABLE_NAME, file, editor, TextRange.create(startOffset, endOffset), true, highlightInfoProcessor); myUpdateAll = updateAll; myPriorityRange = priorityRange; PsiUtilCore.ensureValid(file); boolean wholeFileHighlighting = isWholeFileHighlighting(); myHasErrorElement = !wholeFileHighlighting && Boolean.TRUE.equals(getFile().getUserData(HAS_ERROR_ELEMENT)); final DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); FileStatusMap fileStatusMap = daemonCodeAnalyzer.getFileStatusMap(); myErrorFound = !wholeFileHighlighting && fileStatusMap.wasErrorFound(getDocument()); // initial guess to show correct progress in the traffic light icon setProgressLimit(document.getTextLength()/2); // approx number of PSI elements = file length/2 myGlobalScheme = editor != null ? editor.getColorsScheme() : EditorColorsManager.getInstance().getGlobalScheme(); }
protected static Editor createEditor(String text, int column, int line, int selectedLine) { EditorFactory editorFactory = EditorFactory.getInstance(); Document editorDocument = editorFactory.createDocument(text); EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); editor.setColorsScheme(scheme); EditorSettings settings = editor.getSettings(); settings.setWhitespacesShown(true); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setFoldingOutlineShown(false); settings.setAdditionalColumnsCount(0); settings.setAdditionalLinesCount(0); settings.setRightMarginShown(true); settings.setRightMargin(60); LogicalPosition pos = new LogicalPosition(line, column); editor.getCaretModel().moveToLogicalPosition(pos); if (selectedLine >= 0) { editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine), editorDocument.getLineEndOffset(selectedLine)); } return editor; }
private void applyFontSize() { Document document = myEditorPane.getDocument(); if (!(document instanceof StyledDocument)) { return; } final StyledDocument styledDocument = (StyledDocument)document; 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()); } ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { styledDocument.setCharacterAttributes(0, styledDocument.getLength(), myFontSizeStyle, false); } }); }
public EditorComponentImpl(@NotNull EditorImpl editor) { myEditor = editor; enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.INPUT_METHOD_EVENT_MASK); enableInputMethods(true); setFocusCycleRoot(true); setOpaque(true); putClientProperty(Magnificator.CLIENT_PROPERTY_KEY, new Magnificator() { @Override public Point magnify(double scale, Point at) { VisualPosition magnificationPosition = myEditor.xyToVisualPosition(at); double currentSize = myEditor.getColorsScheme().getEditorFontSize(); int defaultFontSize = EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize(); myEditor.setFontSize(Math.max((int)(currentSize * scale), defaultFontSize)); return myEditor.visualPositionToXY(magnificationPosition); } }); myApplication = (ApplicationImpl)ApplicationManager.getApplication(); }
@NotNull private static JTextPane createTaskTextPane() { final JTextPane taskTextPane = new JTextPane(); taskTextPane.setContentType(new HTMLEditorKit().getContentType()); final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); final String fontName = editorColorsScheme.getEditorFontName(); final Font font = new Font(fontName, Font.PLAIN, fontSize); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)taskTextPane.getDocument()).getStyleSheet().addRule(bodyRule); taskTextPane.setEditable(false); if (!UIUtil.isUnderDarcula()) { taskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()); } taskTextPane.setBorder(new EmptyBorder(15, 20, 0, 100)); return taskTextPane; }
private void highlightUsages() { if (mySearchResults.getEditor() == null) return; if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) return; for (FindResult range : mySearchResults.getOccurrences()) { if (range.getEndOffset() > mySearchResults.getEditor().getDocument().getTextLength()) continue; TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); if (range.getLength() == 0) { attributes = attributes.clone(); attributes.setEffectType(EffectType.BOXED); attributes.setEffectColor(attributes.getBackgroundColor()); } if (mySearchResults.isExcluded(range)) { highlightRange(range, strikeout(), myHighlighters); } else { highlightRange(range, attributes, myHighlighters); } } updateInSelectionHighlighters(); if (!myListeningSelection) { mySearchResults.getEditor().getSelectionModel().addSelectionListener(this); myListeningSelection = true; } }
@Override public void itemHovered(@Nullable BreadcrumbsPsiItem item) { if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) { return; } HighlightManager hm = HighlightManager.getInstance(myProject); if (myHighlighed != null) { for (RangeHighlighter highlighter : myHighlighed) { hm.removeSegmentHighlighter(myEditor, highlighter); } myHighlighed = null; } if (item != null) { final TextRange range = item.getPsiElement().getTextRange(); final TextAttributes attributes = new TextAttributes(); final CrumbPresentation p = item.getPresentation(); final Color color = p != null ? p.getBackgroundColor(false, false, false) : BreadcrumbsComponent.ButtonSettings.DEFAULT_BG_COLOR; final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR); attributes.setBackgroundColor(XmlTagTreeHighlightingUtil.makeTransparent(color, background != null ? background : Gray._200, 0.3)); myHighlighed = new ArrayList<RangeHighlighter>(1); int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY; hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null); } }
@Override public void projectOpened() { StartupManager.getInstance(myProject).registerPreStartupActivity(new Runnable() { @Override public void run() { final MyFileStatusListener fileStatusListener = new MyFileStatusListener(); final EditorFactoryListener editorFactoryListener = new MyEditorFactoryListener(); final MyVirtualFileListener virtualFileListener = new MyVirtualFileListener(); final EditorColorsListener editorColorsListener = new MyEditorColorsListener(); final FileStatusManager fsManager = FileStatusManager.getInstance(myProject); fsManager.addFileStatusListener(fileStatusListener, myDisposable); final EditorFactory editorFactory = EditorFactory.getInstance(); editorFactory.addEditorFactoryListener(editorFactoryListener, myDisposable); final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); virtualFileManager.addVirtualFileListener(virtualFileListener, myDisposable); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); editorColorsManager.addEditorColorsListener(editorColorsListener, myDisposable); } }); }
public void renderElement(LookupElement element, LookupElementPresentation presentation) { Suggestion suggestion = (Suggestion) element.getObject(); if (suggestion.icon != null) { presentation.setIcon(suggestion.icon); } presentation.setStrikeout(suggestion.deprecationLevel != null); if (suggestion.deprecationLevel != null) { if (suggestion.deprecationLevel == SpringConfigurationMetadataDeprecationLevel.error) { presentation.setItemTextForeground(RED); } else { presentation.setItemTextForeground(YELLOW); } } String lookupString = element.getLookupString(); presentation.setItemText(lookupString); if (!lookupString.equals(suggestion.suggestion)) { presentation.setItemTextBold(true); } String shortDescription; if (suggestion.defaultValue != null) { shortDescription = shortenTextWithEllipsis(suggestion.defaultValue, 60, 0, true); TextAttributes attrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SCALAR_TEXT); presentation.setTailText("=" + shortDescription, attrs.getForegroundColor()); } if (suggestion.description != null) { presentation.appendTailText( " (" + Util.getFirstSentenceWithoutDot(suggestion.description) + ")", true); } if (suggestion.shortType != null) { presentation.setTypeText(suggestion.shortType); } }
private static TextAttributes getNormalAttributes() { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.INLINED_VALUES); if (attributes == null || attributes.getForegroundColor() == null) { return new TextAttributes(new JBColor(Gray._135, new Color(0x3d8065)), null, null, null, Font.ITALIC); } return attributes; }
@Contract protected void modifyHighlightedArea( @NotNull final Editor editor, @NotNull final List<PsiElement> column, final boolean clear ) { Validate.notNull(editor); Validate.notNull(column); if (null == editor.getProject()) { return; } if (editor.getProject().isDisposed()) { return; } // This list must be modifiable // https://bitbucket.org/AlexanderBartash/impex-editor-intellij-idea-plugin/issue/11/unsupportedoperationexception-null final List<TextRange> ranges = newArrayList(); column.forEach((cell) -> ranges.add(cell.getTextRange())); HighlightUsagesHandler.highlightRanges( HighlightManager.getInstance(editor.getProject()), editor, EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES), clear, ranges ); }
@Contract(pure = false) protected void modifyHighlightedArea( @NotNull final Editor editor, @NotNull final PsiElement impexFullHeaderParameter, final boolean clear ) { Validate.notNull(editor); Validate.notNull(impexFullHeaderParameter); if (null == editor.getProject()) { return; } if (editor.getProject().isDisposed()) { return; } // This list must be modifiable // https://bitbucket.org/AlexanderBartash/impex-editor-intellij-idea-plugin/issue/11/unsupportedoperationexception-null final List<TextRange> ranges = new ArrayList<TextRange>(); ranges.add(impexFullHeaderParameter.getTextRange()); HighlightUsagesHandler.highlightRanges( HighlightManager.getInstance(editor.getProject()), editor, EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES), clear, ranges ); }
public static void drawAnswerPlaceholderFromPrevStep(@NotNull Editor editor, int start, int end) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Color color = scheme.getColor(EditorColors.TEARLINE_COLOR); SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES; final TextAttributes textAttributes = new TextAttributes(attributes.getFgColor(), color, null, null, attributes.getFontStyle()); drawAnswerPlaceholder(editor, start, end, textAttributes, HighlighterLayer.LAST); }
private CommandInputForm(final JFrame ideFrame, Component sourceComponent, AnActionEvent originalEvent) { super(ideFrame, true); this.ideFrame = ideFrame; this.setUndecorated(true); this.sourceComponent = sourceComponent; this.originalEvent = originalEvent; this.add(topPanel); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font commandFont = new Font(scheme.getConsoleFontName(), Font.PLAIN, scheme.getConsoleFontSize()); commandField.setFont(commandFont); this.pack(); popupMenu = new JPopupMenu(); topPanel.setComponentPopupMenu(popupMenu); topPanel.setBorder(BorderFactory.createLineBorder(JBColor.gray)); this.setAlwaysOnTop(true); commandField.setRequestFocusEnabled(true); commandField.addActionListener(e -> { }); KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); commandField.registerKeyboardAction(e -> { popupMenu.setVisible(false); CommandInputForm.this.setVisible(false); CommandInputForm.this.dispose(); currTyped = null; focusOnIdeFrame(ideFrame); }, escKeyStroke, JComponent.WHEN_FOCUSED); commandField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent documentEvent) { onTextChange(); } }); }
public static Color errorColor() { TextAttributes attribute = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.ERRORS_ATTRIBUTES); Color color = JBColor.RED; if (attribute != null) { if (attribute.getForegroundColor() != null) { color = attribute.getForegroundColor(); } else if (attribute.getEffectColor() != null) { color = attribute.getEffectColor(); } else if (attribute.getErrorStripeColor() != null) { color = attribute.getErrorStripeColor(); } } return color; }
public static Color warningColor() { TextAttributes attribute = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.WARNINGS_ATTRIBUTES); Color color = JBColor.ORANGE; if (attribute != null) { if (attribute.getForegroundColor() != null) { color = attribute.getForegroundColor(); } else if (attribute.getEffectColor() != null) { color = attribute.getEffectColor(); } else if (attribute.getErrorStripeColor() != null) { color = attribute.getErrorStripeColor(); } } return color; }
public void testYieldInNestedFunction() { // highlight func declaration first, lest we get an "Extra fragment highlighted" error. EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = TextAttributesKey.find("PY.FUNC_DEFINITION"); TextAttributes xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD); scheme.setAttributes(xKey, xAttributes); doTest(); }
private void setupStyle() { // Make the scrollPane transparent if (myScrollPane != null) { JViewport viewPort = myScrollPane.getViewport(); viewPort.setOpaque(false); viewPort.setBackground(null); myScrollPane.setOpaque(false); myScrollPane.setBackground(null); } 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); // Make background semitransparent Color background = myHTMLViewer.getBackground(); if (background != null) { background = new Color(background.getRed(), background.getGreen(), background.getBlue(), ERROR_PANEL_OPACITY); myHTMLViewer.setBackground(background); } }
public DebuggerManagerImpl(Project project, StartupManager startupManager, EditorColorsManager colorsManager) { myProject = project; myBreakpointManager = new BreakpointManager(myProject, startupManager, this); if (!project.isDefault()) { colorsManager.addEditorColorsListener(new EditorColorsListener() { @Override public void globalSchemeChange(EditorColorsScheme scheme) { getBreakpointManager().updateBreakpointsUI(); } }, project); } }
@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); }
@Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { PsiAssignmentExpression assignment = getAssignmentUnderCaret(editor, file); if (assignment == null) return; PsiField field = getAssignedField(assignment); if (field == null) return; if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; List<PsiAssignmentExpression> assignments = new ArrayList<PsiAssignmentExpression>(); if (!isInitializedWithSameExpression(field, assignment, assignments)) return; PsiExpression initializer = assignment.getRExpression(); field.setInitializer(initializer); for (PsiAssignmentExpression assignmentExpression : assignments) { PsiElement statement = assignmentExpression.getParent(); PsiElement parent = statement.getParent(); if (parent instanceof PsiIfStatement || parent instanceof PsiWhileStatement || parent instanceof PsiForStatement || parent instanceof PsiForeachStatement) { PsiStatement emptyStatement = JavaPsiFacade.getInstance(file.getProject()).getElementFactory().createStatementFromText(";", statement); statement.replace(emptyStatement); } else { statement.delete(); } } TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); HighlightManager.getInstance(project).addOccurrenceHighlights(editor, new PsiElement[]{field.getInitializer()}, attributes, false, null); }
public static void highlightOccurrences(Project project, @Nullable Editor editor, PsiElement[] elements) { if (editor == null) return; ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (elements.length > 0) { highlightManager.addOccurrenceHighlights(editor, elements, attributes, false, highlighters); } }
private void showMultipleExitPointsMessage() { if (myShowErrorDialogs) { HighlightManager highlightManager = HighlightManager.getInstance(myProject); PsiStatement[] exitStatementsArray = myExitStatements.toArray(new PsiStatement[myExitStatements.size()]); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights(myEditor, exitStatementsArray, attributes, true, null); String message = RefactoringBundle .getCannotRefactorMessage(RefactoringBundle.message("there.are.multiple.exit.points.in.the.selected.code.fragment")); CommonRefactoringUtil.showErrorHint(myProject, myEditor, message, myRefactoringName, myHelpId); WindowManager.getInstance().getStatusBar(myProject).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting")); } }
public static void highlightPrepareError(PrepareFailedException e, PsiFile file, Editor editor, final Project project) { if (e.getFile() == file) { final TextRange textRange = e.getTextRange(); final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, null); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset()); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting")); } }
public static String printWithHighlighting(@NotNull LanguageConsoleView console, @NotNull Editor inputEditor, @NotNull TextRange textRange) { String text; EditorHighlighter highlighter; if (inputEditor instanceof EditorWindow) { PsiFile file = ((EditorWindow)inputEditor).getInjectedFile(); highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), console.getProject()); String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null); highlighter.setText(fullText); text = textRange.substring(fullText); } else { text = inputEditor.getDocument().getText(textRange); highlighter = ((EditorEx)inputEditor).getHighlighter(); } SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter)highlighter).getSyntaxHighlighter() : null; ((LanguageConsoleImpl)console).doAddPromptToHistory(); if (syntax != null) { ConsoleViewUtil.printWithHighlighting(console, text, syntax); } else { console.print(text, ConsoleViewContentType.USER_INPUT); } console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); return text; }
private static void highlightError(Project project, Editor editor, PsiElement errorElement) { if (editor != null) { final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final TextRange textRange = errorElement.getTextRange(); HighlightManager.getInstance(project).addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, new ArrayList<RangeHighlighter>()); } }
@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; }
public void testSharedScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); NamedScope projectScope = PackagesScopesProvider.getInstance(myProject).getProjectProductionScope(); TextAttributesKey projectKey = ScopeAttributesUtil.getScopeTextAttributeKey(projectScope.getName()); TextAttributes projectAttributes = new TextAttributes(null, null, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(projectKey, projectAttributes); try { testFile(BASE_PATH + "/scopeBased/x/Shared.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }