org.eclipse.jface.text.TextAttribute Java Examples

The following examples show how to use org.eclipse.jface.text.TextAttribute. 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: AbstractEditorConfigScanner.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
	boolean eventValue = false;
	Object value = event.getNewValue();
	if (value instanceof Boolean)
		eventValue = ((Boolean) value).booleanValue();
	else if (IPreferenceStore.TRUE.equals(value))
		eventValue = true;

	Object data = token.getData();
	if (data instanceof TextAttribute) {
		TextAttribute oldAttr = (TextAttribute) data;
		boolean activeValue = (oldAttr.getStyle() & styleAttribute) == styleAttribute;
		if (activeValue != eventValue)
			token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(),
					eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
	}
}
 
Example #2
Source File: SyntaxColoringPreferencePage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void handleTreeSelection() {
    RootTreeItem root = getRootTreeItem();
    if (root != null) {
        List<HighlightingColorTreeItem> lst = new ArrayList<HighlightingColorTreeItem>();
        getHLItemsFromRoot(root, lst);
    	fPreviewer.activateContent(root.syntaxColoring, lst);
        fPreviewer.updateColors();
    }
    
	HighlightingColorTreeItem it = getHighlightingColorListItem();

    fEnable.setEnabled(it != null && it.mayBeDisabled);
	fSyntaxForegroundColorEditor.setEnabled(it != null);
    fBoldCheckBox.setEnabled(it != null);
    fItalicCheckBox.setEnabled(it != null);
    fStrikethroughCheckBox.setEnabled(it != null);
    fUnderlineCheckBox.setEnabled(it != null);

    fEnable.setSelection(it == null || !it.isDisabled);
	fSyntaxForegroundColorEditor.setColorValue(it == null ? new RGB(0x80, 0x80, 0x80) : it.rgb);
    fBoldCheckBox.setSelection(it == null ? false : (it.style & SWT.BOLD) != 0);
    fItalicCheckBox.setSelection(it == null ? false : (it.style & SWT.ITALIC) != 0);
    fStrikethroughCheckBox.setSelection(it == null ? false : (it.style & TextAttribute.STRIKETHROUGH) != 0);
    fUnderlineCheckBox.setSelection(it == null ? false : (it.style & TextAttribute.UNDERLINE) != 0);
}
 
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: XMLTextScanner.java    From http4e with Apache License 2.0 6 votes vote down vote up
public XMLTextScanner( ColorManager colorManager) {

      ESCAPED_CHAR = new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.ESCAPED_CHAR)));
      CDATA_START = new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.CDATA)));
      CDATA_END = new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.CDATA)));
      CDATA_TEXT = new Token(new TextAttribute(colorManager.getColor(IXMLColorConstants.CDATA_TEXT)));
      IRule[] rules = new IRule[2];

      // Add rule to pick up escaped chars
      // Add rule to pick up start of CDATA section
      rules[0] = new CDataRule(CDATA_START, true);
      // Add a rule to pick up end of CDATA sections
      rules[1] = new CDataRule(CDATA_END, false);
      setRules(rules);

   }
 
Example #5
Source File: TextAttributeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public TextAttribute getMergedAttributes(String[] ids) {
	if (ids.length < 2)
		throw new IllegalStateException();
	String mergedIds = getMergedIds(ids);
	TextAttribute result = getAttribute(mergedIds);
	if (result == null) {
		for (String id : ids) {
			result = merge(result, getAttribute(id));
		}
		if (result != null)
			attributes.put(mergedIds, result);
		else
			attributes.remove(mergedIds);
	}
	return result;
}
 
Example #6
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 #7
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addLink(IHyperlink link, int offset, int length) {
    if (testOutputText == null) {
        return;
    }
    StyleRangeWithCustomData range = new StyleRangeWithCustomData();
    range.underline = true;
    try {
        range.underlineStyle = SWT.UNDERLINE_LINK;
    } catch (Throwable e) {
        //Ignore (not available on earlier versions of eclipse)
    }

    //Set the proper color if it's available.
    TextAttribute textAttribute = ColorManager.getDefault().getHyperlinkTextAttribute();
    if (textAttribute != null) {
        range.foreground = textAttribute.getForeground();
    } else {
        range.foreground = JFaceColors.getHyperlinkText(Display.getDefault());
    }
    range.start = offset;
    range.length = length + 1;
    range.customData = link;
    testOutputText.setStyleRange(range);
}
 
Example #8
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the color that should be used for errors.
 */
public Color getErrorColor() {
    TextAttribute attribute = ColorManager.getDefault().getConsoleErrorTextAttribute();
    if (attribute == null) {
        return null;
    }
    Color errorColor = attribute.getForeground();
    return errorColor;
}
 
Example #9
Source File: TextStyling.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static TextAttribute createTextAttribute(Color color, boolean isBold, boolean isItalic, 
		boolean isStrikethrough, boolean isUnderline) {
	int style = SWT.NORMAL;
	
	style |= isBold ? SWT.BOLD : 0;
	style |= isItalic ? SWT.ITALIC : 0;
	style |= isStrikethrough ? TextAttribute.STRIKETHROUGH : 0;
	style |= isUnderline ? TextAttribute.UNDERLINE : 0;
	
	return new TextAttribute(color, null, style);
}
 
Example #10
Source File: AttributedPosition.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return Returns a corresponding style range.
 */
public StyleRange createStyleRange() {
	int len = getLength();

	TextAttribute textAttribute = attribute;
	int style = textAttribute.getStyle();
	int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
	StyleRange styleRange = new StyleRange(getOffset(), len, textAttribute.getForeground(),
			textAttribute.getBackground(), fontStyle);
	styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
	styleRange.underline = (style & TextAttribute.UNDERLINE) != 0;
	styleRange.font = textAttribute.getFont();

	return styleRange;
}
 
Example #11
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Color getBackground(String scope)
{
	TextAttribute attr = getTextAttribute(scope);
	if (attr == null)
	{
		return null;
	}
	return attr.getBackground();
}
 
Example #12
Source File: NonRuleBasedDamagerRepairer.java    From codeexamples-eclipse 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)
		presentation.addStyleRange(
			new StyleRange(
				offset,
				length,
				attr.getForeground(),
				attr.getBackground(),
				attr.getStyle()));
}
 
Example #13
Source File: BibCodeScanner.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a BibTeX document scanner
 * 
 * @param provider The color provider for syntax highlighting
 */
public BibCodeScanner(BibColorProvider provider) {

    IToken keyword = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.KEYWORD)));
    IToken comment = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.SINGLE_LINE_COMMENT)));
    IToken other = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.DEFAULT)));

    List rules = new ArrayList();

    // Add rule for single line comments.
    rules.add(new EndOfLineRule("%", comment));

    rules.add(new BibCommandRule(keyword));

    // Add generic whitespace rule.
    rules.add(new WhitespaceRule(new WhitespaceDetector()));

    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new BibWordDetector(), other);
    rules.add(wordRule);

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example #14
Source File: XMLConfiguration.java    From http4e with Apache License 2.0 5 votes vote down vote up
protected XMLTextScanner getXMLTextScanner(){
    if( textScanner == null) {
        textScanner = new XMLTextScanner(colorManager);
        textScanner.setDefaultReturnToken(new Token(new TextAttribute(
                colorManager.getColor(IXMLColorConstants.DEFAULT))));
    }
    return textScanner;
}
 
Example #15
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private TextAttribute getTextAttribute(String name)
{
	if (getCurrentTheme() != null)
	{
		return getCurrentTheme().getTextAttribute(name);
	}
	return new TextAttribute(ThemePlugin.getDefault().getColorManager().getColor(new RGB(255, 255, 255)));
}
 
Example #16
Source File: ThemeGetTextAttribute.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private TextAttribute toTextAttribute(DelayedTextAttribute delayedOrTextAttr, boolean forceColor)
{
	DelayedTextAttribute attr = (DelayedTextAttribute) delayedOrTextAttr;
	Color fg = null;
	if (attr.foreground != null || forceColor)
	{
		fg = colorManager.getColor(merge(attr.foreground, null, defaultFG).toRGB());
	}
	Color bg = null;
	if (attr.background != null || forceColor)
	{
		bg = colorManager.getColor(merge(attr.background, null, defaultBG).toRGB());
	}
	return new TextAttribute(fg, bg, attr.style);
}
 
Example #17
Source File: XMLConfiguration.java    From http4e with Apache License 2.0 5 votes vote down vote up
protected CDataScanner getCDataScanner(){
    if( cdataScanner == null) {
        cdataScanner = new CDataScanner(colorManager);
        cdataScanner.setDefaultReturnToken(new Token(new TextAttribute(
                colorManager.getColor(IXMLColorConstants.CDATA_TEXT))));
    }
    return cdataScanner;
}
 
Example #18
Source File: NonRuleBasedDamagerRepairer.java    From birt 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 )
	{
		presentation.addStyleRange( new StyleRange( offset,
				length,
				attr.getForeground( ),
				attr.getBackground( ),
				attr.getStyle( ) ) );
	}
}
 
Example #19
Source File: HighlightingPresenter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Invalidate text presentation of positions with the given highlighting.
 * 
 * @param highlighting
 *            The highlighting
 */
public void highlightingStyleChanged(TextAttribute highlighting) {
	for (int i = 0, n = fPositions.size(); i < n; i++) {
		AttributedPosition position = fPositions.get(i);
		if (position.getHighlighting() == highlighting)
			fSourceViewer.invalidateTextPresentation(position.getOffset(), position.getLength());
	}
}
 
Example #20
Source File: CommentScanner.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
public CommentScanner() {
	List<IRule> rules = new ArrayList<IRule>();

	Token commentToken = new Token(new TextAttribute(new Color(
			Display.getCurrent(), new RGB(63, 127, 95))));
	rules.add(new EndOfLineRule("--", commentToken));
	rules.add(new EndOfLineRule("//", commentToken));
	rules.add(new MultiLineRule("/*", "*/", commentToken));

	setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example #21
Source File: SemanticHighlightingManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void adaptToTextStyleChange(Highlighting highlighting, PropertyChangeEvent event, int styleAttribute) {
	boolean eventValue= false;
	Object value= event.getNewValue();
	if (value instanceof Boolean)
		eventValue= ((Boolean) value).booleanValue();
	else if (IPreferenceStore.TRUE.equals(value))
		eventValue= true;

	TextAttribute oldAttr= highlighting.getTextAttribute();
	boolean activeValue= (oldAttr.getStyle() & styleAttribute) == styleAttribute;

	if (activeValue != eventValue)
		highlighting.setTextAttribute(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
}
 
Example #22
Source File: TextAttributeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected TextAttribute createTextAttribute(String id, TextStyle defaultTextStyle) {
	TextStyle textStyle = new TextStyle();
	preferencesAccessor.populateTextStyle(id, textStyle, defaultTextStyle);
	int style = textStyle.getStyle();
	Font fontFromFontData = EditorUtils.fontFromFontData(textStyle.getFontData());
	return new TextAttribute(EditorUtils.colorFromRGB(textStyle.getColor()), EditorUtils.colorFromRGB(textStyle
			.getBackgroundColor()), style, fontFromFontData);
}
 
Example #23
Source File: TexSourceViewerConfiguration.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Defines a math partition scanner and sets the default
 * color for it.
 * @return a scanner to detect math partitions
 */
protected TexMathScanner getTeXMathScanner() {
    if (mathScanner == null) {
        mathScanner = new TexMathScanner(colorManager);
        mathScanner.setDefaultReturnToken(
                new Token(
                        new TextAttribute(
                                colorManager.getColor(ColorManager.EQUATION),
                                null,
                                colorManager.getStyle(ColorManager.EQUATION_STYLE))));
    }
    return mathScanner;
}
 
Example #24
Source File: AbstractEditorConfigScanner.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
public void adaptToPreferenceChange(PropertyChangeEvent event) {
	String p = event.getProperty();
	int index = indexOf(p);
	Token token = getToken(fPropertyNamesColor[index]);
	if (fPropertyNamesColor[index].equals(p))
		adaptToColorChange(token, event);
	else if (fPropertyNamesBold[index].equals(p))
		adaptToStyleChange(token, event, SWT.BOLD);
	else if (fPropertyNamesItalic[index].equals(p))
		adaptToStyleChange(token, event, SWT.ITALIC);
	else if (fPropertyNamesStrikethrough[index].equals(p))
		adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
	else if (fPropertyNamesUnderline[index].equals(p))
		adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
}
 
Example #25
Source File: LineStyleProviderForInlinedCss.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void addStyleRange(Collection<StyleRange> holdResults, TextAttribute attribute,
    int start, int end) {
  if (attribute != null) {
    holdResults.add(new StyleRange(start, end, attribute.getForeground(),
        attribute.getBackground(), attribute.getStyle()));
  } else {
    holdResults.add(new StyleRange(start, end, null, null));
  }
}
 
Example #26
Source File: TexSourceViewerConfiguration.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Defines an optional argument (square bracket) scanner and sets the default color for it
 * @return a scanner to detect argument partitions
 */
protected TexOptArgScanner getTexOptArgScanner() {
    if (optArgumentScanner == null) {
        optArgumentScanner = new TexOptArgScanner(colorManager);
        optArgumentScanner.setDefaultReturnToken(
                new Token(
                        new TextAttribute(
                                colorManager.getColor(ColorManager.SQUARE_BRACKETS),
                                null,
                                colorManager.getStyle(ColorManager.SQUARE_BRACKETS_STYLE))));
    }
    return optArgumentScanner;
}
 
Example #27
Source File: PyDefaultDamagerRepairer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a damager/repairer that uses the given scanner. The scanner may not be <code>null</code>
 * and is assumed to return only token that carry text attributes.
 *
 * @param scanner the token scanner to be used, may not be <code>null</code>
 */
public PyDefaultDamagerRepairer(ITokenScanner scanner) {

    Assert.isNotNull(scanner);

    fScanner = scanner;
    fDefaultTextAttribute = new TextAttribute(null);
}
 
Example #28
Source File: StringScanner.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
public StringScanner() {
	List<IRule> rules = new ArrayList<IRule>();

	Token stringToken = new Token(new TextAttribute(new Color(
			Display.getCurrent(), new RGB(42, 0, 255))));
	rules.add(new SingleLineRule("'", "'", stringToken));
	rules.add(new SingleLineRule("\"", "\"", stringToken));

	setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example #29
Source File: InstructionsRuleScanner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
public InstructionsRuleScanner(ColorProvider provider) {
	IToken stringToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_STRING_COLOR))));
	IToken commentToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_COMMENT_COLOR))));
	IToken instructToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_INSTRUCT_COLOR)), null, Font.ITALIC));
	IToken definitionsToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_DEF_COLOR)), null, Font.ITALIC));

	List<IRule> rules = Lists.newArrayList();
	// rule for Strings - may spanning multiple lines
	rules.add(new MultiLineRule("\"", "\"", stringToken));
	rules.add(new MultiLineRule("\'", "\'", stringToken));
	rules.add(new EndOfLineRule("#%", instructToken));
	// rule for comments - ended by a line delimiter
	rules.add(new EndOfLineRule("//", commentToken));

	WordRule wordRule = RuleFactory.buildRule(ImpexRules.KEYWORD, null);		
	// rule for instructions
	for (String word : Formatter.INSTRUCTION_CLASS_PROPOSALS) {
		wordRule.addWord(word, instructToken);
	}

	rules.add(wordRule);

	// rule for definitions
	wordRule = RuleFactory.buildRule(ImpexRules.VARIABLE, definitionsToken);
	rules.add(wordRule);
	IRule[] ruleArray = new IRule[rules.size()];
	setRules(rules.toArray(ruleArray));
}
 
Example #30
Source File: AbstractJavaScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void adaptToPreferenceChange(PropertyChangeEvent event) {
	String p= event.getProperty();
	int index= indexOf(p);
	Token token= getToken(fPropertyNamesColor[index]);
	if (fPropertyNamesColor[index].equals(p))
		adaptToColorChange(token, event);
	else if (fPropertyNamesBold[index].equals(p))
		adaptToStyleChange(token, event, SWT.BOLD);
	else if (fPropertyNamesItalic[index].equals(p))
		adaptToStyleChange(token, event, SWT.ITALIC);
	else if (fPropertyNamesStrikethrough[index].equals(p))
		adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
	else if (fPropertyNamesUnderline[index].equals(p))
		adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
}