Search in sources :

Example 6 with SingleWord

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);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) SingleWord(net.heartsome.cat.ts.core.bean.SingleWord) LinkedList(java.util.LinkedList)

Example 7 with SingleWord

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

Aggregations

SingleWord (net.heartsome.cat.ts.core.bean.SingleWord)7 LinkedList (java.util.LinkedList)3 StringTokenizer (java.util.StringTokenizer)3 StyledText (org.eclipse.swt.custom.StyledText)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 QAResultBean (net.heartsome.cat.ts.ui.qa.model.QAResultBean)1 NonTransElementOperate (net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate)1 AspellChecker (net.heartsome.cat.ts.ui.qa.spell.AspellChecker)1 Hunspell (net.heartsome.cat.ts.ui.qa.spell.Hunspell)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 Point (org.eclipse.swt.graphics.Point)1 TextStyle (org.eclipse.swt.graphics.TextStyle)1