Search in sources :

Example 16 with InnerTagBean

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

the class XGridCellRenderer method drawInnerTag.

protected void drawInnerTag(GC gc, TextLayout layout) {
    String displayStr = layout.getText();
    List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
    Rectangle bounds = getBounds();
    for (InnerTagBean innerTagBean : innerTagBeans) {
        String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
        int start = displayStr.indexOf(placeHolder);
        if (start == -1) {
            continue;
        }
        if (gc != null) {
            Point p = layout.getLocation(start, false);
            int x = bounds.x + p.x + leftMargin;
            x += SEGMENT_LINE_SPACING;
            Point tagSize = tagRender.calculateTagSize(innerTagBean);
            int lineIdx = layout.getLineIndex(start);
            Rectangle r = layout.getLineBounds(lineIdx);
            int y = bounds.y + p.y + topMargin + r.height / 2 - tagSize.y / 2;
            tagRender.draw(gc, innerTagBean, x, y - layout.getAscent());
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 17 with InnerTagBean

use of net.heartsome.cat.common.innertag.InnerTagBean 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)

Example 18 with InnerTagBean

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

the class IntelligentTagPrcessor method processNextStandloneTag.

private static StringBuilder processNextStandloneTag(String srcFullText, List<InnerTagBean> srcTags, int startTagsOffset) {
    StringBuilder sb = new StringBuilder();
    if (startTagsOffset >= srcTags.size()) {
        return sb;
    }
    String firstTagCnt = srcTags.get(startTagsOffset).getContent();
    int i = startTagsOffset + 1;
    int offset = srcFullText.indexOf(firstTagCnt) + firstTagCnt.length();
    while (i < srcTags.size()) {
        InnerTagBean nextTag = srcTags.get(i);
        String nextTagCnt = nextTag.getContent();
        if (nextTag.getType() == TagType.STANDALONE && srcFullText.indexOf(nextTagCnt) == offset) {
            sb.append(nextTagCnt);
            offset += nextTagCnt.length();
            i++;
        } else {
            break;
        }
    }
    return sb;
}
Also used : InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean)

Example 19 with InnerTagBean

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

the class IntelligentTagPrcessor method processPreStandloneTag.

private static StringBuilder processPreStandloneTag(String targetText, String srcFullText, List<InnerTagBean> srcTags, int startTagsOffset) {
    StringBuilder sb = new StringBuilder();
    if (startTagsOffset >= srcTags.size()) {
        return sb;
    }
    String lastTagCnt = srcTags.get(startTagsOffset).getContent();
    int i = startTagsOffset - 1;
    int offset = srcFullText.lastIndexOf(lastTagCnt);
    while (i >= 0) {
        InnerTagBean preTag = srcTags.get(i);
        String preTagCnt = preTag.getContent();
        if (preTag.getType() == TagType.STANDALONE && targetText.indexOf(preTagCnt) == -1 && srcFullText.lastIndexOf(preTagCnt) + preTagCnt.length() == offset) {
            sb.insert(0, preTagCnt);
            offset = srcFullText.lastIndexOf(preTagCnt);
            i--;
        } else {
            break;
        }
    }
    return sb;
}
Also used : InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean)

Aggregations

InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)19 Point (org.eclipse.swt.graphics.Point)7 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)5 ArrayList (java.util.ArrayList)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 SQLException (java.sql.SQLException)3 IInnerTagFactory (net.heartsome.cat.common.innertag.factory.IInnerTagFactory)3 TextStyle (org.eclipse.swt.graphics.TextStyle)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 TreeMap (java.util.TreeMap)2 MetaData (net.heartsome.cat.common.bean.MetaData)2 InnerTag (net.heartsome.cat.common.ui.innertag.InnerTag)2 DBOperator (net.heartsome.cat.database.DBOperator)2 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)2 TextLayout (org.eclipse.swt.graphics.TextLayout)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 IRow (de.jaret.util.ui.table.model.IRow)1 List (java.util.List)1 Entry (java.util.Map.Entry)1