org.eclipse.jface.text.TextPresentation Java Examples

The following examples show how to use org.eclipse.jface.text.TextPresentation. 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: InformationControl.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see IInformationControl#setInformation(String)
 */
@SuppressWarnings("deprecation")
public void setInformation(String content) {
	if (fPresenter == null) {
		fText.setText(content);
	} else {
		fPresentation.clear();
		content= fPresenter.updatePresentation(fShell.getDisplay(), content, fPresentation, Math.max(fMaxWidth, 260), fMaxHeight);
		if (content != null) {
			fText.setText(content);
			TextPresentation.applyTextPresentation(fPresentation, fText);
		} else {
			fText.setText("");  //$NON-NLS-1$
		}
	}
}
 
Example #2
Source File: CoverageInformationItem.java    From tlaplus with MIT License 6 votes vote down vote up
public void style(final TextPresentation textPresentation, final Color c, final Representation rep) {
	if (!isRoot()) {
		final StyleRange rs = new StyleRange();
		rs.start = region.getOffset();
		rs.length = region.getLength();
		rs.background = c;
		if ((rep == Representation.STATES_DISTINCT || rep == Representation.STATES) && !(this instanceof ActionInformationItem)) {
			rs.background = JFaceResources.getColorRegistry().get(ModuleCoverageInformation.GRAY);
			rs.borderStyle = SWT.NONE;
			rs.borderColor = null;
		} else if (rep != Representation.COST && rep.getValue(this, Grouping.INDIVIDUAL) == 0L) {
			rs.background = null;
			rs.borderStyle = SWT.BORDER_SOLID;
			rs.borderColor = JFaceResources.getColorRegistry().get(ModuleCoverageInformation.RED);
		}
		active = false;
		textPresentation.replaceStyleRange(addStlye(rs));
	}
	for (CoverageInformationItem child : childs) {
		child.style(textPresentation, c, rep);
	}
}
 
Example #3
Source File: DamageRepairer.java    From LogViewer with Eclipse Public License 2.0 6 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
    int start= region.getOffset();
    int length= 0;
    boolean firstToken= true;
    TextAttribute attribute = getTokenTextAttribute(Token.UNDEFINED);

    scanner.setRange(document,start,region.getLength());

    while (true) {
        IToken resultToken = scanner.nextToken();
        if (resultToken.isEOF()) {
            break;
        }
        if(resultToken.equals(Token.UNDEFINED)) {
        	continue;
        }
        if (!firstToken) {
        	addRange(presentation,start,length,attribute,true);
        }
        firstToken = false;
        attribute = getTokenTextAttribute(resultToken);
        start = scanner.getTokenOffset();
        length = scanner.getTokenLength();
    }
    addRange(presentation,start,length,attribute,true);
}
 
Example #4
Source File: HighlightingReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Update the presentation.
 * 
 * @param textPresentation
 *            the text presentation
 * @param addedPositions
 *            the added positions
 * @param removedPositions
 *            the removed positions
 * @param resource
 *            the resource for which the positions have been computed 
 */
private void updatePresentation(TextPresentation textPresentation, List<AttributedPosition> addedPositions,
		List<AttributedPosition> removedPositions, XtextResource resource) {
	final Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
	if (runnable == null)
		return;
	final XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet();
	final int modificationStamp = resourceSet.getModificationStamp();
	Display display = getDisplay();
	display.asyncExec(new Runnable() {
		@Override
		public void run() {
			// never apply outdated highlighting
			if(sourceViewer != null	&& modificationStamp == resourceSet.getModificationStamp())
				runnable.run();
		}
	});
}
 
Example #5
Source File: HighlightingPresenter.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a runnable for updating the presentation.
 * <p>
 * NOTE: Called from background thread.
 * </p>
 * 
 * @param textPresentation
 *            the text presentation
 * @param addedPositions
 *            the added positions
 * @param removedPositions
 *            the removed positions
 * @return the runnable or <code>null</code>, if reconciliation should be canceled
 */
public Runnable createUpdateRunnable(final TextPresentation textPresentation,
		List<AttributedPosition> addedPositions, List<AttributedPosition> removedPositions) {
	if (fSourceViewer == null || textPresentation == null)
		return null;

	// TODO: do clustering of positions and post multiple fast runnables
	final AttributedPosition[] added = new AttributedPosition[addedPositions.size()];
	addedPositions.toArray(added);
	final AttributedPosition[] removed = new AttributedPosition[removedPositions.size()];
	removedPositions.toArray(removed);

	if (isCanceled())
		return null;

	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			updatePresentation(textPresentation, added, removed);
		}
	};
	return runnable;
}
 
Example #6
Source File: DamageRepairer.java    From LogViewer with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: InformationPresenterHelpers.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public TooltipInformationControlCreator(IInformationPresenter presenter) {
    if (presenter == null) {
        presenter = new AbstractTooltipInformationPresenter() {

            @Override
            protected void onUpdatePresentation(String hoverInfo, TextPresentation presentation) {
            }

            @Override
            protected void onHandleClick(Object data) {

            }
        };
    }
    this.presenter = presenter;
}
 
Example #8
Source File: StyledTextForShowingCodeFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #9
Source File: FixedHighlightingReconciler.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Update the presentation.
 *
 * @param textPresentation
 *          the text presentation
 * @param addedPositions
 *          the added positions
 * @param removedPositions
 *          the removed positions
 * @param resource
 *          the resource for which the positions have been computed
 */
private void updatePresentation(final TextPresentation textPresentation, final List<AttributedPosition> addedPositions, final List<AttributedPosition> removedPositions, final XtextResource resource) {
  final Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
  if (runnable == null) {
    return;
  }
  final XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet();
  final int modificationStamp = resourceSet.getModificationStamp();
  Display display = getDisplay();
  display.asyncExec(new Runnable() {
    @Override
    public void run() {
      // never apply outdated highlighting
      if (sourceViewer != null && modificationStamp == resourceSet.getModificationStamp()) {
        runnable.run();
      }
    }
  });
}
 
Example #10
Source File: PyInformationPresenter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #11
Source File: StyleRangesCollector.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void colorize(TextPresentation presentation, Throwable error) {
	add(presentation);
	if (waitForToLineNumber != null) {
		int offset = presentation.getExtent().getOffset() + presentation.getExtent().getLength();
		try {
			if (waitForToLineNumber != document.getLineOfOffset(offset)) {
				return;
			} else {
				waitForToLineNumber = null;
			}
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	}
	((Command) command).setStyleRanges("[" + currentRanges.toString() + "]");
	synchronized (lock) {
		lock.notifyAll();
	}
}
 
Example #12
Source File: PyInformationPresenterTest.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void testStyleRanges() throws Exception {
    PyInformationPresenter presenter = new PyInformationPresenter();
    TextPresentation presentation = new TextPresentation();
    String str = "@foo: <pydev_link link=\"itemPointer\">link</pydev_link> <pydev_hint_bold>bold</pydev_hint_bold>";

    Reader reader = presenter.createReader(str, presentation);
    String handled = StringUtils.readAll(reader);
    assertEquals("@foo: link bold", handled);
    Iterator<StyleRange> it = presentation.getAllStyleRangeIterator();
    ArrayList<String> tagsReplaced = new ArrayList<String>();

    ArrayList<String> expected = new ArrayList<String>();
    expected.add("<pydev_link link=\"itemPointer\">");
    expected.add("<pydev_hint_bold>");

    while (it.hasNext()) {
        PyStyleRange next = (PyStyleRange) it.next();
        tagsReplaced.add(next.tagReplaced);
    }
    assertEquals(expected, tagsReplaced);
}
 
Example #13
Source File: NonRuleBasedDamagerRepairer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
 */
public void createPresentation(TextPresentation presentation, ITypedRegion region)
{
	wipeExistingScopes(region);
	synchronized (getLockObject(fDocument))
	{
		try
		{
			fDocument.addPositionCategory(ICommonConstants.SCOPE_CATEGORY);
			fDocument.addPosition(
					ICommonConstants.SCOPE_CATEGORY,
					new TypedPosition(region.getOffset(), region.getLength(), (String) fDefaultTextAttribute
							.getData()));
		}
		catch (Exception e)
		{
			IdeLog.logError(CommonEditorPlugin.getDefault(), e);
		}
	}

	addRange(presentation, region.getOffset(), region.getLength(), getTextAttribute(region));
}
 
Example #14
Source File: SemanticHighlightingPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a runnable for updating the presentation.
 * <p>
 * NOTE: Called from background thread.
 * </p>
 * @param textPresentation the text presentation
 * @param addedPositions the added positions
 * @param removedPositions the removed positions
 * @return the runnable or <code>null</code>, if reconciliation should be canceled
 */
public Runnable createUpdateRunnable(final TextPresentation textPresentation, List<Position> addedPositions, List<Position> removedPositions) {
	if (fSourceViewer == null || textPresentation == null)
		return null;

	// TODO: do clustering of positions and post multiple fast runnables
	final HighlightedPosition[] added= new SemanticHighlightingManager.HighlightedPosition[addedPositions.size()];
	addedPositions.toArray(added);
	final SemanticHighlightingManager.HighlightedPosition[] removed= new SemanticHighlightingManager.HighlightedPosition[removedPositions.size()];
	removedPositions.toArray(removed);

	if (isCanceled())
		return null;

	Runnable runnable= new Runnable() {
		public void run() {
			updatePresentation(textPresentation, added, removed);
		}
	};
	return runnable;
}
 
Example #15
Source File: PyInformationPresenter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
protected void adaptTextPresentation(TextPresentation presentation, int offset, int insertLength) {

        int yoursStart = offset;
        int yoursEnd = offset + insertLength - 1;
        yoursEnd = Math.max(yoursStart, yoursEnd);

        Iterator<StyleRange> e = presentation.getAllStyleRangeIterator();
        while (e.hasNext()) {

            StyleRange range = e.next();

            int myStart = range.start;
            int myEnd = range.start + range.length - 1;
            myEnd = Math.max(myStart, myEnd);

            if (myEnd < yoursStart) {
                continue;
            }

            if (myStart < yoursStart) {
                range.length += insertLength;
            } else {
                range.start += insertLength;
            }
        }
    }
 
Example #16
Source File: CoverageInformationItem.java    From tlaplus with MIT License 5 votes vote down vote up
public void style(final TextPresentation textPresentation, final Representation rep) {
	if (isRoot()) {
		style(textPresentation, true, rep);
	} else {
		style(textPresentation, false, rep);
	}
}
 
Example #17
Source File: ActionInformationItem.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public void style(TextPresentation textPresentation, final Representation rep) {
	if (relation == Relation.PROP) {
		return;
	} else if (isNotInFile) {
		// Skip styling this item but style its children.
		for (CoverageInformationItem child : getChildren()) {
			child.style(textPresentation, rep);
		}
		return;
	}
	super.style(textPresentation, rep);
}
 
Example #18
Source File: ActionInformationItem.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
protected void style(final TextPresentation textPresentation, boolean merge, final Representation rep) {
	if (relation == Relation.PROP) {
		return;
	} else if (isNotInFile) {
		// Skip styling this item but style its children.
		for (CoverageInformationItem child : getChildren()) {
			child.style(textPresentation, merge, rep);
		}
		return;
	}
	super.style(textPresentation, merge, rep);
}
 
Example #19
Source File: CoverageInformationItem.java    From tlaplus with MIT License 5 votes vote down vote up
protected void style(final TextPresentation textPresentation, final boolean merge, final Representation rep) {
	if (!isRoot()) {
		final StyleRange rs = new StyleRange();
		
		// IRegion
		rs.start = region.getOffset();
		rs.length = region.getLength();
		
		// Background Color
		rs.background = rep.getColor(this, merge ? Grouping.COMBINED : Grouping.INDIVIDUAL);
		
		// Zero Coverage
		if ((rep == Representation.STATES_DISTINCT || rep == Representation.STATES) && !(this instanceof ActionInformationItem)) {
			rs.background = JFaceResources.getColorRegistry().get(ModuleCoverageInformation.GRAY);
			rs.borderStyle = SWT.NONE;
			rs.borderColor = null;
		} else if (rep != Representation.COST && rep.getValue(this, Grouping.INDIVIDUAL) == 0L) {
			rs.background = null;
			rs.borderStyle = SWT.BORDER_SOLID;
			rs.borderColor = JFaceResources.getColorRegistry().get(ModuleCoverageInformation.RED);
		}
		
		// Track active subtree
		rs.data = this; //mergeStyleRange does not merge rs.data, thus track active instead.
		active = true;
		
		textPresentation.mergeStyleRange(addStlye(rs));
	}
	for (CoverageInformationItem child : childs) {
		child.style(textPresentation, merge, rep);
	}
}
 
Example #20
Source File: NonRuleBasedDamagerRepairer.java    From http4e with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: PresentationRepairer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example #22
Source File: ActionInformationItem.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public void style(final TextPresentation textPresentation, final Color c, final Representation rep) {
	// Do not unstyle AII when specific CostModel tree gets selected.
	for (CoverageInformationItem child : getChildren()) {
		child.style(textPresentation, c, rep);
	}
}
 
Example #23
Source File: NonRuleBasedDamagerRepairer.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	addRange(
		presentation,
		region.getOffset(),
		region.getLength(),
		fDefaultTextAttribute);
}
 
Example #24
Source File: XtextStyledTextHighlightingReconciler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Update the presentation.
 * 
 * @param textPresentation
 *            the text presentation
 * @param addedPositions
 *            the added positions
 * @param removedPositions
 *            the removed positions
 */
private void updatePresentation(TextPresentation textPresentation,
		List<AttributedPosition> addedPositions,
		List<AttributedPosition> removedPositions) {
	Runnable runnable = presenter.createUpdateRunnable(textPresentation,
			addedPositions, removedPositions);
	if (runnable == null)
		return;

	Display display = Display.getDefault();
	display.asyncExec(runnable);
}
 
Example #25
Source File: XtextStyledTextHighlightingReconciler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void modelChanged(XtextResource resource) {
	// ensure at most one thread can be reconciling at any time
	synchronized (fReconcileLock) {
		if (reconciling)
			return;
		reconciling = true;
	}
	final HighlightingPresenter highlightingPresenter = presenter;
	try {
		if (highlightingPresenter == null)
			return;

		highlightingPresenter.setCanceled(false);

		if (highlightingPresenter.isCanceled())
			return;

		startReconcilingPositions();

		if (!highlightingPresenter.isCanceled()) {
			reconcilePositions(resource);
		}

		final TextPresentation[] textPresentation = new TextPresentation[1];
		if (!highlightingPresenter.isCanceled()) {
			textPresentation[0] = highlightingPresenter.createPresentation(
					addedPositions, removedPositions);
		}

		if (!highlightingPresenter.isCanceled())
			updatePresentation(textPresentation[0], addedPositions,
					removedPositions);

		stopReconcilingPositions();
	} finally {
		synchronized (fReconcileLock) {
			reconciling = false;
		}
	}
}
 
Example #26
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example #27
Source File: PyInformationPresenter.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void append(FastStringBuffer buffer, String string, TextPresentation presentation) {

        int length = string.length();
        buffer.append(string);

        if (presentation != null) {
            adaptTextPresentation(presentation, fCounter, length);
        }

        fCounter += length;
    }
 
Example #28
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #29
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example #30
Source File: PyDefaultDamagerRepairer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
    }
}