private static void getCategoryLabel(IMember member, ColoredString result) throws JavaModelException { String[] categories= member.getCategories(); if (categories.length > 0) { ColoredString categoriesBuf= new ColoredString(); for (int i= 0; i < categories.length; i++) { if (i > 0) categoriesBuf.append(JavaUIMessages.JavaElementLabels_category_separator_string); categoriesBuf.append(categories[i]); } result.append(JavaElementLabels.CONCAT_STRING); result.append(Messages.format(JavaUIMessages.JavaElementLabels_category , categoriesBuf.toString())); } }
public void colorize(int offset, int length, Style style) { if (offset < 0 || offset + length > fBuffer.length()) { throw new IllegalArgumentException("Invalid offset (" + offset + ") or length (" + length + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ } int insertPos= 0; int nRanges= getNumberOfRanges(); for (int i= 0; i < nRanges; i++) { StyleRange curr= getRange(i); if (curr.offset + curr.length <= offset) { insertPos= i + 1; } } if (insertPos < nRanges) { StyleRange curr= getRange(insertPos); if (curr.offset > offset + length) { throw new IllegalArgumentException("Overlapping ranges"); //$NON-NLS-1$ } } addRange(insertPos, new StyleRange(offset, length, style)); }
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 Iterator getRanges() { if (!hasRanges()) return Collections.EMPTY_LIST.iterator(); return getRangesList().iterator(); }
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 }
/** * Appends the label for a initializer to a {@link ColoredString}. Considers the I_* flags. * @param initializer The element to render. * @param flags The rendering flags. Flags with names starting with 'I_' are considered. * @param result The buffer to append the resulting label to. */ public static void getInitializerLabel(IInitializer initializer, long flags, ColoredString result) { // qualification if (getFlag(flags, JavaElementLabels.I_FULLY_QUALIFIED)) { getTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS), result); result.append('.'); } result.append(JavaUIMessages.JavaElementLabels_initializer); // post qualification if (getFlag(flags, JavaElementLabels.I_POST_QUALIFIED)) { int offset= result.length(); result.append(JavaElementLabels.CONCAT_STRING); getTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS), result); if (getFlag(flags, COLORIZE)) { result.colorize(offset, result.length() - offset, QUALIFIER_STYLE); } } }
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)); }
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(String text, Style style) { this(); append(text, style); }
public ColoredString getRichTextLabel(Object element) { ColoredString text= super.getRichTextLabel(element); String qualifier= getQualifier(element); if (qualifier != null) { return new ColoredString(qualifier).append(text); } return text; }
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; }
ColoredString str= new ColoredString(description); if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) { int index= description.indexOf('['); if (index != -1) { str.colorize(index, description.length() - index, DECORATIONS_STYLE); return new ColoredString(containerPath.toString());
/** * Returns the label for a Java element with the flags as defined by this class. * @param element The element to render. * @param flags The rendering flags. * @return the label of the Java element */ public static ColoredString getElementLabel(IJavaElement element, long flags) { ColoredString result= new ColoredString(); getElementLabel(element, flags, result); return result; }
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$ }
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; }
private void addRange(int index, StyleRange range) { getRangesList().add(index, range); }
private static void getExternalArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) { IPath path= root.getPath(); if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements= path.segmentCount(); if (segements > 0) { result.append(path.segment(segements - 1)); int offset= result.length(); if (segements > 1 || path.getDevice() != null) { result.append(JavaElementLabels.CONCAT_STRING); result.append(path.removeLastSegments(1).toOSString()); } if (getFlag(flags, COLORIZE)) { result.colorize(offset, result.length() - offset, QUALIFIER_STYLE); } } else { result.append(path.toOSString()); } } else { result.append(path.toOSString()); } }
public ColoredString append(String text) { return append(text, DEFAULT_STYLE); }
public ColoredString getRichTextLabel(Object element) { if (element instanceof IPackageFragment || element instanceof LogicalPackage) return new ColoredString(getText(element)); return super.getRichTextLabel(element); }
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; }