Search in sources :

Example 81 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.

the class CustomMessageDialog method setStyle.

private void setStyle() {
    for (HashMap<String, Integer> map : list) {
        StyleRange styleRange = new StyleRange();
        styleRange.start = map.get("start");
        styleRange.length = map.get("length");
        styleRange.fontStyle = SWT.BOLD;
        styleRange.foreground = red;
        text.setStyleRange(styleRange);
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 82 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.

the class HsMultiCellEditor method refreshErrorWordsStyle.

/**
	 * 刷新拼写检查中错误单词的样式
	 * @param ranges
	 */
public void refreshErrorWordsStyle(List<StyleRange> ranges) {
    StyledText styledText = cellEditor.viewer.getTextWidget();
    List<StyleRange> oldRangeList = new ArrayList<StyleRange>();
    for (StyleRange oldRange : styledText.getStyleRanges()) {
        if (oldRange.underlineStyle != SWT.UNDERLINE_ERROR) {
            oldRangeList.add(oldRange);
        }
    }
    styledText.setStyleRange(null);
    styledText.setStyleRanges(oldRangeList.toArray(new StyleRange[oldRangeList.size()]));
    if (ranges != null) {
        for (StyleRange range : ranges) {
            styledText.setStyleRange(range);
        }
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList)

Example 83 with StyleRange

use of org.eclipse.swt.custom.StyleRange 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 84 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.

the class HsMultiCellEditor method getErrorWordRange.

/**
	 * 根据传入的相关参数获取错误单词的样式	robert	2013-01-22
	 * @param style
	 * @param start
	 * @param length
	 * @return
	 */
private StyleRange getErrorWordRange(TextStyle style, int start, int length) {
    StyleRange range = new StyleRange(style);
    range.start = start;
    range.length = length;
    range.underline = true;
    range.underlineStyle = SWT.UNDERLINE_ERROR;
    range.underlineColor = ColorConfigBean.getInstance().getErrorWordColor();
    return range;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 85 with StyleRange

use of org.eclipse.swt.custom.StyleRange 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)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)145 Point (org.eclipse.swt.graphics.Point)52 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)25 Color (org.eclipse.swt.graphics.Color)22 StyledText (org.eclipse.swt.custom.StyledText)13 Font (org.eclipse.swt.graphics.Font)10 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)10 Matcher (java.util.regex.Matcher)9 FontData (org.eclipse.swt.graphics.FontData)8 RGB (org.eclipse.swt.graphics.RGB)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 IOException (java.io.IOException)5 TextPresentation (org.eclipse.jface.text.TextPresentation)5 Image (org.eclipse.swt.graphics.Image)5 Control (org.eclipse.swt.widgets.Control)5 Position (org.eclipse.jface.text.Position)4 TextStyle (org.eclipse.swt.graphics.TextStyle)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3