Java Code Examples for org.eclipse.jface.text.TextAttribute#UNDERLINE

The following examples show how to use org.eclipse.jface.text.TextAttribute#UNDERLINE . 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: NonRuleBasedDamagerRepairer.java    From birt with Eclipse Public License 1.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
 */
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 );
	}
}
 
Example 2
Source File: AbstractEditorConfigScanner.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
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 4
Source File: JsonScanner.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: TextAttributeFactory.java    From LogViewer with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 6
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 7
Source File: SemanticHighlightingManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 8
Source File: SemanticHighlightingManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 9
Source File: ThemeingDamagerRepairer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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());
	}
}
 
Example 11
Source File: CSSTokenProvider.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
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();
	}
}
 
Example 12
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);
    }
}
 
Example 13
Source File: XStyledString.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 14
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 15
Source File: StylerFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example 16
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: ExpressionSyntaxColoringPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 );
	}
}
 
Example 18
Source File: ThemeGetTextAttribute.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@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)) };
}
 
Example 19
Source File: FormatterPreview.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
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) {}
 }
 
Example 20
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 3 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 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);
	}
}