use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class ShowUsagesTableCellRenderer method textComponentSpanningWholeRow.
@NotNull
private static Component textComponentSpanningWholeRow(@NotNull SimpleColoredComponent chunks, Color panelBackground, Color panelForeground, final int column, @NotNull final JTable table) {
final SimpleColoredComponent component = new SimpleColoredComponent() {
@Override
protected void doPaint(Graphics2D g) {
int offset = 0;
int i = 0;
final TableColumnModel columnModel = table.getColumnModel();
while (i < column) {
offset += columnModel.getColumn(i).getWidth();
i++;
}
g.translate(-offset, 0);
//if (column == columnModel.getColumnCount()-1) {
//}
// should increase the column width so that selection background will be visible even after offset translation
setSize(getWidth() + offset, getHeight());
super.doPaint(g);
g.translate(+offset, 0);
}
@NotNull
@Override
public Dimension getPreferredSize() {
//return super.getPreferredSize();
return column == table.getColumnModel().getColumnCount() - 1 ? super.getPreferredSize() : new Dimension(0, 0);
// it should span the whole row, so we can't return any specific value here,
// because otherwise it would be used in the "max width" calculation in com.intellij.find.actions.ShowUsagesAction.calcMaxWidth
}
};
component.setBackground(panelBackground);
component.setForeground(panelForeground);
for (SimpleColoredComponent.ColoredIterator iterator = chunks.iterator(); iterator.hasNext(); ) {
iterator.next();
String fragment = iterator.getFragment();
SimpleTextAttributes attributes = iterator.getTextAttributes();
attributes = attributes.derive(attributes.getStyle(), panelForeground, panelBackground, attributes.getWaveColor());
component.append(fragment, attributes);
}
return component;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class UsageListCellRenderer method customizeCellRenderer.
@Override
protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
Usage usage = (Usage) value;
UsagePresentation presentation = usage.getPresentation();
setIcon(presentation.getIcon());
VirtualFile virtualFile = getVirtualFile(usage);
if (virtualFile != null) {
append(virtualFile.getName() + ": ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
setIcon(virtualFile.getFileType().getIcon());
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile != null) {
setIcon(psiFile.getIcon(0));
}
}
TextChunk[] text = presentation.getText();
for (TextChunk textChunk : text) {
SimpleTextAttributes simples = textChunk.getSimpleAttributesIgnoreBackground();
append(textChunk.getText(), simples);
}
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (!(value instanceof NavigationItem))
return false;
NavigationItem item = (NavigationItem) value;
TextAttributes attributes = getNavigationItemAttributes(item);
SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
Color color = list.getForeground();
if (nameAttributes == null)
nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
renderer.append(item + " ", nameAttributes);
ItemPresentation itemPresentation = item.getPresentation();
assert itemPresentation != null;
renderer.setIcon(itemPresentation.getIcon(true));
String locationString = itemPresentation.getLocationString();
if (!StringUtil.isEmpty(locationString)) {
renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
}
return true;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class NodeRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Color color = null;
NodeDescriptor descriptor = null;
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
descriptor = (NodeDescriptor) userObject;
color = descriptor.getColor();
setIcon(descriptor.getIcon());
}
}
if (descriptor instanceof PresentableNodeDescriptor) {
final PresentableNodeDescriptor node = (PresentableNodeDescriptor) descriptor;
final PresentationData presentation = node.getPresentation();
final List<PresentableNodeDescriptor.ColoredFragment> coloredText = presentation.getColoredText();
if (coloredText.isEmpty()) {
String text = tree.convertValueToText(value.toString(), selected, expanded, leaf, row, hasFocus);
SimpleTextAttributes simpleTextAttributes = getSimpleTextAttributes(node, presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
append(text, simpleTextAttributes);
String location = presentation.getLocationString();
if (!StringUtil.isEmpty(location)) {
SimpleTextAttributes attributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.GRAYED_ATTRIBUTES);
append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), attributes, false);
}
} else {
boolean first = true;
for (PresentableNodeDescriptor.ColoredFragment each : coloredText) {
SimpleTextAttributes simpleTextAttributes = each.getAttributes();
if (each.getAttributes().getFgColor() == null && presentation.getForcedTextForeground() != null) {
simpleTextAttributes = addColorToSimpleTextAttributes(each.getAttributes(), presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
}
if (first) {
final TextAttributesKey textAttributesKey = presentation.getTextAttributesKey();
if (textAttributesKey != null) {
final TextAttributes forcedAttributes = getColorsScheme().getAttributes(textAttributesKey);
if (forcedAttributes != null) {
simpleTextAttributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.fromTextAttributes(forcedAttributes));
}
}
first = false;
}
// treat grayed text as non-main
boolean isMain = simpleTextAttributes != SimpleTextAttributes.GRAYED_ATTRIBUTES;
append(each.getText(), simpleTextAttributes, isMain);
}
String location = presentation.getLocationString();
if (!StringUtil.isEmpty(location)) {
append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), SimpleTextAttributes.GRAY_ATTRIBUTES, false);
}
}
setToolTipText(presentation.getTooltip());
} else if (value != null) {
String text = value.toString();
if (descriptor != null) {
text = descriptor.myName;
}
text = tree.convertValueToText(text, selected, expanded, leaf, row, hasFocus);
if (text == null) {
text = "";
}
append(text);
setToolTipText(null);
}
if (!AbstractTreeUi.isLoadingNode(value)) {
SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
}
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class NodeRenderer method addColorToSimpleTextAttributes.
private static SimpleTextAttributes addColorToSimpleTextAttributes(SimpleTextAttributes simpleTextAttributes, Color color) {
if (color != null) {
final TextAttributes textAttributes = simpleTextAttributes.toTextAttributes();
textAttributes.setForegroundColor(color);
simpleTextAttributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
}
return simpleTextAttributes;
}
Aggregations