use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method initGroupIdAndSearch.
public void initGroupIdAndSearch() {
updateHistory(cmbSearch, lstSearchHistory);
updateHistory(cmbFilter, lstFilterHistory);
String searchText = cmbSearch.getText();
if (searchText == null || searchText.trim().equals("")) {
txtPage.setText("");
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ConcordanceSearchDialog.msgTitle"), Messages.getString("dialog.ConcordanceSearchDialog.msg2"));
return;
}
StringBuffer searchTextBf = new StringBuffer(searchText);
TreeMap<String, InnerTagBean> tags = InnerTagUtil.parseXmlToDisplayValue(searchTextBf, TagStyle.getDefault(false));
searchText = InnerTagUtil.resolveTag(searchTextBf.toString());
searchText = InnerTagUtil.escapeTag(searchText);
searchText = InnerTagUtil.parseDisplayToXmlValue(tags, searchText);
clearTable();
mapGroupId.clear();
curPageNum = 1;
String[] arrFilter = null;
String strFilter = cmbFilter.getText();
if (cmpExpandableFilter.isExpanded() && strFilter != null && !strFilter.equals("")) {
String srcOrTgt = (String) cmbSrcOrTgt.getData(cmbSrcOrTgt.getText());
String contain = (String) cmbContain.getData(cmbContain.getText());
arrFilter = new String[] { srcOrTgt, contain, strFilter };
}
ArrayList<String> lstSelLangs = new ArrayList<String>();
for (MenuItem item : menu.getItems()) {
if (item.getSelection()) {
lstSelLangs.add(item.getText());
}
}
List<MetaData> lstMetaData = new ArrayList<MetaData>();
if (cmbDatabase.getSelectionIndex() == 0) {
for (DatabaseModelBean model : lstDatabase) {
lstMetaData.add(model.toDbMetaData());
}
} else {
DatabaseModelBean model = lstDatabase.get(cmbDatabase.getSelectionIndex() - 1);
MetaData metaData = model.toDbMetaData();
lstMetaData.add(metaData);
}
size = 0;
for (MetaData metaData : lstMetaData) {
DBOperator dbOp = DatabaseService.getDBOperator(metaData);
if (null == dbOp) {
continue;
}
try {
dbOp.start();
ArrayList<Integer> lstGroupId = dbOp.getConcordanceGroupId(searchText, btnIsCaseSensitive.getSelection(), btnApplyRegularExpression.getSelection(), btnIsIgnoreMark.getSelection(), strSrcLang, arrFilter, lstSelLangs);
if (lstGroupId.size() != 0) {
mapGroupId.put(metaData, lstGroupId);
}
size += lstGroupId.size();
} catch (SQLException e1) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger2"), e1);
} catch (ClassNotFoundException e1) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger3"), e1);
} finally {
try {
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
if (size == 0) {
clearTable();
txtPage.setText("");
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ConcordanceSearchDialog.msgTitle"), Messages.getString("dialog.ConcordanceSearchDialog.msg1"));
return;
}
amountPage = size / rowNumPerPage;
if (size % rowNumPerPage != 0) {
amountPage += 1;
}
if (search()) {
refreshPageNumText();
}
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class XliffInnerTagFactory method parseInnerTag.
public String parseInnerTag(String xml, boolean isEditMode) {
if (xml == null || xml.length() == 0) {
return "";
}
if (!indexStack.empty()) {
indexStack.clear();
}
StringBuffer sbOriginalValue = new StringBuffer(xml);
int beanSize = beans.size();
// 起始索引
this.start = -1;
if (beans.size() > 0) {
targetFlg = true;
int index = -1;
for (int i = 0; i < beans.size(); i++) {
InnerTagBean bean = beans.get(i);
if (bean.getType() != TagType.STANDALONE) {
continue;
}
String content = bean.getContent();
index = sbOriginalValue.indexOf(content);
if (index > -1 && (isEditMode || TagStyle.curStyle != TagStyle.FULL)) {
String placeHolder = placeHolderCreater.getPlaceHolder(beans, i);
if (sbOriginalValue.indexOf(placeHolder) != -1) {
// 已经存在,说明这个标记在译文中是重复的。
continue;
}
sbOriginalValue.replace(index, index + content.length(), placeHolder);
} else if (TagStyle.curStyle == TagStyle.FULL) {
this.start = index + content.length();
}
}
beanSize = beans.size();
} else {
beanSize = -1;
}
while ((start = sbOriginalValue.indexOf("<", start + 1)) > -1) {
int end = sbOriginalValue.indexOf(">", start + 1);
if (end > -1) {
// 提取出的内部标记xml形式的文本
String xmlTag = sbOriginalValue.substring(start, end + 1);
String tagName = getTagName(xmlTag);
sbOriginalValue.replace(start, end + 1, xmlTag);
if (xmlTag.indexOf("/>", 1) > -1) {
// 独立标签
if (standaloneTags.contains(tagName) || normalTags.contains(tagName)) {
if ("bx".equals(tagName)) {
addInnerTagBean(START, sbOriginalValue, xmlTag, tagName);
} else if ("ex".equals(tagName)) {
addInnerTagBean(END, sbOriginalValue, xmlTag, tagName);
} else {
addInnerTagBean(STANDALONE, sbOriginalValue, xmlTag, tagName);
}
}
} else if (xmlTag.indexOf("</") > -1) {
// 结束标签
if (normalTags.contains(tagName)) {
addInnerTagBean(END, sbOriginalValue, xmlTag, tagName);
}
} else if (xmlTag.indexOf(">") > -1) {
// 开始标签
if (normalTags.contains(tagName)) {
if ("bpt".equals(tagName)) {
int endIndex = sbOriginalValue.indexOf("</bpt>", start) + "</bpt>".length();
xmlTag = sbOriginalValue.substring(start, endIndex);
sbOriginalValue.replace(start, endIndex, xmlTag);
addInnerTagBean(START, sbOriginalValue, xmlTag, tagName);
} else if ("ept".equals(tagName)) {
int endIndex = sbOriginalValue.indexOf("</ept>", start) + "</ept>".length();
xmlTag = sbOriginalValue.substring(start, endIndex);
sbOriginalValue.replace(start, endIndex, xmlTag);
addInnerTagBean(END, sbOriginalValue, xmlTag, tagName);
} else if ("ph".equals(tagName) || "it".equals(tagName)) {
String tempTagName = "</" + tagName + ">";
int endIndex = sbOriginalValue.indexOf(tempTagName, start) + tempTagName.length();
xmlTag = sbOriginalValue.substring(start, endIndex);
sbOriginalValue.replace(start, endIndex, xmlTag);
addInnerTagBean(STANDALONE, sbOriginalValue, xmlTag, tagName);
} else {
addInnerTagBean(START, sbOriginalValue, xmlTag, tagName);
}
}
}
}
}
if (beanSize > 0) {
// 设置为错误标记
for (int i = beanSize; i < beans.size(); i++) {
beans.get(i).setWrongTag(true);
}
}
targetFlg = false;
return sbOriginalValue.toString();
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class TagDisplayConverter method displayToCanonicalValue.
/**
* (non-Javadoc)
* @see net.sourceforge.nattable.data.convert.DefaultDisplayConverter#displayToCanonicalValue(java.lang.Object)
*/
public Object displayToCanonicalValue(Object tagValue) {
String displayValue = tagValue == null ? "" : tagValue.toString();
String content = InnerTagUtil.escapeTag(displayValue);
int rowIndex = currentCell.getLayer().getRowIndexByPosition(currentCell.getRowPosition());
int srcColumnPosition = LayerUtil.getColumnPositionByIndex(table, xliffEditor.getSrcColumnIndex());
if (srcColumnPosition != -1) {
// 得到Source列的位置
DataLayer dataLayer = LayerUtil.getLayer(table, DataLayer.class);
String srcOriginalValue = dataLayer.getDataValueByPosition(srcColumnPosition, rowIndex).toString();
TreeMap<String, InnerTagBean> sourceTags = InnerTagUtil.parseXmlToDisplayValue(new StringBuffer(srcOriginalValue), xliffEditor.getTagStyleManager().getTagStyle());
// 换回xml格式的内容
return InnerTagUtil.parseDisplayToXmlValue(sourceTags, content);
} else {
// 设置内部标记索引及样式
return content;
}
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class TextPainterWithPadding method paintCell.
/**
* (non-Javadoc)
* @see net.sourceforge.nattable.painter.cell.BackgroundPainter#paintCell(net.sourceforge.nattable.layer.cell.LayerCell,
* org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle,
* net.sourceforge.nattable.config.IConfigRegistry)
*/
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
super.paintCell(cell, gc, rectangle, configRegistry);
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
if (innerTagFactory == null) {
innerTagFactory = new XliffInnerTagFactory(placeHolderBuilder);
}
innerTagFactory.reset();
int rowIndex = cell.getLayer().getRowIndexByPosition(cell.getRowPosition());
int columnIndex = cell.getLayer().getColumnIndexByPosition(cell.getColumnPosition());
if (!editor.isHorizontalLayout()) {
// 垂直
if (rowIndex % 2 != 0) {
LayerCell srcCell = cell.getLayer().getCellByPosition(cell.getColumnPosition(), cell.getRowPosition() - 1);
if (srcCell != null) {
String sourceVal = (String) srcCell.getDataValue();
innerTagFactory.parseInnerTag(sourceVal);
}
}
} else {
// 水平
if (columnIndex == editor.getTgtColumnIndex()) {
LayerCell srcCell = cell.getLayer().getCellByPosition(1, cell.getRowPosition());
if (srcCell != null) {
String sourceVal = (String) srcCell.getDataValue();
innerTagFactory.parseInnerTag(sourceVal);
}
}
}
TextLayout layout = getCellTextLayout(cell);
int tempIndx = rowIndex;
if (!editor.isHorizontalLayout()) {
tempIndx = tempIndx / 2;
}
if (tempIndx == editor.getSelectedRows()[0] && (editor.isHorizontalLayout() ? columnIndex == editor.getSrcColumnIndex() : rowIndex % 2 == 0)) {
List<String> terms = editor.getTermsCache().get(tempIndx);
if (terms != null && terms.size() > 0) {
List<StyleRange> ranges = new ArrayList<StyleRange>();
TextStyle style = new TextStyle(getFont(), null, ColorConfigBean.getInstance().getHighlightedTermColor());
char[] source = layout.getText().toCharArray();
for (String term : terms) {
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "");
term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
}
for (StyleRange range : ranges) {
layout.setStyle(range, range.start, range.start + range.length - 1);
}
}
}
try {
String displayText = layout.getText();
Rectangle bounds = cell.getBounds();
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
appendNonprintingStyle(layout);
}
layout.draw(gc, bounds.x + leftPadding, bounds.y + topPadding);
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
for (InnerTagBean innerTagBean : innerTagBeans) {
String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
int start = displayText.indexOf(placeHolder);
if (start == -1) {
continue;
}
Point p = layout.getLocation(start, false);
int x = bounds.x + p.x + leftPadding;
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 + topPadding + r.height / 2 - tagSize.y / 2;
// layout.getLineMetrics(0).getDescent();
// if (y + r.height > tagSize.y) {
// FontMetrics fm = layout.getLineMetrics(lineIdx);
// y = y + r.height - tagSize.y - fm.getDescent();
// }
tagRender.draw(gc, innerTagBean, x, y);
}
} finally {
layout.dispose();
}
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class XGridCellRenderer method attachInnertTagStyle.
protected void attachInnertTagStyle(GC gc, TextLayout layout, boolean drawInnerTag) {
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;
}
TextStyle style = new TextStyle();
Point rect = tagRender.calculateTagSize(innerTagBean);
style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
layout.setStyle(style, start, start + placeHolder.length() - 1);
if (drawInnerTag && 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());
}
}
}
Aggregations