Search in sources :

Example 6 with XliffInnerTagFactory

use of net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory in project translationstudio8 by heartsome.

the class SegmentViewer method setText.

/**
	 * @see net.heartsome.cat.ts.ui.innertag.ISegmentViewer#setText(java.lang.String)
	 */
public void setText(String text) {
    // 重置缓存的标记。
    reset();
    if (isSource()) {
        // 当前是源文本
        IInnerTagFactory innerTagFactory = new XliffInnerTagFactory(text, placeHolderBuilder);
        List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
        for (InnerTagBean innerTagBean : innerTagBeans) {
            InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
            innerTag.setVisible(false);
            innerTagCacheList.add(innerTag);
            sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
        }
        // 记录错误标记的起始,source 中所有标记都不是错误标记。
        errorTagStart = innerTagCacheList.size();
        text = innerTagFactory.getText();
    } else {
        // 当前是目标文本
        XliffInnerTagFactory innerTagFactory = new XliffInnerTagFactory(source, placeHolderBuilder);
        // source 中包含的内部标记。
        List<InnerTagBean> sourceInnerTagBeans = innerTagFactory.getInnerTagBeans();
        // 记录错误标记的起始,source 中所有标记都不是错误标记。
        errorTagStart = sourceInnerTagBeans.size();
        // 如果当前是 Target,就先记录 Source 中的最大索引。
        for (InnerTagBean innerTagBean : sourceInnerTagBeans) {
            // 记录source中内部标记的最大标记索引。
            sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
        }
        text = innerTagFactory.parseInnerTag(text, true);
        List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
        for (InnerTagBean innerTagBean : innerTagBeans) {
            InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
            innerTag.setVisible(false);
            innerTagCacheList.add(innerTag);
        }
    }
    getTextWidget().setText(resetRegularString(text));
}
Also used : XliffInnerTagFactory(net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory) InnerTag(net.heartsome.cat.common.ui.innertag.InnerTag) IInnerTagFactory(net.heartsome.cat.common.innertag.factory.IInnerTagFactory) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean)

Aggregations

XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)6 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)5 IInnerTagFactory (net.heartsome.cat.common.innertag.factory.IInnerTagFactory)3 TreeMap (java.util.TreeMap)2 Point (org.eclipse.swt.graphics.Point)2 TextLayout (org.eclipse.swt.graphics.TextLayout)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PlaceHolderEditModeBuilder (net.heartsome.cat.common.innertag.factory.PlaceHolderEditModeBuilder)1 InnerTag (net.heartsome.cat.common.ui.innertag.InnerTag)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 IStyle (net.sourceforge.nattable.style.IStyle)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 TextStyle (org.eclipse.swt.graphics.TextStyle)1