Java Code Examples for org.eclipse.jface.text.TextPresentation#addStyleRange()
The following examples show how to use
org.eclipse.jface.text.TextPresentation#addStyleRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DamageRepairer.java From LogViewer with Eclipse Public License 2.0 | 6 votes |
/** * Adds style information to the given text presentation. * * @param presentation the text presentation to be extended * @param offset the offset of the range to be styled * @param length the length of the range to be styled * @param attr the attribute describing the style of the range to be styled * @param wholeLine the boolean switch to declare that the whole line should be colored */ private void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr, boolean wholeLine) { if (attr != null) { int style= attr.getStyle(); int fontStyle= style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); if(wholeLine) { try { int line = document.getLineOfOffset(offset); int start = document.getLineOffset(line); length = document.getLineLength(line); offset = start; } catch (BadLocationException e) { } } StyleRange styleRange = new StyleRange(offset,length,attr.getForeground(),attr.getBackground(),fontStyle); styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; presentation.addStyleRange(styleRange); } }
Example 2
Source File: StyledTextForShowingCodeFactory.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Creates the ranges from parsing the code with the PyCodeScanner. * * @param textPresentation this is the container of the style ranges. * @param scanner the scanner used to parse the document. * @param doc document to parse. * @param partitionOffset the offset of the document we should parse. * @param partitionLen the length to be parsed. */ private void createDefaultRanges(TextPresentation textPresentation, PyCodeScanner scanner, Document doc, int partitionOffset, int partitionLen) { scanner.setRange(doc, partitionOffset, partitionLen); IToken nextToken = scanner.nextToken(); while (!nextToken.isEOF()) { Object data = nextToken.getData(); if (data instanceof TextAttribute) { TextAttribute textAttribute = (TextAttribute) data; int offset = scanner.getTokenOffset(); int len = scanner.getTokenLength(); Color foreground = textAttribute.getForeground(); Color background = textAttribute.getBackground(); int style = textAttribute.getStyle(); textPresentation.addStyleRange(new StyleRange(offset, len, foreground, background, style)); } nextToken = scanner.nextToken(); } }
Example 3
Source File: PyInformationPresenter.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Creates the reader and properly puts the presentation into place. */ public Reader createReader(String hoverInfo, TextPresentation presentation) { String str = PyStringUtils.removeWhitespaceColumnsToLeft(hoverInfo); str = correctLineDelimiters(str); List<PyStyleRange> lst = new ArrayList<>(); str = handlePydevTags(lst, str); Collections.sort(lst, new Comparator<PyStyleRange>() { @Override public int compare(PyStyleRange o1, PyStyleRange o2) { return Integer.compare(o1.start, o2.start); } }); for (PyStyleRange pyStyleRange : lst) { presentation.addStyleRange(pyStyleRange); } return new StringReader(str); }
Example 4
Source File: NonRuleBasedDamagerRepairer.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled */ protected void addRange( TextPresentation presentation, int offset, int length, TextAttribute attr ) { if ( attr != null ) { int style= attr.getStyle(); int fontStyle= style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); StyleRange range = new StyleRange( offset, length, attr.getForeground( ), attr.getBackground( ), fontStyle ); range.strikeout = ( attr.getStyle( ) & TextAttribute.STRIKETHROUGH ) != 0; range.underline = ( attr.getStyle( ) & TextAttribute.UNDERLINE ) != 0; range.font= attr.getFont(); presentation.addStyleRange( range ); } }
Example 5
Source File: NonRuleBasedDamagerRepairer.java From http4e with Apache License 2.0 | 5 votes |
/** * Adds style information to the given text presentation. * * @param presentation the text presentation to be extended * @param offset the offset of the range to be styled * @param length the length of the range to be styled * @param attr the attribute describing the style of the range to be styled */ protected void addRange( TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) presentation.addStyleRange( new StyleRange( offset, length, attr.getForeground(), attr.getBackground(), attr.getStyle())); }
Example 6
Source File: TexSourceViewerConfiguration.java From texlipse with Eclipse Public License 1.0 | 5 votes |
private void boldRange(int start, int length, TextPresentation presentation, boolean doItalic) { // We have found a tag and create a new style range int fontStyle = doItalic ? (SWT.BOLD | SWT.ITALIC) : SWT.BOLD; StyleRange range = new StyleRange(start, length, null, null, fontStyle); // Add this style range to the presentation presentation.addStyleRange(range); }
Example 7
Source File: JavaParameterListValidator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @see IContextInformationPresenter#updatePresentation(int, TextPresentation) */ public boolean updatePresentation(int position, TextPresentation presentation) { int currentParameter= -1; try { currentParameter= getCharCount(fViewer.getDocument(), fPosition, position, ",", "", true); //$NON-NLS-1$//$NON-NLS-2$ } catch (BadLocationException x) { return false; } if (fCurrentParameter != -1) { if (currentParameter == fCurrentParameter) return false; } presentation.clear(); fCurrentParameter= currentParameter; String s= fInformation.getInformationDisplayString(); int[] commas= computeCommaPositions(s); if (commas.length - 2 < fCurrentParameter) { presentation.addStyleRange(new StyleRange(0, s.length(), null, null, SWT.NORMAL)); return true; } int start= commas[fCurrentParameter] + 1; int end= commas[fCurrentParameter + 1]; if (start > 0) presentation.addStyleRange(new StyleRange(0, start, null, null, SWT.NORMAL)); if (end > start) presentation.addStyleRange(new StyleRange(start, end - start, null, null, SWT.BOLD)); if (end < s.length()) presentation.addStyleRange(new StyleRange(end, s.length() - end, null, null, SWT.NORMAL)); return true; }
Example 8
Source File: PresentationRepairer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Adds style information to the given text presentation. * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param textStyle * the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) { if (textStyle != null) { if (textStyle.metrics != null && length >= 1) { for (int i = offset; i < offset + length; i++) { try { StyleRange styleRange = new StyleRange(textStyle); String placeHolder = fDocument.get(i, 1); InnerTag innerTag = InnerTagUtil.getInnerTag(fViewer.getInnerTagCacheList(), placeHolder); if (innerTag != null) { Point rect = innerTag.computeSize(SWT.DEFAULT, SWT.DEFAULT); // int ascent = 4 * rect.height / 5 + SEGMENT_LINE_SPACING / 2; // int descent = rect.height - ascent + SEGMENT_LINE_SPACING; styleRange.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2); } styleRange.start = i; styleRange.length = 1; presentation.addStyleRange(styleRange); } catch (BadLocationException e) { e.printStackTrace(); } } } /* * else { StyleRange styleRange = new StyleRange(textStyle); styleRange.start = offset; styleRange.length = * length; presentation.addStyleRange(styleRange); } */ } }
Example 9
Source File: NonRuleBasedDamagerRepairer.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
/** * Adds style information to the given text presentation. * * @param presentation the text presentation to be extended * @param offset the offset of the range to be styled * @param length the length of the range to be styled * @param attr the attribute describing the style of the range to be styled */ protected void addRange( TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) presentation.addStyleRange( new StyleRange( offset, length, attr.getForeground(), attr.getBackground(), attr.getStyle())); }
Example 10
Source File: PyDefaultDamagerRepairer.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Adds style information to the given text presentation. * * @param presentation the text presentation to be extended * @param offset the offset of the range to be styled * @param length the length of the range to be styled * @param attr the attribute describing the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) { int style = attr.getStyle(); int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), fontStyle); styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; styleRange.font = attr.getFont(); presentation.addStyleRange(styleRange); } }
Example 11
Source File: NonRuleBasedDamagerRepairer.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled */ protected void addRange( TextPresentation presentation, int offset, int length, TextAttribute attr ) { if ( attr != null ) { presentation.addStyleRange( new StyleRange( offset, length, attr.getForeground( ), attr.getBackground( ), attr.getStyle( ) ) ); } }
Example 12
Source File: ParameterContextInformation.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public boolean updatePresentation(ITextViewer viewer, int position, TextPresentation presentation) { int currentParameter= -1; try { currentParameter= getCharCount(viewer.getDocument(), this.parameterListOffset, position, ",", "", true); //$NON-NLS-1$//$NON-NLS-2$ } catch (BadLocationException x) { return false; } if (currentParameter != -1) { if (currentParameter == this.currentParameter) return false; } presentation.clear(); this.currentParameter= currentParameter; List<String> rawStrings = internalGetInformationDisplayString(); List<int[]> commaArrays = Lists.newArrayList(); for(String s: rawStrings) { commaArrays.add(computeCommaPositions(s)); } int offset = 0; for(int i = 0; i < rawStrings.size(); i++) { String raw = rawStrings.get(i); int[] commas = commaArrays.get(i); if (commas.length - 2 < this.currentParameter && !data.isVarArgs(i)) { presentation.addStyleRange(new StyleRange(offset, raw.length(), JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR), null, SWT.NORMAL)); } else { int actualParameter = this.currentParameter; if (actualParameter + 1 >= commas.length) actualParameter = commas.length - 2; int start= commas[actualParameter] + 1; int end= commas[actualParameter + 1]; if (start > 0) presentation.addStyleRange(new StyleRange(offset, start, null, null, SWT.NORMAL)); if (end > start) presentation.addStyleRange(new StyleRange(offset + start, end - start, null, null, SWT.BOLD)); if (end < raw.length()) presentation.addStyleRange(new StyleRange(offset + end, raw.length() - end, null, null, SWT.NORMAL)); } offset += raw.length() + 1; } return true; }
Example 13
Source File: TexSourceViewerConfiguration.java From texlipse with Eclipse Public License 1.0 | 4 votes |
private void italicizeRange(int start, int length, TextPresentation presentation) { StyleRange range = new StyleRange(start, length, null, null, SWT.ITALIC); presentation.addStyleRange(range); }
Example 14
Source File: PresentationRepairer.java From translationstudio8 with GNU General Public License v2.0 | 3 votes |
/** * Adds style information to the given text presentation. * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param textStyle * the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) { if (textStyle != null) { StyleRange styleRange = new StyleRange(textStyle); styleRange.start = offset; styleRange.length = length; presentation.addStyleRange(styleRange); } }
Example 15
Source File: NonRuleBasedDamagerRepairer.java From birt with Eclipse Public License 1.0 | 3 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled */ protected void addRange( TextPresentation presentation, int offset, int length, TextAttribute attr ) { if ( attr != null ) presentation.addStyleRange( new StyleRange( offset, length, attr.getForeground( ), attr.getBackground( ), attr.getStyle( ) ) ); }
Example 16
Source File: PresentationRepairer.java From tmxeditor8 with GNU General Public License v2.0 | 3 votes |
/** * Adds style information to the given text presentation. * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param textStyle * the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) { if (textStyle != null) { StyleRange styleRange = new StyleRange(textStyle); styleRange.start = offset; styleRange.length = length; presentation.addStyleRange(styleRange); } }
Example 17
Source File: TMPresentationReconciler.java From tm4e with Eclipse Public License 1.0 | 3 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled * @param lastLineStyleRanges */ protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) { int style = attr.getStyle(); int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL); StyleRange styleRange = new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), fontStyle); styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0; styleRange.underline = (style & TextAttribute.UNDERLINE) != 0; styleRange.font = attr.getFont(); presentation.addStyleRange(styleRange); } }
Example 18
Source File: NonRuleBasedDamagerRepairer.java From APICloud-Studio with GNU General Public License v3.0 | 3 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) { presentation.addStyleRange(new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), attr .getStyle())); } }
Example 19
Source File: NonRuleBasedDamagerRepairer.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** * Adds style information to the given text presentation. * * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param attr * the attribute describing the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) { if (attr != null) presentation.addStyleRange(new StyleRange(offset, length, attr.getForeground(), attr .getBackground(), attr.getStyle())); }