org.eclipse.swt.custom.StyledTextContent Java Examples

The following examples show how to use org.eclipse.swt.custom.StyledTextContent. 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: IndentGuidesPainter.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Draw the given line range.
 * 
 * @param gc
 *            the GC
 * @param startLine
 *            first line number
 * @param endLine
 *            last line number (inclusive)
 * @param x
 *            the X-coordinate of the drawing range
 * @param w
 *            the width of the drawing range
 */
private void drawLineRange(GC gc, int startLine, int endLine, int x, int w) {
	spaceWidth = gc.getAdvanceWidth(' ');

	StyledTextContent content = fTextWidget.getContent();
	for (int line = startLine; line <= endLine; line++) {
		int widgetOffset = fTextWidget.getOffsetAtLine(line);
           if (!isFoldedLine(content.getLineAtOffset(widgetOffset))) {
               IndentGuideDescriptor[] indentGuides = indentsModel.getIndentGuidesAtLine(line);
               if (indentGuides == null) 
                   return; // not computed yet
               for (IndentGuideDescriptor indent : indentGuides) {
                   draw(gc, widgetOffset, indent.indentLevel);
               }
           }
	}
}
 
Example #2
Source File: VerticalIndentGuidesPainter.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private boolean getStyledTextContentChangedAndStoreNew() {
    StyledTextContent currentContent = this.styledText.getContent();
    StyledTextContent oldContent = this.content;
    if (currentContent != oldContent) {
        //Important: the content may change during runtime, so, we have to stop listening the old one and
        //start listening the new one.
        if (oldContent != null) {
            oldContent.removeTextChangeListener(this);
        }
        this.content = currentContent;
        currentContent.addTextChangeListener(this);
        return true;
    }
    return false;
}
 
Example #3
Source File: BidiLayout.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void setContent(StyledTextContent newContent) {
	styledText.setContent(newContent);
}
 
Example #4
Source File: WhitespaceCharacterPainter.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw characters of content range.
 * 
 * @param gc
 *            the GC
 * @param startOffset
 *            inclusive start index
 * @param endOffset
 *            exclusive end index
 */
private void drawCharRange(GC gc, int startOffset, int endOffset)
{
	StyledTextContent content = fTextWidget.getContent();
	int length = endOffset - startOffset;
	String text = content.getTextRange(startOffset, length);
	StyleRange styleRange = null;
	Color fg = null;
	Point selection = fTextWidget.getSelection();
	StringBuffer visibleChar = new StringBuffer(10);
	for (int textOffset = 0; textOffset <= length; ++textOffset)
	{
		int delta = 0;
		boolean eol = false;
		if (textOffset < length)
		{
			delta = 1;
			char c = text.charAt(textOffset);
			switch (c)
			{
				case ' ':
					visibleChar.append(SPACE_SIGN);
					// 'continue' would improve performance but may produce
					// drawing errors
					// for long runs of space if width of space and dot differ
					break;
				case '\u3000': // ideographic whitespace
					visibleChar.append(IDEOGRAPHIC_SPACE_SIGN);
					// 'continue' would improve performance but may produce
					// drawing errors
					// for long runs of space if width of space and dot differ
					break;
				case '\t':
					visibleChar.append(TAB_SIGN);
					break;
				case '\r':
					visibleChar.append(CARRIAGE_RETURN_SIGN);
					if (textOffset >= length - 1 || text.charAt(textOffset + 1) != '\n')
					{
						eol = true;
						break;
					}
					continue;
				case '\n':
					visibleChar.append(LINE_FEED_SIGN);
					eol = true;
					break;
				default:
					delta = 0;
					break;
			}
		}
		if (visibleChar.length() > 0)
		{
			int widgetOffset = startOffset + textOffset - visibleChar.length() + delta;
			if (!eol || !isFoldedLine(content.getLineAtOffset(widgetOffset)))
			{
				if (widgetOffset >= selection.x && widgetOffset < selection.y)
				{
					fg = fTextWidget.getSelectionForeground();
				}
				else if (styleRange == null || styleRange.start + styleRange.length <= widgetOffset)
				{
					styleRange = fTextWidget.getStyleRangeAtOffset(widgetOffset);
					if (styleRange == null || styleRange.foreground == null)
					{
						fg = fTextWidget.getForeground();
					}
					else
					{
						fg = styleRange.foreground;
					}
				}
				draw(gc, widgetOffset, visibleChar.toString(), fg);
			}
			visibleChar.delete(0, visibleChar.length());
		}
	}
}
 
Example #5
Source File: IndentGuidePainter.java    From IndentGuide with MIT License 4 votes vote down vote up
/**
 * Draw the given line range.
 * 
 * @param gc
 *            the GC
 * @param startLine
 *            first line number
 * @param endLine
 *            last line number (inclusive)
 * @param x
 *            the X-coordinate of the drawing range
 * @param w
 *            the width of the drawing range
 */
private void drawLineRange(GC gc, int startLine, int endLine, int x, int w) {
	int tabs = fTextWidget.getTabs();

	StyledTextContent content = fTextWidget.getContent();
	for (int line = startLine; line <= endLine; line++) {
		int widgetOffset = fTextWidget.getOffsetAtLine(line);
		if (!isFoldedLine(content.getLineAtOffset(widgetOffset))) {
			String text = fTextWidget.getLine(line);
			int extend = 0;
			if (skipCommentBlock && assumeCommentBlock(text, tabs)) {
				extend -= tabs;
			}
			if (drawBlankLine && text.trim().length() == 0) {
				int prevLine = line;
				while (--prevLine >= 0) {
					text = fTextWidget.getLine(prevLine);
					if (text.trim().length() > 0) {
						int postLine = line;
						int lineCount = fTextWidget.getLineCount();
						while (++postLine < lineCount) {
							String tmp = fTextWidget.getLine(postLine);
							if (tmp.trim().length() > 0) {
								if (countSpaces(text, tabs) < countSpaces(
										tmp, tabs)) {
									extend += tabs;
								}
								break;
							}
						}
						break;
					}
				}
			}
			int count = countSpaces(text, tabs) + extend;
			for (int i = drawLeftEnd ? 0 : tabs; i < count; i += tabs) {
				draw(gc, widgetOffset, i);
			}
		}
	}
}