Search in sources :

Example 1 with ColorConfigBean

use of net.heartsome.cat.common.bean.ColorConfigBean in project translationstudio8 by heartsome.

the class Comparator method Compare.

/**
	 * 用于比较的参照文本(不含内部标记)
	 * @param referenceText
	 * @param text
	 *            ;
	 */
public static void Compare(String referenceText, StyledText text) {
    ColorConfigBean colorCfgBean = ColorConfigBean.getInstance();
    final Color differencefg = colorCfgBean.getSrcDiffFgColor();
    final Color differencebg = colorCfgBean.getSrcDiffBgColor();
    Position[] tagRanges = InnerTagUtil.getStyledTagRanges(text.getText());
    TokenComparator left = new TokenComparator(InnerTagUtil.getDisplayValueWithoutTags(text.getText()));
    TokenComparator right = new TokenComparator(referenceText);
    ArrayList<StyleRange> styleRanges = new ArrayList<StyleRange>();
    RangeDifference[] e = RangeDifferencer.findRanges(left, right);
    for (int i = 0; i < e.length; i++) {
        RangeDifference es = e[i];
        int leftStart = es.leftStart();
        int leftEnd = es.leftEnd();
        int lStart = left.getTokenStart(leftStart);
        int lEnd = left.getTokenStart(leftEnd);
        if (es.kind() == RangeDifference.CHANGE) {
            int start = lStart;
            int end = lEnd;
            if (tagRanges.length > 0) {
                for (Position tagRange : tagRanges) {
                    int tagStart = tagRange.getOffset();
                    int tagEnd = tagRange.getOffset() + tagRange.getLength();
                    if (tagStart <= start) {
                        start += tagRange.getLength();
                        end += tagRange.getLength();
                    } else if (start < tagStart && tagStart < end) {
                        StyleRange range = new StyleRange(start, tagStart - start, differencefg, differencebg);
                        styleRanges.add(range);
                        start = tagEnd;
                        end += tagRange.getLength();
                    } else {
                        break;
                    }
                }
            }
            StyleRange range = new StyleRange(start, end - start, differencefg, differencebg);
            styleRanges.add(range);
        }
    }
    for (int i = 0; i < styleRanges.size(); i++) {
        text.setStyleRange(styleRanges.get(i));
        text.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                differencefg.dispose();
                differencebg.dispose();
            }
        });
    }
}
Also used : ColorConfigBean(net.heartsome.cat.common.bean.ColorConfigBean) DisposeListener(org.eclipse.swt.events.DisposeListener) Position(org.eclipse.jface.text.Position) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList) DisposeEvent(org.eclipse.swt.events.DisposeEvent) RangeDifference(org.eclipse.compare.rangedifferencer.RangeDifference)

Aggregations

ArrayList (java.util.ArrayList)1 ColorConfigBean (net.heartsome.cat.common.bean.ColorConfigBean)1 RangeDifference (org.eclipse.compare.rangedifferencer.RangeDifference)1 Position (org.eclipse.jface.text.Position)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 Color (org.eclipse.swt.graphics.Color)1