use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class InspectionListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
final BorderLayout layout = new BorderLayout();
layout.setHgap(5);
final JPanel panel = new JPanel(layout);
panel.setOpaque(true);
final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
panel.setBackground(bg);
panel.setForeground(fg);
if (value instanceof InspectionToolWrapper) {
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper) value;
final String inspectionName = " " + toolWrapper.getDisplayName();
final String groupName = StringUtil.join(toolWrapper.getGroupPath(), " | ");
final String matchingText = inspectionName + "|" + groupName;
Matcher matcher = MatcherHolder.getAssociatedMatcher(list);
List<TextRange> fragments = matcher == null ? null : ((MinusculeMatcher) matcher).matchingFragments(matchingText);
List<TextRange> adjustedFragments = new ArrayList<>();
if (fragments != null) {
adjustedFragments.addAll(fragments);
}
final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1);
final SimpleColoredComponent c = new SimpleColoredComponent();
final boolean matchHighlighting = Registry.is("ide.highlight.match.in.selected.only") && !sel;
if (matchHighlighting) {
c.append(inspectionName, myPlain);
} else {
final List<TextRange> ranges = adjustedFragments.subList(0, splitPoint);
SpeedSearchUtil.appendColoredFragments(c, inspectionName, ranges, sel ? mySelected : myPlain, myHighlighted);
}
panel.add(c, BorderLayout.WEST);
final SimpleColoredComponent group = new SimpleColoredComponent();
if (matchHighlighting) {
group.append(groupName, SimpleTextAttributes.GRAYED_ATTRIBUTES);
} else {
final SimpleTextAttributes attributes = sel ? mySelected : SimpleTextAttributes.GRAYED_ATTRIBUTES;
final List<TextRange> ranges = adjustedFragments.subList(splitPoint, adjustedFragments.size());
SpeedSearchUtil.appendColoredFragments(group, groupName, ranges, attributes, myHighlighted);
}
final JPanel right = new JPanel(new BorderLayout());
right.setBackground(bg);
right.setForeground(fg);
right.add(group, BorderLayout.CENTER);
final JLabel icon = new JLabel(getIcon(toolWrapper));
icon.setBackground(bg);
icon.setForeground(fg);
right.add(icon, BorderLayout.EAST);
panel.add(right, BorderLayout.EAST);
} else {
// E.g. "..." item
return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground()) : super.getListCellRendererComponent(list, value, index, sel, focus);
}
return panel;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class PackagingElementNode method addErrorHighlighting.
private static SimpleTextAttributes addErrorHighlighting(boolean error, SimpleTextAttributes attributes) {
final TextAttributes textAttributes = attributes.toTextAttributes();
textAttributes.setEffectType(EffectType.WAVE_UNDERSCORE);
textAttributes.setEffectColor(error ? JBColor.RED : JBColor.GRAY);
return SimpleTextAttributes.fromTextAttributes(textAttributes);
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class LibraryTreeRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
final NodeDescriptor descriptor = (NodeDescriptor) userObject;
setIcon(descriptor.getIcon());
append(descriptor.toString(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, descriptor.getColor()));
}
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class NavBarPresentation method getTextAttributes.
protected SimpleTextAttributes getTextAttributes(final Object object, final boolean selected) {
if (!NavBarModel.isValid(object))
return SimpleTextAttributes.REGULAR_ATTRIBUTES;
if (object instanceof PsiElement) {
if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return ((PsiElement) object).isValid();
}
}).booleanValue())
return SimpleTextAttributes.GRAYED_ATTRIBUTES;
PsiFile psiFile = ((PsiElement) object).getContainingFile();
if (psiFile != null) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
return new SimpleTextAttributes(null, selected ? null : FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor(), JBColor.red, WolfTheProblemSolver.getInstance(myProject).isProblemFile(virtualFile) ? SimpleTextAttributes.STYLE_WAVED : SimpleTextAttributes.STYLE_PLAIN);
} else {
if (object instanceof PsiDirectory) {
VirtualFile vDir = ((PsiDirectory) object).getVirtualFile();
if (vDir.getParent() == null || ProjectRootsUtil.isModuleContentRoot(vDir, myProject)) {
return SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
}
}
if (wolfHasProblemFilesBeneath((PsiElement) object)) {
return WOLFED;
}
}
} else if (object instanceof Module) {
if (WolfTheProblemSolver.getInstance(myProject).hasProblemFilesBeneath((Module) object)) {
return WOLFED;
}
} else if (object instanceof Project) {
final Project project = (Project) object;
final Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
@Override
public Module[] compute() {
return ModuleManager.getInstance(project).getModules();
}
});
for (Module module : modules) {
if (WolfTheProblemSolver.getInstance(project).hasProblemFilesBeneath(module)) {
return WOLFED;
}
}
}
return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class BlockTreeNode method update.
@Override
protected void update(PresentationData presentation) {
String name = myBlock.getClass().getSimpleName();
if (myBlock instanceof DataLanguageBlockWrapper) {
name += " (" + ((DataLanguageBlockWrapper) myBlock).getOriginal().getClass().getSimpleName() + ")";
}
presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES);
if (myBlock.getIndent() != null) {
presentation.addText(" " + String.valueOf(myBlock.getIndent()).replaceAll("[<>]", " "), SimpleTextAttributes.GRAY_ATTRIBUTES);
} else {
presentation.addText(" Indent: null", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
if (myBlock.getAlignment() != null) {
float d = 1.f * System.identityHashCode(myBlock.getAlignment()) / Integer.MAX_VALUE;
Color color = new JBColor(Color.HSBtoRGB(1.0f * d, .3f, .7f), Color.HSBtoRGB(1.0f * d, .3f, .8f));
presentation.addText(" " + String.valueOf(myBlock.getAlignment()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, color));
}
if (myBlock.getWrap() != null) {
presentation.addText(" " + String.valueOf(myBlock.getWrap()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, PlatformColors.BLUE));
}
}
Aggregations