protected final ColoredString getColoredLabelWithCounts(Object element, ColoredString coloredName) { String name= coloredName.getString(); String decorated= getLabelWithCounts(element, name); if (decorated.length() > name.length()) { ColoredJavaElementLabels.decorateColoredString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE); } return coloredName; }
public ColoredString append(ColoredString string) { int offset= fBuffer.length(); fBuffer.append(string.getString()); for (Iterator iterator= string.getRanges(); iterator.hasNext();) { StyleRange curr= (StyleRange) iterator.next(); addRange(new StyleRange(offset + curr.offset, curr.length, curr.style)); } return this; }
public static ColoredString decorateColoredString(ColoredString string, String decorated, Style color) { String label= string.getString(); int originalStart= decorated.indexOf(label); if (originalStart == -1) { return new ColoredString(decorated); // the decorator did something wild } if (originalStart > 0) { ColoredString newString= new ColoredString(decorated.substring(0, originalStart), color); newString.append(string); string= newString; } if (decorated.length() > originalStart + label.length()) { // decorator appended something return string.append(decorated.substring(originalStart + label.length()), color); } return string; // no change }
private ColoredString getColoredLabelForView(Item item) { ColoredString oldLabel= (ColoredString) item.getData(COLORED_LABEL_KEY); String itemText= item.getText(); if (oldLabel != null && oldLabel.getString().equals(itemText)) { // avoid accesses to the label provider if possible return oldLabel; } ColoredString newLabel= null; IBaseLabelProvider labelProvider= fViewer.getLabelProvider(); if (labelProvider instanceof IRichLabelProvider) { newLabel= ((IRichLabelProvider) labelProvider).getRichTextLabel(item.getData()); } if (newLabel == null) { newLabel= new ColoredString(itemText); // fallback. Should never happen. } else if (!newLabel.getString().equals(itemText)) { // the decorator manager has already queued an new update newLabel= ColoredJavaElementLabels.decorateColoredString(newLabel, itemText, ColoredJavaElementLabels.DECORATIONS_STYLE); } item.setData(COLORED_LABEL_KEY, newLabel); // cache the result return newLabel; }
public ColoredString getRichTextLabel(Object element) { ILabelProvider labelProvider= getLabelProvider(); if (labelProvider instanceof IRichLabelProvider) { // get a rich label from the label decorator IRichLabelProvider richLabelProvider= (IRichLabelProvider) labelProvider; ColoredString richLabel= richLabelProvider.getRichTextLabel(element); if (richLabel != null) { String decorated= null; ILabelDecorator labelDecorator= getLabelDecorator(); if (labelDecorator != null) { if (labelDecorator instanceof LabelDecorator) { decorated= ((LabelDecorator) labelDecorator).decorateText(richLabel.getString(), element, getDecorationContext()); } else { decorated= labelDecorator.decorateText(richLabel.getString(), element); } } if (decorated != null) { return ColoredJavaElementLabels.decorateColoredString(richLabel, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); } return richLabel; } } return null; }
private void processColoredLabel(ColoredString richLabel, GC gc, Rectangle textBounds, boolean isSelected, Font font) { String text= richLabel.getString(); fTextLayout.setText(text); fTextLayout.setFont(font); if (!isSelected) { // apply the styled ranges only when element is not selected Display display= (Display) gc.getDevice(); Iterator ranges= richLabel.getRanges(); while (ranges.hasNext()) { ColoredString.StyleRange curr= (ColoredString.StyleRange) ranges.next(); ColoredString.Style style= curr.style; if (style != null) { Color foreground= getColor(style.getForegroundColorName(), display); TextStyle textStyle= new TextStyle(null, foreground, null); fTextLayout.setStyle(textStyle, curr.offset, curr.offset + curr.length - 1); } } } Rectangle bounds= fTextLayout.getBounds(); int x= textBounds.x; int y = textBounds.y + Math.max(0, (textBounds.height - bounds.height) / 2); fTextLayout.draw(gc, x, y); fTextLayout.setText(""); // clear all ranges //$NON-NLS-1$ }
public ColoredString getRichTextLabel(Object element) { ColoredString string= ColoredJavaElementLabels.getTextLabel(element, evaluateTextFlags(element) | ColoredJavaElementLabels.COLORIZE); if (string.length() == 0 && (element instanceof IStorage)) { string= new ColoredString(fStorageLabelProvider.getText(element)); } String decorated= decorateText(string.getString(), element); if (decorated != null) { return ColoredJavaElementLabels.decorateColoredString(string, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); } return string; }
public ColoredString getRichTextLabel(Object element) { if (element instanceof IImportDeclaration) element= ((IImportDeclaration)element).getParent().getParent(); ColoredString text= super.getRichTextLabel(element); if (text.length() > 0) { ColoredString countLabel= getColoredLabelWithCounts(element, text); if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) { countLabel.append(getPostQualification(element, text.getString()), ColoredJavaElementLabels.QUALIFIER_STYLE); } return countLabel; } return new ColoredString(getParticipantText(element)); }