类org.eclipse.jface.text.TextAttribute源码实例Demo

下面列出了怎么用org.eclipse.jface.text.TextAttribute的API类实例代码及写法,或者点击链接到github查看源代码。

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));
	}
}
 
源代码2 项目: Pydev   文件: PyUnitView.java
@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);
}
 
源代码3 项目: http4e   文件: XMLTextScanner.java
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);

   }
 
源代码4 项目: xtext-eclipse   文件: TextAttributeProvider.java
@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;
}
 
源代码5 项目: xds-ide   文件: SyntaxColoringPreferencePage.java
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);
}
 
源代码6 项目: Pydev   文件: StyledTextForShowingCodeFactory.java
/**
 * 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();
    }
}
 
源代码7 项目: LogViewer   文件: DamageRepairer.java
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);
}
 
源代码8 项目: APICloud-Studio   文件: Theme.java
public Color getForeground(String scope)
{
	TextAttribute attr = getTextAttribute(scope);
	if (attr == null)
	{
		return null;
	}
	return attr.getForeground();
}
 
源代码9 项目: http4e   文件: HConfiguration.java
private RuleBasedScanner getValueScanner(){
   if (valueScanner == null) {
       valueScanner = new HValueScanner();
       valueScanner.setDefaultReturnToken(new Token(new TextAttribute(ResourceUtils.getColor(Styles.STRING))));
   }
   return valueScanner;
}
 
源代码10 项目: Pydev   文件: PyUnitView.java
/**
 * @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;
}
 
源代码11 项目: http4e   文件: XMLConfiguration.java
protected XMLTextScanner getXMLTextScanner(){
    if( textScanner == null) {
        textScanner = new XMLTextScanner(colorManager);
        textScanner.setDefaultReturnToken(new Token(new TextAttribute(
                colorManager.getColor(IXMLColorConstants.DEFAULT))));
    }
    return textScanner;
}
 
源代码12 项目: http4e   文件: XMLConfiguration.java
protected CDataScanner getCDataScanner(){
    if( cdataScanner == null) {
        cdataScanner = new CDataScanner(colorManager);
        cdataScanner.setDefaultReturnToken(new Token(new TextAttribute(
                colorManager.getColor(IXMLColorConstants.CDATA_TEXT))));
    }
    return cdataScanner;
}
 
源代码13 项目: birt   文件: NonRuleBasedDamagerRepairer.java
/**
 * 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( ) ) );
	}
}
 
/**
 * 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()));
}
 
源代码15 项目: APICloud-Studio   文件: ThemeManager.java
private TextAttribute getTextAttribute(String name)
{
	if (getCurrentTheme() != null)
	{
		return getCurrentTheme().getTextAttribute(name);
	}
	return new TextAttribute(ThemePlugin.getDefault().getColorManager().getColor(new RGB(255, 255, 255)));
}
 
源代码16 项目: textuml   文件: SyntaxHighlighter.java
ITokenScanner getCommentScanner() {
    // lazy init
    if (this.commentScanner == null) {
        final Token comment = new Token(new TextAttribute(JFaceResources.getColorRegistry().get(COMMENT_COLOR)));
        // no rules needed, because this will apply to comment partition
        // only
        final RuleBasedScanner ruleBasedScanner = new RuleBasedScanner();
        // this will apply the syntax
        ruleBasedScanner.setDefaultReturnToken(comment);
        this.commentScanner = ruleBasedScanner;
    }
    return commentScanner;
}
 
源代码17 项目: xtext-eclipse   文件: TextAttributeProvider.java
@Inject
public TextAttributeProvider(IHighlightingConfiguration highlightingConfig,
		IPreferenceStoreAccess preferenceStoreAccess, PreferenceStoreAccessor prefStoreAccessor) {
	this.highlightingConfig = highlightingConfig;
	this.preferencesAccessor = prefStoreAccessor;
	this.attributes = new HashMap<String, TextAttribute>();
	preferenceStoreAccess.getPreferenceStore().addPropertyChangeListener(this);
	initialize();
}
 
源代码18 项目: xtext-eclipse   文件: TextAttributeProvider.java
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);
}
 
源代码19 项目: xtext-eclipse   文件: AttributedPosition.java
/**
 * @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;
}
 
源代码20 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * 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());
	}
}
 
源代码21 项目: mat-calcite-plugin   文件: CommentScanner.java
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()]));
}
 
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));
}
 
源代码23 项目: texlipse   文件: BibCodeScanner.java
/**
 * 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);
}
 
源代码24 项目: texlipse   文件: TexSourceViewerConfiguration.java
/**
 * 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;
}
 
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);
}
 
源代码26 项目: texlipse   文件: TexSourceViewerConfiguration.java
/**
 * 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;
}
 
源代码27 项目: mat-calcite-plugin   文件: StringScanner.java
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()]));
}
 
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);
}
 
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));
}
 
源代码30 项目: APICloud-Studio   文件: Theme.java
public Color getBackground(String scope)
{
	TextAttribute attr = getTextAttribute(scope);
	if (attr == null)
	{
		return null;
	}
	return attr.getBackground();
}
 
 类所在包
 同包方法