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();
}
});
}
}
Aggregations