下面列出了com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider#com.intellij.openapi.editor.colors.EditorColorsScheme 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createUIComponents() {
final EditorFactory editorFactory = EditorFactory.getInstance();
jsonDocument = editorFactory.createDocument(EMPTY_TEXT);
jsonEditor = editorFactory.createEditor(jsonDocument, project, JsonFileType.INSTANCE, false);
final EditorSettings settings = jsonEditor.getSettings();
settings.setWhitespacesShown(true);
settings.setLineMarkerAreaShown(false);
settings.setIndentGuidesShown(false);
settings.setLineNumbersShown(true);
settings.setFoldingOutlineShown(false);
settings.setRightMarginShown(false);
settings.setVirtualSpace(false);
settings.setWheelFontChangeEnabled(false);
settings.setUseSoftWraps(false);
settings.setAdditionalColumnsCount(0);
settings.setAdditionalLinesCount(1);
final EditorColorsScheme colorsScheme = jsonEditor.getColorsScheme();
colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null);
jsonEditor.getContentComponent().setFocusable(true);
jsonPanel = (JPanel) jsonEditor.getComponent();
}
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());
}
private 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;
}
@Override
public void highlightsOutsideVisiblePartAreProduced(@Nonnull final HighlightingSession session,
@Nullable Editor editor,
@Nonnull final List<? extends HighlightInfo> infos,
@Nonnull final TextRange priorityRange,
@Nonnull final TextRange restrictedRange, final int groupId) {
final PsiFile psiFile = session.getPsiFile();
final Project project = psiFile.getProject();
final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) return;
final long modificationStamp = document.getModificationStamp();
((HighlightingSessionImpl)session).applyInEDT(() -> {
if (project.isDisposed() || modificationStamp != document.getModificationStamp()) return;
EditorColorsScheme scheme = session.getColorsScheme();
UpdateHighlightersUtil
.setHighlightersOutsideRange(project, document, psiFile, infos, scheme, restrictedRange.getStartOffset(), restrictedRange.getEndOffset(), ProperTextRange.create(priorityRange), groupId);
if (editor != null) {
repaintErrorStripeAndIcon(editor, project);
}
});
}
public static EditorImpl createEditorPreview(String text, boolean editable) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
ColorAndFontOptions options = new ColorAndFontOptions();
options.reset();
options.selectScheme(scheme.getName());
EditorFactory editorFactory = EditorFactory.getInstance();
Document editorDocument = editorFactory.createDocument(text);
EditorEx editor = (EditorEx) (editable ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
editor.setColorsScheme(scheme);
EditorSettings settings = editor.getSettings();
settings.setLineNumbersShown(true);
settings.setWhitespacesShown(false);
settings.setLineMarkerAreaShown(false);
settings.setIndentGuidesShown(false);
settings.setFoldingOutlineShown(false);
settings.setAdditionalColumnsCount(0);
settings.setAdditionalLinesCount(0);
settings.setRightMarginShown(false);
return (EditorImpl) editor;
}
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements)
{
final HighlightManager highlightManager =
HighlightManager.getInstance(project);
final EditorColorsManager editorColorsManager =
EditorColorsManager.getInstance();
final EditorColorsScheme globalScheme =
editorColorsManager.getGlobalScheme();
final TextAttributes textattributes =
globalScheme.getAttributes(
EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
highlightManager.addOccurrenceHighlights(
editor, elements, textattributes, true, null);
final WindowManager windowManager = WindowManager.getInstance();
final StatusBar statusBar = windowManager.getStatusBar(project);
statusBar.setInfo("Press Esc to remove highlighting");
}
@Nonnull
@Override
public EditorColorsScheme[] getAllSchemes() {
List<EditorColorsScheme> schemes = mySchemesManager.getAllSchemes();
EditorColorsScheme[] result = schemes.toArray(new EditorColorsScheme[schemes.size()]);
Arrays.sort(result, new Comparator<EditorColorsScheme>() {
@Override
public int compare(@Nonnull EditorColorsScheme s1, @Nonnull EditorColorsScheme s2) {
if (isDefaultScheme(s1) && !isDefaultScheme(s2)) return -1;
if (!isDefaultScheme(s1) && isDefaultScheme(s2)) return 1;
if (s1.getName().equals(DEFAULT_NAME)) return -1;
if (s2.getName().equals(DEFAULT_NAME)) return 1;
return s1.getName().compareToIgnoreCase(s2.getName());
}
});
return result;
}
public LookupCellRenderer(LookupImpl lookup) {
EditorColorsScheme scheme = lookup.getTopLevelEditor().getColorsScheme();
myNormalFont = scheme.getFont(EditorFontType.PLAIN);
myBoldFont = scheme.getFont(EditorFontType.BOLD);
myLookup = lookup;
myNameComponent = new MySimpleColoredComponent();
myNameComponent.setIpad(JBUI.insetsLeft(2));
myNameComponent.setMyBorder(null);
myTailComponent = new MySimpleColoredComponent();
myTailComponent.setIpad(JBUI.emptyInsets());
myTailComponent.setBorder(JBUI.Borders.emptyRight(10));
myTypeLabel = new MySimpleColoredComponent();
myTypeLabel.setIpad(JBUI.emptyInsets());
myTypeLabel.setBorder(JBUI.Borders.emptyRight(6));
myPanel = new LookupPanel();
myPanel.add(myNameComponent, BorderLayout.WEST);
myPanel.add(myTailComponent, BorderLayout.CENTER);
myPanel.add(myTypeLabel, BorderLayout.EAST);
myNormalMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myNormalFont);
myBoldMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myBoldFont);
}
@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);
applyChangesToEditors();
reset();
}
finally {
myApplyCompleted = true;
}
}
private HighlightingSessionImpl(@Nonnull PsiFile psiFile, @Nonnull DaemonProgressIndicator progressIndicator, EditorColorsScheme editorColorsScheme) {
myPsiFile = psiFile;
myProgressIndicator = progressIndicator;
myEditorColorsScheme = editorColorsScheme;
myProject = psiFile.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
myEDTQueue = new TransferToEDTQueue<Runnable>("Apply highlighting results", runnable -> {
runnable.run();
return true;
}, o -> myProject.isDisposed() || getProgressIndicator().isCanceled()) {
@Override
protected void schedule(@Nonnull Runnable updateRunnable) {
ApplicationManager.getApplication().invokeLater(updateRunnable, ModalityState.any());
}
};
}
@Nonnull
protected Editor createEditor(@Nullable Project project, Document document, VirtualFile file) {
EditorEx editor = (EditorEx)EditorFactory.getInstance().createViewer(document, project);
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
editor.setFile(file);
editor.setHighlighter(highlighter);
EditorSettings settings = editor.getSettings();
settings.setAnimatedScrolling(false);
settings.setRefrainFromScrolling(false);
settings.setLineNumbersShown(true);
settings.setFoldingOutlineShown(false);
if (settings instanceof SettingsImpl) {
((SettingsImpl)settings).setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.PREVIEW);
}
editor.getFoldingModel().setFoldingEnabled(false);
return editor;
}
@Override
public Component getListCellRendererComponent(JList<? extends RecentLocationItem> list, RecentLocationItem value, int index, boolean selected, boolean hasFocus) {
EditorEx editor = value.getEditor();
if (myProject.isDisposed() || editor.isDisposed()) {
return super.getListCellRendererComponent(list, value, index, selected, hasFocus);
}
EditorColorsScheme colorsScheme = editor.getColorsScheme();
String breadcrumbs = myData.getBreadcrumbsMap(myCheckBox.isSelected()).get(value.getInfo());
JPanel panel = new JPanel(new VerticalFlowLayout(0, 0));
if (index != 0) {
panel.add(createSeparatorLine(colorsScheme));
}
panel.add(createTitleComponent(myProject, list, mySpeedSearch, breadcrumbs, value.getInfo(), colorsScheme, selected));
panel.add(setupEditorComponent(editor, editor.getDocument().getText(), mySpeedSearch, colorsScheme, selected));
return panel;
}
protected FluidFileType() {
super(FluidLanguage.INSTANCE);
FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() {
public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
return new FluidTemplateHighlighter(project, virtualFile, colors);
}
});
}
@Nonnull
public EditorColorsScheme getColorsScheme(@Nonnull EditorColorsScheme editorColorsScheme) {
EditorColorsScheme result = null;
if (mySchemeName != null && !ACTIVE_GLOBAL_SCHEME_MARKER.equals(mySchemeName)) {
result = EditorColorsManager.getInstance().getScheme(mySchemeName);
}
return result == null ? editorColorsScheme : result;
}
public boolean updateDescription(boolean modified) {
EditorColorsScheme scheme = myOptions.getSelectedScheme();
if (modified && (ColorAndFontOptions.isReadOnly(scheme))) {
FontOptions.showReadOnlyMessage(this, false);
return false;
}
return true;
}
@Nullable
private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) {
if (psiFile.getContext() != null || !RTFileUtil.isRTFile(psiFile)) {
return null;
}
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
return null;
}
if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
return null;
}
Project project = psiFile.getProject();
RTProjectComponent component = project.getComponent(RTProjectComponent.class);
if (component == null || !component.isValidAndEnabled()) {
return null;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) {
return null;
}
String fileContent = document.getText();
if (StringUtil.isEmptyOrSpaces(fileContent)) {
return null;
}
EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme();
// tabSize = getTabSize(editor);
// tabSize = 4;
return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme);
}
public ColorAndFontDescription(String name, String group, String type, EditorColorsScheme scheme, final Image icon, final String toolTip) {
myName = name;
myGroup = group;
myType = type;
myScheme = scheme;
myIcon = icon;
myToolTip = toolTip;
}
@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);
}
@Nonnull
public static Color getDividerColorFromScheme(@Nonnull EditorColorsScheme scheme) {
Color gutterBackground = scheme.getColor(EditorColors.GUTTER_BACKGROUND);
if (gutterBackground == null) {
gutterBackground = EditorColors.GUTTER_BACKGROUND.getDefaultColor();
}
return gutterBackground;
}
@Nonnull
public static LineMarkerInfo<PsiElement> createMethodSeparatorLineMarker(@Nonnull PsiElement startFrom, @Nonnull EditorColorsManager colorsManager) {
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(startFrom, startFrom.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = colorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
@Nonnull
public static List<DividerSeparator> createVisibleSeparators(@Nonnull Editor editor1,
@Nonnull Editor editor2,
@Nonnull DividerSeparatorPaintable paintable) {
final List<DividerSeparator> separators = new ArrayList<DividerSeparator>();
final Transformation[] transformations = new Transformation[]{getTransformation(editor1), getTransformation(editor2)};
final Interval leftInterval = getVisibleInterval(editor1);
final Interval rightInterval = getVisibleInterval(editor2);
final int height1 = editor1.getLineHeight();
final int height2 = editor2.getLineHeight();
final EditorColorsScheme scheme = editor1.getColorsScheme();
paintable.process(new DividerSeparatorPaintable.Handler() {
@Override
public boolean process(int line1, int line2) {
if (leftInterval.startLine > line1 + 1 && rightInterval.startLine > line2 + 1) return true;
if (leftInterval.endLine < line1 && rightInterval.endLine < line2) return false;
separators.add(createSeparator(transformations, line1, line2, height1, height2, scheme));
return true;
}
});
return separators;
}
private void highlightBrace(@Nonnull TextRange braceRange, boolean matched) {
EditorColorsScheme scheme = myEditor.getColorsScheme();
final TextAttributes attributes =
matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
: scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
RangeHighlighter rbraceHighlighter =
myEditor.getMarkupModel().addRangeHighlighter(
braceRange.getStartOffset(), braceRange.getEndOffset(), HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE);
rbraceHighlighter.setGreedyToLeft(false);
rbraceHighlighter.setGreedyToRight(false);
registerHighlighter(rbraceHighlighter);
}
public void invokeHint(Runnable hideRunnable) {
myHideRunnable = hideRunnable;
if (!canShowHint()) {
hideHint();
return;
}
if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);
myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
HighlighterLayer.SELECTION + 1, attributes,
HighlighterTargetArea.EXACT_RANGE);
Component internalComponent = myEditor.getContentComponent();
myStoredCursor = internalComponent.getCursor();
internalComponent.addKeyListener(myEditorKeyListener);
internalComponent.setCursor(hintCursor());
if (LOG.isDebugEnabled()) {
LOG.debug("internalComponent.setCursor(hintCursor())");
}
}
else {
evaluateAndShowHint();
}
}
@Override
public void apply(EditorColorsScheme scheme) {
if (myGetSetBackground != null) {
myGetSetBackground.apply(scheme);
}
if (myGetSetForeground != null) {
myGetSetForeground.apply(scheme);
}
}
public void addImportedScheme(@Nonnull final EditorColorsScheme imported) {
MyColorScheme newScheme = new MyColorScheme(imported, EditorColorsManager.getInstance());
initScheme(newScheme);
mySchemes.put(imported.getName(), newScheme);
selectScheme(newScheme.getName());
resetSchemesCombo(null);
}
@Override
public void execute(@Nonnull Editor editor, DataContext dataContext) {
if (!(editor instanceof EditorEx)) {
return;
}
EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
int fontSize = ConsoleViewUtil.isConsoleViewEditor(editor) ? globalScheme.getConsoleFontSize() : globalScheme.getEditorFontSize();
EditorEx editorEx = (EditorEx)editor;
editorEx.setFontSize(fontSize);
}
private void applyLaf(String lafName, Component component) {
UIManager.LookAndFeelInfo info = getLookAndFeelInfo(lafName);
if (info == null) return;
try {
UIManager.setLookAndFeel(info.getClassName());
if (!myInitial) {
LafManager.getInstance().setCurrentLookAndFeel(info);
if(info instanceof LafWithColorScheme) {
EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = editorColorsManager.getScheme(((LafWithColorScheme)info).getColorSchemeName());
if(scheme != null) {
editorColorsManager.setGlobalScheme(scheme);
}
}
}
Window window = SwingUtilities.getWindowAncestor(component);
if (window != null) {
window.setBackground(new Color(UIUtil.getPanelBackground().getRGB()));
SwingUtilities.updateComponentTreeUI(window);
}
if (myColumnMode) {
myPreviewLabel.setIcon(myLafNames.get(lafName));
myPreviewLabel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Label.foreground")));
}
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
private static SeverityRegistrar.SeverityBasedTextAttributes getSeverityBasedTextAttributes(@Nonnull SeverityRegistrar registrar, @Nonnull HighlightInfoType type) {
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
if (textAttributes != null) {
return new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes, (HighlightInfoType.HighlightInfoTypeImpl)type);
}
return new SeverityRegistrar.SeverityBasedTextAttributes(registrar.getTextAttributesBySeverity(type.getSeverity(null)), (HighlightInfoType.HighlightInfoTypeImpl)type);
}
@Override
public EditorColorsScheme clone() {
EditorColorsSchemeImpl newScheme = new EditorColorsSchemeImpl(myParentScheme, myEditorColorsManager);
copyTo(newScheme);
newScheme.setName(getName());
return newScheme;
}
@Nonnull
protected Runnable loadEditorInBackground() {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, scheme, myProject);
EditorEx editor = (EditorEx)getEditor();
highlighter.setText(editor.getDocument().getImmutableCharSequence());
return () -> editor.setHighlighter(highlighter);
}