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

下面列出了org.eclipse.jface.text.TextAttribute#STRIKETHROUGH 实例代码,或者点击链接到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);
    }
}
 
/**
 * 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
 * @since 3.0
 */
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);
}
 
/**
 * 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 项目: 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;
}
 
源代码10 项目: 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());
	}
}
 
源代码11 项目: 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);
	}
}
 
源代码14 项目: 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);
    }
}
 
源代码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 项目: 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 );
	}
}
 
源代码18 项目: 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);
	}
}
 
源代码19 项目: dsl-devkit   文件: AbstractSyntaxColoringTest.java
/**
 * Creates a {@link StyleRange} from the given parameters.
 *
 * @param offset
 *          the offset
 * @param length
 *          the length of the range
 * @param textAttribute
 *          the {@link TextAttribute}
 * @return a {@link StyleRange} from the given parameters
 */
public static StyleRange createStyleRange(final int offset, final int length, final TextAttribute textAttribute) {
  int style = textAttribute.getStyle();
  int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
  StyleRange styleRange = new StyleRange(offset, length, textAttribute.getForeground(), textAttribute.getBackground(), fontStyle);
  styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
  styleRange.underline = (style & TextAttribute.UNDERLINE) != 0;
  styleRange.font = textAttribute.getFont();
  return styleRange;
}