Search in sources :

Example 21 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project translationstudio8 by heartsome.

the class HsMultiCellEditor method highLightedErrorWord.

/**
	 * 实时拼检查时高亮错误单词	robert	2013-01-21
	 * @param terms
	 */
public void highLightedErrorWord(String tgtText, List<SingleWord> errorWordList) {
    if (!isValid()) {
        return;
    }
    List<StyleRange> ranges = new ArrayList<StyleRange>();
    TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null, null);
    for (SingleWord singleWord : errorWordList) {
        Matcher match = PlaceHolderEditModeBuilder.PATTERN.matcher(singleWord.getWord());
        // 这里是处理一个单词中有一个或多个标记,从而导致标记绘画失败的BUG,如果其中有标记,那么这个 StyleRange 就应该被切断
        boolean hasTag = false;
        int index = 0;
        while (match.find()) {
            StyleRange range = getErrorWordRange(style, singleWord.getStart() + index, match.start() - index);
            ranges.add(range);
            index = match.end();
            hasTag = true;
        }
        if (hasTag) {
            if (index < singleWord.getLength()) {
                StyleRange range = getErrorWordRange(style, singleWord.getStart() + index, singleWord.getLength() - index);
                ranges.add(range);
            }
        } else {
            ranges.add(getErrorWordRange(style, singleWord.getStart(), singleWord.getLength()));
        }
    }
    refreshErrorWordsStyle(ranges);
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Matcher(java.util.regex.Matcher) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList) SingleWord(net.heartsome.cat.ts.core.bean.SingleWord) Point(org.eclipse.swt.graphics.Point)

Example 22 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project translationstudio8 by heartsome.

the class HsMultiCellEditor method highlightedTerms.

public void highlightedTerms(List<String> terms) {
    if (!isValid()) {
        return;
    }
    StyledText styledText = cellEditor.viewer.getTextWidget();
    String text = styledText.getText();
    char[] source = text.toCharArray();
    List<StyleRange> ranges = new ArrayList<StyleRange>();
    TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null, ColorConfigBean.getInstance().getHighlightedTermColor());
    for (String term : terms) {
        if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
            term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
            term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
            term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
        }
        ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
    }
    for (StyleRange range : ranges) {
        styledText.setStyleRange(range);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) TextStyle(org.eclipse.swt.graphics.TextStyle) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList)

Example 23 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentAssistProcessor method getTemplateLabel.

protected StyledString getTemplateLabel(Template template) {
    Styler nameStyle = new StyledString.Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.foreground = new Color(Display.getCurrent(), new RGB(80, 80, 255));
        }
    };
    Styler descriptionStyle = new StyledString.Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.foreground = new Color(Display.getCurrent(), new RGB(120, 120, 120));
        }
    };
    return new StyledString(template.getName(), nameStyle).append(": ", descriptionStyle).append(template.getDescription(), descriptionStyle);
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Color(org.eclipse.swt.graphics.Color) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) RGB(org.eclipse.swt.graphics.RGB)

Example 24 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project eclipse.platform.text by eclipse.

the class BrowserInformationControl method createTextLayout.

/**
 * Creates and initializes the text layout used
 * to compute the size hint.
 *
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fBrowser.getDisplay());
    // Initialize fonts
    String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
    Font font = JFaceResources.getFont(symbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
    fBoldStyle = new TextStyle(font, null, null);
    // Compute and set tab width
    // $NON-NLS-1$
    fTextLayout.setText("    ");
    int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });
    // $NON-NLS-1$
    fTextLayout.setText("");
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 25 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project yamcs-studio by yamcs.

the class RCPSSTextLayout method addStyle.

/**
 * {@inheritDoc}
 */
@Override
public void addStyle(Font font, Color color, int x, int y) {
    TextStyle textStyle = new TextStyle(font, color, null);
    textLayout.setStyle(textStyle, x, y);
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle)

Aggregations

TextStyle (org.eclipse.swt.graphics.TextStyle)25 Point (org.eclipse.swt.graphics.Point)12 TextLayout (org.eclipse.swt.graphics.TextLayout)10 Color (org.eclipse.swt.graphics.Color)7 Font (org.eclipse.swt.graphics.Font)7 Rectangle (org.eclipse.swt.graphics.Rectangle)7 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 StyleRange (org.eclipse.swt.custom.StyleRange)5 IToken (org.eclipse.jface.text.rules.IToken)4 RGB (org.eclipse.swt.graphics.RGB)4 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)3 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)3 List (java.util.List)2 Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 ITokenScanner (org.eclipse.jface.text.rules.ITokenScanner)2 Styler (org.eclipse.jface.viewers.StyledString.Styler)2 GridItem (org.eclipse.nebula.widgets.grid.GridItem)2 StyledText (org.eclipse.swt.custom.StyledText)2