use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class SelectionLayerPainter method paintLayer.
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
columnPositionOffset = positionRectangle.x;
rowPositionOffset = positionRectangle.y;
cells = new HashMap<PositionCoordinate, LayerCell>();
super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
// Save gc settings
int originalLineStyle = gc.getLineStyle();
Color originalForeground = gc.getForeground();
// Apply border settings
gc.setLineStyle(SWT.LINE_CUSTOM);
gc.setLineDash(new int[] { 1, 1 });
gc.setForeground(GUIHelper.COLOR_BLACK);
// Draw horizontal borders
boolean selectedMode = false;
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
LayerCell cell = null;
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
if (cell != null) {
if (selectedMode != isSelected(cell)) {
selectedMode = !selectedMode;
Rectangle cellBounds = cell.getBounds();
// Draw top edge
gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y - 1);
}
}
}
if (selectedMode && cell != null) {
// If last cell is selected, draw its bottom edge
Rectangle cellBounds = cell.getBounds();
gc.drawLine(cellBounds.x - 1, cellBounds.y + cellBounds.height - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
}
selectedMode = false;
}
// Draw vertical borders
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
LayerCell cell = null;
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
if (cell != null) {
if (selectedMode != isSelected(cell)) {
selectedMode = !selectedMode;
Rectangle cellBounds = cell.getBounds();
// Draw left edge
gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x - 1, cellBounds.y + cellBounds.height - 1);
}
}
}
if (selectedMode && cell != null) {
// If last cell is selected, draw its right edge
Rectangle cellBounds = cell.getBounds();
gc.drawLine(cellBounds.x + cellBounds.width - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
}
selectedMode = false;
}
// Restore original gc settings
gc.setLineStyle(originalLineStyle);
gc.setForeground(originalForeground);
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class FindReplaceDialog method doFindNext.
/**
* 查找下一个 ;
* @return
*/
private boolean doFindNext() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return false;
}
int[] selectedRows = editor.getSelectedRows();
int startingRowPosition;
if (selectedRows.length > 0) {
Arrays.sort(selectedRows);
if (forwardButton.getSelection()) {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[selectedRows.length - 1];
} else {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[0];
}
if (!editor.isHorizontalLayout()) {
startingRowPosition *= VerticalNatTableConfig.ROW_SPAN;
if (!sourceButton.getSelection()) {
startingRowPosition++;
}
}
int startOffset;
CellRegion cellRegion = ActiveCellRegion.getActiveCellRegion();
if (cellRegion == null || cellRegion.getPositionCoordinate().getRowPosition() != startingRowPosition) {
// 起始行不一致
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
// 得到上次查找的列
int columnIndex = coordinate.getLayer().getColumnIndexByPosition(coordinate.getColumnPosition());
if (columnIndex != (sourceButton.getSelection() ? editor.getSrcColumnIndex() : editor.getTgtColumnIndex())) {
// 如果所查找的列改变了,赋为初始值
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
if (forwardButton.getSelection()) {
startOffset = cellRegion.getRegion().getOffset() + cellRegion.getRegion().getLength();
} else {
startOffset = cellRegion.getRegion().getOffset() - 1;
if (startOffset == -1) {
// 解决在垂直布局时,选择向后查找在查找到某一行后会返回到最后一行继续查找的问题。
if (editor.isHorizontalLayout()) {
startingRowPosition--;
} else {
startingRowPosition -= 2;
}
}
}
}
}
cellRegion = find(startingRowPosition, startOffset);
replaceButton.setEnabled(!sourceButton.getSelection() && cellRegion != null);
if (cellRegion == null) {
refreshMsgAndTable();
}
return cellRegion != null;
} else {
return doFind();
}
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class FindReplaceDialog method doReplaceAll.
/**
* 替换全部 ;
*/
private void doReplaceAll() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return;
}
CellRegion cellRegion = null;
if (editor.isHorizontalLayout()) {
cellRegion = find(0, 0);
} else {
cellRegion = find(1, 0);
}
if (cellRegion == null) {
// 无查找结果
return;
}
boolean forward = forwardButton.getSelection();
if (!forward) {
forwardButton.setSelection(true);
}
int firstRowPosition = cellRegion.getPositionCoordinate().getRowPosition();
HashMap<String, String> segments = new HashMap<String, String>();
int count = 0;
String findStr = cmbFind.getText();
String replaceStr = cmbReplace.getText();
do {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
int rowPosition = coordinate.rowPosition;
int columnPosition = coordinate.columnPosition;
int rowIndex = coordinate.getLayer().getRowIndexByPosition(rowPosition);
if (!editor.isHorizontalLayout()) {
rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
}
// 判断锁定
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
String translate = transUnit.getTuProps().get("translate");
if (translate != null && "no".equalsIgnoreCase(translate)) {
rowPosition++;
cellRegion = find(rowPosition, 0);
continue;
}
String cellValue = (String) coordinate.getLayer().getDataValueByPosition(columnPosition, rowPosition);
StringBuffer cellValueBf = new StringBuffer(cellValue);
int start = cellValue.toUpperCase().indexOf(findStr.toUpperCase());
while (start != -1) {
cellValueBf.replace(start, start + findStr.length(), replaceStr);
start = cellValueBf.indexOf(findStr, start);
count++;
}
segments.put(editor.getXLFHandler().getRowId(rowIndex), cellValueBf.toString());
rowPosition++;
if (!editor.isHorizontalLayout()) {
rowPosition++;
}
cellRegion = find(rowPosition, 0);
} while (cellRegion.getPositionCoordinate().getRowPosition() != firstRowPosition);
if (!forward) {
forwardButton.setSelection(false);
backwardButton.setSelection(true);
}
int columnIndex = 0;
if (sourceButton.getSelection()) {
columnIndex = editor.getSrcColumnIndex();
} else {
columnIndex = editor.getTgtColumnIndex();
}
try {
editor.updateSegments(segments, columnIndex, null, null);
} catch (ExecutionException e) {
LOGGER.error(Messages.getString("dialog.FindReplaceDialog.logger1"), e);
}
String msg = Messages.getString("dialog.FindReplaceDialog.status3");
statusLabel.setText(MessageFormat.format(msg, count));
ActiveCellRegion.setActiveCellRegion(null);
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class CellDisplayValueSearchUtil method getCellCoordinates.
static List<PositionCoordinate> getCellCoordinates(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height, boolean isHorizontalLayout) {
if (!isHorizontalLayout) {
height = (int) Math.ceil(height * 1.0 / VerticalNatTableConfig.ROW_SPAN);
}
List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>();
for (int columnPosition = 0; columnPosition < width; columnPosition++) {
for (int rowPosition = 0; rowPosition < height; rowPosition++) {
PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition, startingRowPosition);
coordinates.add(coordinate);
startingRowPosition += isHorizontalLayout ? 1 : VerticalNatTableConfig.ROW_SPAN;
}
startingColumnPosition++;
}
return coordinates;
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class CellDisplayValueSearchUtil method findCell.
static CellRegion findCell(final ILayer layer, final IConfigRegistry configRegistry, final PositionCoordinate[] cellsToSearch, final Object valueToMatch, final ICellSearchStrategy cellSearchStrategy) {
final List<PositionCoordinate> cellCoordinates = Arrays.asList(cellsToSearch);
// Find cell
CellRegion targetCoordinate = null;
String stringValue = valueToMatch.toString();
final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
for (int cellIndex = 0; cellIndex < cellCoordinates.size(); cellIndex++) {
final PositionCoordinate cellCoordinate = cellCoordinates.get(cellIndex);
final int columnPosition = cellCoordinate.columnPosition;
final int rowPosition = cellCoordinate.rowPosition;
// Convert cell's data
if (displayConverter instanceof TagDisplayConverter) {
LayerCell cell = new LayerCell(cellCoordinate.getLayer(), cellCoordinate.getColumnPosition(), cellCoordinate.getRowPosition());
((TagDisplayConverter) displayConverter).setCell(cell);
}
final Object dataValue = displayConverter.canonicalToDisplayValue(layer.getDataValueByPosition(columnPosition, rowPosition));
// Compare with valueToMatch
if (dataValue instanceof String) {
String dataValueString = dataValue.toString();
IRegion region;
if ((region = cellSearchStrategy.executeSearch(stringValue, dataValueString)) != null) {
targetCoordinate = new CellRegion(cellCoordinate, region);
break;
}
((DefaultCellSearchStrategy) cellSearchStrategy).setStartOffset(-1);
}
}
return targetCoordinate;
}
Aggregations