List of usage examples for org.eclipse.jface.viewers StyledString length
@Override public int length()
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java
License:Open Source License
/** * Truncates the given text such that it will fit into the given {@link StyledString} * up to a maximum length of {@link #LABEL_MAX_WIDTH}. * * @param text the text to truncate//from ww w . ja v a 2s. com * @param string the existing string to be appended to * @return the truncated string */ private static String truncate(String text, StyledString string) { int existingLength = string.length(); if (text.length() + existingLength > LABEL_MAX_WIDTH) { int truncatedLength = LABEL_MAX_WIDTH - existingLength - 3; if (truncatedLength > 0) { return String.format("%1$s...", text.substring(0, truncatedLength)); } else { return ""; //$NON-NLS-1$ } } return text; }
From source file:com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.java
License:Open Source License
/** * Computes a styled string describing the UI node suitable for tree views. * Similar to {@link #getShortDescription()} but styles the Strings. * * @return A styled string describing the UI node suitable for tree views. */// ww w. jav a 2 s .c om public StyledString getStyledDescription() { String uiName = mDescriptor.getUiName(); // Special case: for <view>, show the class attribute value instead. // This is done here rather than in the descriptor since this depends on // node instance data. if (SdkConstants.VIEW_TAG.equals(uiName) && mXmlNode instanceof Element) { Element element = (Element) mXmlNode; String cls = element.getAttribute(ATTR_CLASS); if (cls != null) { uiName = cls.substring(cls.lastIndexOf('.') + 1); } } StyledString styledString = new StyledString(); String attr = getDescAttribute(); if (attr != null) { // Don't append the two when it's a repeat, e.g. Button01 (Button), // only when the ui name is not part of the attribute if (attr.toLowerCase(Locale.US).indexOf(uiName.toLowerCase(Locale.US)) == -1) { styledString.append(attr); styledString.append(String.format(" (%1$s)", uiName), StyledString.DECORATIONS_STYLER); } else { styledString.append(attr); } } if (styledString.length() == 0) { styledString.append(uiName); } return styledString; }
From source file:com.android.ide.eclipse.auidt.internal.editors.uimodel.UiElementNode.java
License:Open Source License
/** * Computes a styled string describing the UI node suitable for tree views. * Similar to {@link #getShortDescription()} but styles the Strings. * * @return A styled string describing the UI node suitable for tree views. *///from www . j ava 2 s. c o m public StyledString getStyledDescription() { String uiName = mDescriptor.getUiName(); // Special case: for <view>, show the class attribute value instead. // This is done here rather than in the descriptor since this depends on // node instance data. if (LayoutDescriptors.VIEW_VIEWTAG.equals(uiName) && mXmlNode instanceof Element) { Element element = (Element) mXmlNode; String cls = element.getAttribute(ATTR_CLASS); if (cls != null) { uiName = cls.substring(cls.lastIndexOf('.') + 1); } } StyledString styledString = new StyledString(); String attr = getDescAttribute(); if (attr != null) { // Don't append the two when it's a repeat, e.g. Button01 (Button), // only when the ui name is not part of the attribute if (attr.toLowerCase(Locale.US).indexOf(uiName.toLowerCase(Locale.US)) == -1) { styledString.append(attr); styledString.append(String.format(" (%1$s)", uiName), StyledString.DECORATIONS_STYLER); } else { styledString.append(attr); } } if (styledString.length() == 0) { styledString.append(uiName); } return styledString; }
From source file:com.google.dart.tools.ui.internal.search.SearchLabelProvider.java
License:Open Source License
@Override public StyledString getStyledText(Object element) { StyledString string = DartElementLabels.getStyledTextLabel(element, (evaluateTextFlags(element) | DartElementLabels.COLORIZE)); if (string.length() == 0 && (element instanceof IStorage)) { string = new StyledString(fStorageLabelProvider.getText(element)); }/*from w ww . j a va2 s . c o m*/ String decorated = decorateText(string.getString(), element); if (decorated != null) { return StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.DECORATIONS_STYLER, string); } return string; }
From source file:com.google.dart.tools.ui.internal.search.SortingLabelProvider.java
License:Open Source License
@Override public StyledString getStyledText(Object element) { StyledString text = super.getStyledText(element); if (text.length() > 0) { StyledString countLabel = getColoredLabelWithCounts(element, text); if (currentOrder == SHOW_ELEMENT_CONTAINER) { countLabel.append(getPostQualification(element), StyledString.QUALIFIER_STYLER); }//from www . j av a 2s. c o m return countLabel; } return getStyledParticipantText(element); }
From source file:com.palantir.typescript.search.SearchResultLabelProvider.java
License:Apache License
private StyledString getLineStyledText(LineResult lineResult) { StyledString string = new StyledString(); ReferenceEntryEx firstReference = lineResult.getMatches().get(0).getReference(); // line number int lineNumber = firstReference.getLineNumber(); String lineNumberString = MessageFormat.format("{0,number,integer}: ", lineNumber + 1); string.append(lineNumberString, StyledString.QUALIFIER_STYLER); // line (highlight the matches) int lineStart = firstReference.getLineStart(); String line = firstReference.getLine(); int trimStart = NON_WHITESPACE_MATCHER.indexIn(line); int trimEnd = NON_WHITESPACE_MATCHER.lastIndexIn(line); string.append(line.substring(trimStart, trimEnd + 1)); for (FindReferenceMatch match : lineResult.getMatches()) { ReferenceEntryEx reference = match.getReference(); TextSpan textSpan = reference.getTextSpan(); int offset = textSpan.getStart() + lineNumberString.length() - trimStart - lineStart; int length = textSpan.getLength(); // highlight the match if its present in the line (note: the line may have been truncated earlier) if (offset + length <= string.length()) { string.setStyle(offset, length, HIGHLIGHT_STYLE); }//from w ww. j a v a 2 s . c o m } return string; }
From source file:com.puppetlabs.geppetto.pp.dsl.ui.labeling.PPLabelProvider.java
License:Open Source License
private StyledString literalNames(List<? extends EObject> exprs) { StyledString result = new StyledString(); boolean first = true; for (EObject expr : exprs) { Object label = doGetText(expr); if (first) first = false;/* w w w . j a va 2s . co m*/ else result.append(", "); if (label instanceof String) result.append((String) label); else if (label instanceof StyledString) result.append((StyledString) label); else result.append("?"); } // truncate long list (bad way, destroys individual styles) if (result.length() > LABEL_LIMIT) return new StyledString(result.getString().substring(0, LABEL_LIMIT) + "..."); return result; }
From source file:com.redhat.ceylon.eclipse.code.explorer.JavaUILabelProvider.java
License:Open Source License
public StyledString getStyledText(Object element) { StyledString string = JavaElementLabels.getStyledTextLabel(element, (evaluateTextFlags(element) | JavaElementLabels.COLORIZE)); if (string.length() == 0 && (element instanceof IStorage)) { string = new StyledString(fStorageLabelProvider.getText(element)); }/* ww w.j a v a 2 s.co m*/ String decorated = decorateText(string.getString(), element); if (decorated != null) { return StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.DECORATIONS_STYLER, string); } return string; }
From source file:de.walware.ecommons.workbench.search.ui.TextSearchLabelUtil.java
License:Open Source License
public StyledString getStyledText(final LineElement<?> lineElement, final List<? extends Match> matches) { final int lineNumber = lineElement.getLine(); final StyledString text = new StyledString(lineNumber + ": ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ final String lineText = lineElement.getText(); int idx = findStart(lineText, 0, lineText.length()); // index in lineText for (int i = 0; i < matches.size() && text.length() < MAX_SHOWN_LINE; i++) { final Match match = matches.get(i); final int matchStart = Math.max(match.getOffset() - lineElement.getOffset(), 0); final int matchEnd = Math.min(match.getOffset() + match.getLength() - lineElement.getOffset(), lineElement.getLength()); if (matchStart - idx < MIN_SHOWN_CONTEXT * 2 + 10) { text.append(lineText.substring(idx, matchStart)); } else {//from www .j a va 2 s . com text.append(lineText.substring(idx, findEnd(lineText, idx + MIN_SHOWN_CONTEXT, MIN_SHOWN_CONTEXT))); text.append(ELLIPSIS, StyledString.QUALIFIER_STYLER); text.append(lineText.substring( findStart(lineText, matchStart - MIN_SHOWN_CONTEXT, MIN_SHOWN_CONTEXT), matchStart)); } text.append(lineText.substring(matchStart, matchEnd), TextSearchLabelUtil.HIGHLIGHT_STYLE); idx = matchEnd; } if (idx < lineText.length()) { if (lineText.length() - idx < MIN_SHOWN_CONTEXT + 10) { text.append(lineText.substring(idx, lineText.length())); } else { text.append(lineText.substring(idx, findEnd(lineText, idx + MIN_SHOWN_CONTEXT, MIN_SHOWN_CONTEXT))); text.append(ELLIPSIS, StyledString.QUALIFIER_STYLER); } } return text; }
From source file:descent.ui.text.java.CompletionProposalLabelProvider.java
License:Open Source License
/** * Creates and returns a parameter list of the given method proposal * suitable for display. The list does not include parentheses. The lower * bound of parameter types is returned. * <p>//from w w w. j a v a2 s. c o m * Examples: * <pre> * "void method(int i, Strings)" -> "int i, String s" * "? extends Number method(java.lang.String s, ? super Number n)" -> "String s, Number n" * </pre> * </p> * * @param methodProposal the method proposal to create the parameter list * for. Must be of kind {@link CompletionProposal#METHOD_REF}. * @return the list of comma-separated parameters suitable for display */ public String createParameterList(CompletionProposal methodProposal, boolean expandFunctionTemplateArguments) { Assert.isTrue(methodProposal.getKind() == CompletionProposal.METHOD_REF || methodProposal.getKind() == CompletionProposal.EXTENSION_METHOD || methodProposal.getKind() == CompletionProposal.OP_CALL || methodProposal.getKind() == CompletionProposal.FUNCTION_CALL || methodProposal.getKind() == CompletionProposal.TEMPLATE_REF || methodProposal.getKind() == CompletionProposal.TEMPLATED_AGGREGATE_REF || methodProposal.getKind() == CompletionProposal.TEMPLATED_FUNCTION_REF); StyledString sb1 = new StyledString(); if (expandFunctionTemplateArguments) { if (methodProposal.getKind() != CompletionProposal.OP_CALL && methodProposal.getKind() != CompletionProposal.EXTENSION_METHOD) { appendTemplateParameterList(sb1, methodProposal); } } StyledString sb2 = new StyledString(); if (methodProposal.getKind() == CompletionProposal.METHOD_REF || methodProposal.getKind() == CompletionProposal.EXTENSION_METHOD || methodProposal.getKind() == CompletionProposal.OP_CALL || methodProposal.getKind() == CompletionProposal.FUNCTION_CALL || methodProposal.getKind() == CompletionProposal.TEMPLATED_FUNCTION_REF) { appendUnboundedParameterList(sb2, methodProposal); appendVarargs(sb2, methodProposal); } if (sb1.length() > 0 && sb2.length() > 0) { sb1.append(','); sb1.append(' '); } sb1.append(sb2); return sb1.toString(); }