use of net.heartsome.cat.ts.core.bean.SingleWord in project translationstudio8 by heartsome.
the class HsMultiCellEditorControl method tgtTextFirstRealTimeSpellCheck.
/**
* 当一个文本段初次获取焦点时,实时进行拼写检查,<div style='color:red'>该方法与{@link tgtTextRealTimeSpellCheck} 类似</div>
*/
private static void tgtTextFirstRealTimeSpellCheck(final String tgtLang, HsMultiCellEditor targetEditor) {
final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
if (tgtLang == null) {
return;
}
String tgtText = text.getText();
if (tgtText == null || "".equals(tgtText.trim())) {
return;
}
List<SingleWord> errorWordList = new LinkedList<SingleWord>();
errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
if (errorWordList != null && errorWordList.size() > 0) {
targetEditor.highLightedErrorWord(tgtText, errorWordList);
} else {
targetEditor.refreshErrorWordsStyle(null);
}
}
use of net.heartsome.cat.ts.core.bean.SingleWord 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);
}
Aggregations