org.eclipse.jface.text.TextAttribute#UNDERLINE源码实例Demo

下面列出了org.eclipse.jface.text.TextAttribute#UNDERLINE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LogViewer   文件: DamageRepairer.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
 * @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);
    }
}
 
源代码2 项目: KaiZen-OpenAPI-Editor   文件: JsonScanner.java
private TextAttribute tokenAttribute(String colorPrefs, String boldPrefs, String italicPrefs,
        String underlinePrefs) {
    int style = SWT.NORMAL;

    boolean isBold = store.getBoolean(boldPrefs);
    if (isBold) {
        style = style | SWT.BOLD;
    }

    boolean isItalic = store.getBoolean(italicPrefs);
    if (isItalic) {
        style = style | SWT.ITALIC;
    }

    boolean isUnderline = store.getBoolean(underlinePrefs);
    if (isUnderline) {
        style = style | TextAttribute.UNDERLINE;
    }

    RGB color = PreferenceConverter.getColor(store, colorPrefs);
    TextAttribute attr = new TextAttribute(colorManager.getColor(color), null, style);
    return attr;
}
 
/**
 * Create a text attribute based on the given color, bold, italic,
 * strikethrough and underline preference keys.
 *
 * @param colorKey
 *            the color preference key
 * @param boldKey
 *            the bold preference key
 * @param italicKey
 *            the italic preference key
 * @param strikethroughKey
 *            the strikethrough preference key
 * @param underlineKey
 *            the italic preference key
 * @return the created text attribute
 */
private TextAttribute createTextAttribute(String colorKey, String boldKey, String italicKey,
		String strikethroughKey, String underlineKey) {
	Color color = null;
	if (colorKey != null)
		color = fColorManager.getColor(colorKey);

	int style = fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
	if (fPreferenceStore.getBoolean(italicKey))
		style |= SWT.ITALIC;

	if (fPreferenceStore.getBoolean(strikethroughKey))
		style |= TextAttribute.STRIKETHROUGH;

	if (fPreferenceStore.getBoolean(underlineKey))
		style |= TextAttribute.UNDERLINE;

	return new TextAttribute(color, null, style);
}
 
源代码4 项目: 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 )
	{
		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 );
	}
}
 
源代码5 项目: tm4e   文件: CSSTokenProvider.java
public CSSTokenProvider(InputStream in) {
	tokenMaps = new HashMap<>();
	try {
		parser = new CSSParser(in);
		for (IStyle style : parser.getStyles()) {
			RGB color = style.getColor();
			if (color != null) {
				int s = SWT.NORMAL;
				if (style.isBold()) {
					s = s | SWT.BOLD;
				}
				if (style.isItalic()) {
					s = s | SWT.ITALIC;
				}
				if (style.isUnderline()) {
					s = s | TextAttribute.UNDERLINE;
				}
				if (style.isStrikeThrough()) {
					s = s | TextAttribute.STRIKETHROUGH;
				}
				tokenMaps.put(style,
						new Token(new TextAttribute(ColorManager.getInstance().getColor(color), null, s)));
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
源代码6 项目: xtext-eclipse   文件: StylerFactory.java
@Override
public void applyStyles(TextStyle textStyle) {
	textStyle.strikeout = (xtextTextStyle.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
	textStyle.underline = (xtextTextStyle.getStyle() & TextAttribute.UNDERLINE) != 0;
	if (xtextTextStyle.getFontData() == null
			&& xtextTextStyle.getStyle() != org.eclipse.xtext.ui.editor.utils.TextStyle.DEFAULT_FONT_STYLE) {
		FontData fontData = new FontData();
		fontData.setStyle(xtextTextStyle.getStyle());
		xtextTextStyle.setFontData(fontData);
	}
	textStyle.font = fontFromFontData(xtextTextStyle.getFontData());
	if (xtextTextStyle.getBackgroundColor() != null) 
		textStyle.background = colorFromRGB(xtextTextStyle.getBackgroundColor());
	textStyle.foreground = colorFromRGB(xtextTextStyle.getColor());
}
 
源代码7 项目: 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;
}
 
源代码8 项目: xds-ide   文件: XStyledString.java
private StyleRange mkSRange(String s, Color fgColor, int style) {
    //NOTE: new used attributes in StyleRange must be reconcoled in convertToStyledString()
    StyleRange sr = new StyleRange();
    sr.start = sb.length();
    sr.length = s.length();
    sr.foreground = fgColor;
    sr.fontStyle = (style & (SWT.BOLD | SWT.ITALIC));
    sr.underline = (style & TextAttribute.UNDERLINE) != 0;
    sr.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
    usedStyles |= style;
    return sr;
}
 
源代码9 项目: Pydev   文件: PyDefaultDamagerRepairer.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) {
        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);
    }
}
 
源代码10 项目: LogViewer   文件: TextAttributeFactory.java
public static TextAttribute getTextAttribute(LogToolRuleDesc ruleDesc) {		
	if (ruleDesc != null) {
		int style = SWT.NORMAL;
		if (ruleDesc.isItalic())
			style |= SWT.ITALIC;
		if (ruleDesc.isBold())
			style |= SWT.BOLD;
		if (ruleDesc.isStrikethrough())
			style |= TextAttribute.STRIKETHROUGH;
		if (ruleDesc.isUnderline())
			style |= TextAttribute.UNDERLINE;			
		return new TextAttribute(new Color(Display.getDefault(),ruleDesc.getForegroundColor()),new Color(Display.getDefault(),ruleDesc.getBackgroundColor()), style);	
	}
	return null;
}
 
源代码11 项目: APICloud-Studio   文件: InvasiveThemeHijacker.java
protected void setWSTToken(IEclipsePreferences prefs, Theme theme, String ourEquivalentScope, String prefKey,
		boolean revertToDefaults)
{
	if (revertToDefaults)
	{
		prefs.remove(prefKey);
	}
	else
	{
		TextAttribute attr = theme.getTextAttribute(ourEquivalentScope);
		boolean bold = (attr.getStyle() & SWT.BOLD) != 0;
		boolean italic = (attr.getStyle() & SWT.ITALIC) != 0;
		boolean strikethrough = (attr.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
		boolean underline = (attr.getStyle() & TextAttribute.UNDERLINE) != 0;
		StringBuilder value = new StringBuilder();
		value.append(Theme.toHex(attr.getForeground().getRGB()));
		value.append('|');
		value.append(Theme.toHex(attr.getBackground().getRGB()));
		value.append('|');
		value.append(bold);
		value.append('|');
		value.append(italic);
		value.append('|');
		value.append(strikethrough);
		value.append('|');
		value.append(underline);
		prefs.put(prefKey, value.toString());
	}
}
 
源代码12 项目: APICloud-Studio   文件: ThemeingDamagerRepairer.java
private boolean matchesDefaults(TextAttribute attr)
{
	if (attr == null)
	{
		return false;
	}

	// Make sure font is just normal
	int style = attr.getStyle();
	int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
	if (fontStyle != SWT.NORMAL)
	{
		return false;
	}
	if ((style & TextAttribute.STRIKETHROUGH) != 0)
	{
		return false;
	}
	if ((style & TextAttribute.UNDERLINE) != 0)
	{
		return false;
	}

	// Is FG different?
	Color fg = attr.getForeground();
	if (fg != null && !fg.getRGB().equals(getCurrentTheme().getForeground()))
	{
		return false;
	}

	// Is BG different?
	Color bg = attr.getBackground();
	if (bg != null && !bg.getRGB().equals(getCurrentTheme().getBackground()))
	{
		return false;
	}
	return true;
}
 
/**
 * @return Returns a corresponding style range.
 */
public StyleRange createStyleRange() {
	int len= 0;
	if (fStyle.isEnabled())
		len= getLength();

	TextAttribute textAttribute= fStyle.getTextAttribute();
	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;

	return styleRange;
}
 
/**
 * Initialize semantic highlightings.
 */
private void initializeHighlightings() {
	fSemanticHighlightings= SemanticHighlightings.getSemanticHighlightings();
	fHighlightings= new Highlighting[fSemanticHighlightings.length];

	for (int i= 0, n= fSemanticHighlightings.length; i < n; i++) {
		SemanticHighlighting semanticHighlighting= fSemanticHighlightings[i];
		String colorKey= SemanticHighlightings.getColorPreferenceKey(semanticHighlighting);
		addColor(colorKey);

		String boldKey= SemanticHighlightings.getBoldPreferenceKey(semanticHighlighting);
		int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;

		String italicKey= SemanticHighlightings.getItalicPreferenceKey(semanticHighlighting);
		if (fPreferenceStore.getBoolean(italicKey))
			style |= SWT.ITALIC;

		String strikethroughKey= SemanticHighlightings.getStrikethroughPreferenceKey(semanticHighlighting);
		if (fPreferenceStore.getBoolean(strikethroughKey))
			style |= TextAttribute.STRIKETHROUGH;

		String underlineKey= SemanticHighlightings.getUnderlinePreferenceKey(semanticHighlighting);
		if (fPreferenceStore.getBoolean(underlineKey))
			style |= TextAttribute.UNDERLINE;

		boolean isEnabled= fPreferenceStore.getBoolean(SemanticHighlightings.getEnabledPreferenceKey(semanticHighlighting));

		fHighlightings[i]= new Highlighting(new TextAttribute(fColorManager.getColor(PreferenceConverter.getColor(fPreferenceStore, colorKey)), null, style), isEnabled);
	}
}
 
源代码15 项目: goclipse   文件: TextStyling.java
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);
}
 
源代码16 项目: xds-ide   文件: FormatterPreview.java
private void colorIt() {
     try {
         if (pstToTokenMap == null) {
             initTokenMap();
         }
         // Parse text:
         Document doc = new Document(styledText.getText());
         BuildSettings buildSettings = DefaultBuildSettingsHolder.DefaultBuildSettings;
         ParserCriticalErrorReporter errorReporter = ParserCriticalErrorReporter.getInstance();
IImportResolver defaultImportResolver = new DefaultImportResolver(buildSettings, errorReporter, null);
         XdsParser parser = new XdsParser(null, doc.get(), new XdsSettings(buildSettings, xdsSourceType), defaultImportResolver, errorReporter);
         ModulaAst ast = parser.parseModule();
         leafsNodes = new ArrayList<PstLeafNode>();
         // Fill Leaf array:
         collectLeafs(ast);
         Collections.sort(leafsNodes, new Comparator<PstLeafNode>() {
             public int compare(PstLeafNode a, PstLeafNode b) {
                 return a.getOffset() - b.getOffset();
             }
         });
         // Search matched M2Token for elements in the leaf array and collect style ranges for them:
         ArrayList<StyleRange> asr = new ArrayList<StyleRange>(); 
         for (PstLeafNode pln : leafsNodes) {
             ModulaTokens mt = pstToTokenMap.get(pln.getElementType());
             if (mt == null) {
                 mt = ModulaTokens.Default; 
             }
             int style = mt.getToken().getStyleWhenEnabled();
             StyleRange sr = new StyleRange();
             sr.fontStyle = (style & (SWT.BOLD | SWT.ITALIC));
             sr.underline = (style & TextAttribute.UNDERLINE) != 0;
             sr.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
             sr.foreground = new Color(Display.getDefault(), mt.getToken().getRgbWhenEnabled());
             sr.background = defBackgroundColor;
             sr.start = pln.getOffset();
             sr.length = pln.getLength();
             asr.add(sr);
         }
         if (asr.size() > 0) {
             styledText.setStyleRanges(asr.toArray(new StyleRange[asr.size()]));
         }
     } catch (Exception e) {}
 }
 
源代码17 项目: APICloud-Studio   文件: Theme.java
/**
 * A Java Properties file serialization of this theme.
 * 
 * @return
 */
public Properties toProps()
{
	Properties props = new OrderedProperties();
	props.put(THEME_NAME_PROP_KEY, getName());
	props.put(SELECTION_PROP_KEY, toHex(getSelection()));
	props.put(LINE_HIGHLIGHT_PROP_KEY, toHex(getLineHighlight()));
	props.put(FOREGROUND_PROP_KEY, toHex(getForeground()));
	props.put(BACKGROUND_PROP_KEY, toHex(getBackground()));
	props.put(CARET_PROP_KEY, toHex(caret));
	for (ThemeRule rule : coloringRules)
	{
		if (rule == null)
		{
			continue;
		}
		StringBuilder value = new StringBuilder();
		DelayedTextAttribute attr = rule.getTextAttribute();
		RGBa color = attr.foreground;
		if (color != null)
		{
			value.append(toHex(color)).append(DELIMETER);
		}
		color = attr.background;
		if (color != null)
		{
			value.append(toHex(color)).append(DELIMETER);
		}
		int style = attr.style;
		if ((style & SWT.ITALIC) != 0)
		{
			value.append(ITALIC).append(DELIMETER);
		}
		if ((style & TextAttribute.UNDERLINE) != 0)
		{
			value.append(UNDERLINE).append(DELIMETER);
		}
		if ((style & SWT.BOLD) != 0)
		{
			value.append(BOLD).append(DELIMETER);
		}
		if (value.length() > 0)
		{
			value.deleteCharAt(value.length() - 1);
		}
		// Append the scope selector
		value.append(SELECTOR_DELIMITER);
		value.append(rule.getScopeSelector().toString());
		props.put(rule.getName(), value.toString());
	}
	return props;
}
 
源代码18 项目: APICloud-Studio   文件: ThemeGetTextAttribute.java
@SuppressWarnings("unchecked")
private void initializeScopeToAttribute()
{
	// Some tokens are special. They have fallbacks even if not in the theme! Looks like bundles can contribute
	// them?

	scopeToAttribute = new ImmutableTuple[] {
			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.changed"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(248, 205, 14), SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.deleted"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(255, 86, 77), SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.inserted"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(0, 0, 0), new RGBa(128, 250, 120), SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.underline"), //$NON-NLS-1$
					new DelayedTextAttribute(null, null, TextAttribute.UNDERLINE)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.bold"), //$NON-NLS-1$
					new DelayedTextAttribute(null, null, SWT.BOLD)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("markup.italic"), //$NON-NLS-1$
					new DelayedTextAttribute(null, null, SWT.ITALIC)),

			// note: meta.diff.index, meta.diff.range and meta.separator.diff return the same thing.
			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("meta.diff.index"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(65, 126, 218), SWT.ITALIC)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("meta.diff.range"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(65, 126, 218), SWT.ITALIC)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("meta.separator.diff"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(65, 126, 218), SWT.ITALIC)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("meta.diff.header"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(103, 154, 233), SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("meta.separator"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 255, 255), new RGBa(52, 103, 209), SWT.NORMAL)) };

	scopeToAttributeDark = new ImmutableTuple[] {
			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.error"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 0, 0), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.input"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(95, 175, 176), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.prompt"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(131, 132, 161), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.warning"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 215, 0), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.debug"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 236, 139), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("hyperlink"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(84, 143, 160), null, SWT.NORMAL)) };

	scopeToAttributeLight = new ImmutableTuple[] {
			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.error"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(255, 0, 0), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.input"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(63, 127, 95), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.prompt"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(42, 0, 255), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.warning"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(205, 102, 0), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("console.debug"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(93, 102, 102), null, SWT.NORMAL)),

			new ImmutableTuple<ScopeSelector, DelayedTextAttribute>(new ScopeSelector("hyperlink"), //$NON-NLS-1$
					new DelayedTextAttribute(new RGBa(13, 17, 113), null, SWT.NORMAL)) };
}
 
源代码19 项目: birt   文件: ExpressionSyntaxColoringPage.java
/**
 * Color the text in the sample area according to the current preferences
 */
void applyStyles( )
{
	if ( fText == null || fText.isDisposed( ) )
		return;

	try
	{
		ITypedRegion[] regions = TextUtilities.computePartitioning( fDocument,
				IDocumentExtension3.DEFAULT_PARTITIONING,
				0,
				fDocument.getLength( ),
				true );
		if ( regions.length > 0 )
		{
			for ( int i = 0; i < regions.length; i++ )
			{
				ITypedRegion region = regions[i];
				String namedStyle = (String) fContextToStyleMap.get( region.getType( ) );
				if ( namedStyle == null )
					continue;
				TextAttribute attribute = getAttributeFor( namedStyle );
				if ( attribute == null )
					continue;
				int fontStyle = attribute.getStyle( )
						& ( SWT.ITALIC | SWT.BOLD | SWT.NORMAL );
				StyleRange style = new StyleRange( region.getOffset( ),
						region.getLength( ),
						attribute.getForeground( ),
						attribute.getBackground( ),
						fontStyle );
				style.strikeout = ( attribute.getStyle( ) & TextAttribute.STRIKETHROUGH ) != 0;
				style.underline = ( attribute.getStyle( ) & TextAttribute.UNDERLINE ) != 0;
				style.font = attribute.getFont( );
				fText.setStyleRange( style );
			}
		}
	}
	catch ( BadLocationException e )
	{
		ExceptionHandler.handle( e );
	}
}
 
源代码20 项目: tm4e   文件: TMPresentationReconciler.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
 * @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);
	}
}