use of net.sourceforge.nattable.layer.DataLayer in project translationstudio8 by heartsome.
the class HsMultiActiveCellEditor method synchronizeRowHeight.
public static void synchronizeRowHeight() {
if (parent == null || sourceEditor == null || !sourceEditor.isValid() || targetEditor == null || !targetEditor.isValid()) {
return;
}
if (sourceRowIndex != targetRowIndex) {
// 垂直模式
StyledTextCellEditor focusCell = getFocusCellEditor();
if (sourceEditor.getCellEditor() == focusCell) {
// edit source
int srcHeight = sourceEditor.computeSize().y;
int srcColPosition = sourceEditor.getColumnPosition();
int srcRowPosition = sourceEditor.getRowPosition();
int srcRowIndex = sourceEditor.getRowIndex();
Rectangle srcBounds = parent.getBoundsByPosition(srcColPosition, srcRowPosition);
srcHeight += 3;
if (srcBounds != null && srcBounds.height != srcHeight) {
Rectangle srcEditorBounds = sourceEditor.getEditorBounds();
// int preSrcH = srcEditorBounds.height;
srcEditorBounds.height = srcHeight;
int cellStartY = srcBounds.y;
int cellEndY = cellStartY + srcHeight;
Rectangle tgtEditorBounds = targetEditor.getEditorBounds();
int srcAndTgtEndY = cellEndY + tgtEditorBounds.height;
Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
int clientAreaEndY = clientArea.y + clientArea.height;
if (srcAndTgtEndY > clientAreaEndY) {
srcEditorBounds.height = clientAreaEndY - tgtEditorBounds.height - cellStartY - 3;
}
CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
comlayer.doCommand(new TurnViewportOffCommand());
dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(srcRowIndex), srcEditorBounds.height);
comlayer.doCommand(new TurnViewportOnCommand());
// sourceEditor.setEditorBounds(srcEditorBounds, true);
// tgtEditorBounds.y = tgtEditorBounds.y + (srcEditorBounds.height - preSrcH);
// targetEditor.setEditorBounds(tgtEditorBounds, true);
recalculateCellsBounds();
}
} else {
// edit target
int tgtHeight = targetEditor.computeSize().y;
int tgtColPosition = targetEditor.getColumnPosition();
int tgtRowPosition = targetEditor.getRowPosition();
int tgtRowIndex = targetEditor.getRowIndex();
Rectangle bounds = parent.getBoundsByPosition(tgtColPosition, tgtRowPosition);
tgtHeight += 3;
if (bounds != null && bounds.height != tgtHeight) {
Rectangle tgtBounds = targetEditor.getEditorBounds();
tgtBounds.height = tgtHeight;
int cellStartY = tgtBounds.y;
int cellEndY = cellStartY + tgtBounds.height;
Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
int clientAreaEndY = clientArea.y + clientArea.height;
if (cellEndY > clientAreaEndY) {
tgtBounds.height = clientAreaEndY - cellStartY;
}
CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
comlayer.doCommand(new TurnViewportOffCommand());
dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(tgtRowIndex), tgtBounds.height);
comlayer.doCommand(new TurnViewportOnCommand());
// targetEditor.setEditorBounds(tgtBounds, true);
recalculateCellsBounds();
}
}
} else {
// 水平模式
int srcHeight = sourceEditor.computeSize().y;
int tgtHeight = targetEditor.computeSize().y;
int newHeight = srcHeight > tgtHeight ? srcHeight : tgtHeight;
int colPosition = sourceEditor.getColumnPosition();
int rowPosition = sourceEditor.getRowPosition();
int rowIndex = sourceEditor.getRowIndex();
Rectangle bounds = parent.getBoundsByPosition(colPosition, rowPosition);
newHeight += 3;
if (bounds != null && bounds.height == newHeight) {
return;
}
// 加上编辑模式下,StyledTextCellEditor的边框
Rectangle srcBounds = sourceEditor.getEditorBounds();
Rectangle tgtBounds = targetEditor.getEditorBounds();
srcBounds.height = newHeight;
tgtBounds.height = newHeight;
int cellStartY = srcBounds.y;
int cellEndY = cellStartY + srcBounds.height;
Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
int clientAreaEndY = clientArea.y + clientArea.height;
if (cellEndY > clientAreaEndY) {
srcBounds.height = clientAreaEndY - cellStartY;
tgtBounds.height = srcBounds.height;
}
CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
comlayer.doCommand(new TurnViewportOffCommand());
dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(rowIndex), tgtBounds.height);
comlayer.doCommand(new TurnViewportOnCommand());
// HorizontalViewportLayer viewLayer = LayerUtil.getLayer(parent, HorizontalViewportLayer.class);
// int newRowPosition = viewLayer.getRowPositionByIndex(rowIndex) + 1;
// if (newRowPosition != rowPosition) {
// sourceEditor.setRowPosition(newRowPosition);
// targetEditor.setRowPosition(newRowPosition);
// Rectangle newSrcBounds = parent.getBoundsByPosition(colPosition, newRowPosition);
// newSrcBounds.height = srcBounds.height;
// Rectangle newTgtBounds = parent.getBoundsByPosition(targetEditor.getColumnIndex(), newRowPosition);
// sourceEditor.setEditorBounds(newSrcBounds, true);
// targetEditor.setEditorBounds(newTgtBounds, true);
// } else {
// sourceEditor.setEditorBounds(srcBounds, true);
// targetEditor.setEditorBounds(tgtBounds, true);
recalculateCellsBounds();
// }
}
}
use of net.sourceforge.nattable.layer.DataLayer in project translationstudio8 by heartsome.
the class HsMultiCellEditorHandler method commit.
/**
* Just commit the data, will not close the editor control
* @see net.sourceforge.nattable.edit.ICellEditHandler#commit(net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum, boolean)
*/
public boolean commit(MoveDirectionEnum direction, boolean closeEditorAfterCommit) {
switch(direction) {
case LEFT:
layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.LEFT, 1, false, false));
break;
case RIGHT:
layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.RIGHT, 1, false, false));
break;
}
if (cellEditor.isEditable()) {
Object canonicalValue = cellEditor.getCanonicalValue();
DataLayer datalayer = LayerUtil.getLayer((CompositeLayer) layer, DataLayer.class);
datalayer.doCommand(new UpdateDataAndAutoResizeCommand(layer, cellEditor.getColumnIndex(), cellEditor.getRowIndex(), canonicalValue));
// layer.doCommand(new UpdateDataCommand(layer, cellEditor.getColumnPosition(), cellEditor.getRowPosition(), canonicalValue));
}
return true;
}
use of net.sourceforge.nattable.layer.DataLayer 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.sourceforge.nattable.layer.DataLayer in project translationstudio8 by heartsome.
the class TagDisplayConverter method canonicalToDisplayValue.
/**
* (non-Javadoc)
* @see net.sourceforge.nattable.data.convert.DefaultDisplayConverter#canonicalToDisplayValue(java.lang.Object)
*/
public Object canonicalToDisplayValue(Object xmlValue) {
if (xmlValue == null || xmlValue.toString().length() == 0) {
return "";
}
String originalValue = xmlValue.toString();
TagStyle tagStyle = xliffEditor.getTagStyleManager().getTagStyle();
// if (TagStyle.FULL.equals(tagStyle)) {
// return originalValue;
// } else {
StringBuffer displayValue = new StringBuffer(originalValue);
int columnIndex = table.getColumnIndexByPosition(currentCell.getColumnPosition());
if (xliffEditor.isHorizontalLayout()) {
if (columnIndex == xliffEditor.getSrcColumnIndex()) {
// 设置内部标记索引及样式
InnerTagUtil.parseXmlToDisplayValue(displayValue, tagStyle);
} else if (columnIndex == xliffEditor.getTgtColumnIndex()) {
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();
InnerTagUtil.parseXmlToDisplayValueFromSource(srcOriginalValue, displayValue, tagStyle);
} else {
// 设置内部标记索引及样式
InnerTagUtil.parseXmlToDisplayValue(displayValue, tagStyle);
}
// 恢复初始值
currentCell = null;
} else {
// do nothing
}
} else {
int rowIndex = currentCell.getLayer().getRowIndexByPosition(currentCell.getRowPosition());
if (columnIndex == xliffEditor.getSrcColumnIndex() && rowIndex % 2 == 0) {
//源语言
// 设置内部标记索引及样式
InnerTagUtil.parseXmlToDisplayValue(displayValue, tagStyle);
} else if (columnIndex == xliffEditor.getTgtColumnIndex()) {
//目标语言
int srcColumnPosition = LayerUtil.getColumnPositionByIndex(table, xliffEditor.getSrcColumnIndex());
if (srcColumnPosition != -1) {
// 得到Source列的位置
// DataLayer dataLayer = LayerUtil.getLayer(table, DataLayer.class);
String srcOriginalValue = table.getDataValueByPosition(srcColumnPosition, rowIndex - 1).toString();
InnerTagUtil.parseXmlToDisplayValueFromSource(srcOriginalValue, displayValue, tagStyle);
} else {
// 设置内部标记索引及样式
InnerTagUtil.parseXmlToDisplayValue(displayValue, tagStyle);
}
// 恢复初始值
currentCell = null;
} else {
// do nothing
}
}
return InnerTagUtil.resolveTag(displayValue.toString());
// }
}
Aggregations