use of org.eclipse.swt.graphics.Rectangle 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 org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class HsMultiCellEditorControl method activeCell.
private static HsMultiCellEditor activeCell(ViewportLayer vLayer, XLIFFEditorImplWithNatTable xliffEditor, IConfigRegistry configRegistry, int columnIndex, int rowIndex, int rowPosition, String cellType) {
NatTable natTable = xliffEditor.getTable();
int columnPosition = vLayer.getColumnPositionByIndex(columnIndex);
LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
if (cell == null) {
return null;
}
Rectangle cellBounds = cell.getBounds();
List<String> configLabels = cell.getConfigLabels().getLabels();
if (!xliffEditor.isHorizontalLayout()) {
if (cellType.equals(NatTableConstant.SOURCE)) {
configLabels.remove(XLIFFEditorImplWithNatTable.TARGET_EDIT_CELL_LABEL);
} else if (cellType.equals(NatTableConstant.TARGET)) {
configLabels.remove(XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
}
}
ILayer layer = cell.getLayer();
Object originalCanonicalValue = cell.getDataValue();
IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);
Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
int cellStartY = cellBounds.y;
int cellEndY = cellStartY + cellBounds.height;
Rectangle clientArea = natTable.getClientAreaProvider().getClientArea();
int clientAreaEndY = clientArea.y + clientArea.height;
if (cellEndY > clientAreaEndY) {
editorBounds.height = clientAreaEndY - cellStartY;
}
StyledTextCellEditor cellEditor = (StyledTextCellEditor) configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
ICellEditHandler editHandler = new HsMultiCellEditorHandler(cellEditor, layer);
HsMultiCellEditor hsCellEditor = new HsMultiCellEditor(cellType, cellEditor, editHandler, columnPosition, rowPosition, columnIndex, rowIndex, dataValidator, originalCanonicalValue, displayConverter, cellStyle, editorBounds);
return hsCellEditor;
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class TypeColunmCellRenderer method getTextBounds.
/**
* {@inheritDoc}
*/
public Rectangle getTextBounds(GridItem item, boolean preferred) {
int x = leftMargin;
Image image = item.getImage(getColumn());
if (image != null) {
x += image.getBounds().width + 3;
}
Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);
GC gc = new GC(item.getParent());
gc.setFont(item.getFont(getColumn()));
Point size = gc.stringExtent(item.getText(getColumn()));
bounds.height = size.y;
if (preferred) {
bounds.width = size.x - 1;
} else {
bounds.width = getBounds().width - x - rightMargin;
}
gc.dispose();
return bounds;
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class GridCopyEnable method clearSelection.
void clearSelection() {
int start = selection.x;
int end = selection.y;
selection.x = selection.y = caretOffset;
selectionAnchor = -1;
// redraw old selection, if any
if (end - start > 0 && gridTable.getItems().length != 0) {
if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
GridItem item = gridTable.getItem(focusItemIndex);
GridColumn col = gridTable.getColumn(focusColIndex);
GridCellRenderer gcr = col.getCellRenderer();
if (gcr != null && gcr instanceof XGridCellRenderer) {
GC gc = new GC(gcr.getDisplay());
layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
gc.dispose();
}
if (layout == null) {
return;
}
}
Rectangle rect = layout.getBounds(start, end);
gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class GridCopyEnable method handleVerticalScroll.
void handleVerticalScroll(Event event) {
GridVisibleRange visibleR = gridTable.getVisibleRange();
GridItem[] items = visibleR.getItems();
boolean itemFlg = false;
for (GridItem item : items) {
if (focusItem == item) {
itemFlg = true;
}
}
boolean columnFlg = false;
GridColumn[] columns = visibleR.getColumns();
if (columns.length - 1 >= focusColIndex) {
columnFlg = true;
}
if (!itemFlg || !columnFlg) {
defaultCaret.setVisible(false);
return;
}
defaultCaret.setVisible(true);
GridColumn col = gridTable.getColumn(focusColIndex);
GridCellRenderer gcr = col.getCellRenderer();
int colIndex = gcr.getColumn();
if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
return;
}
XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
Rectangle cellBounds = focusItem.getBounds(colIndex);
GC gc = new GC(Display.getDefault());
TextLayout layout = null;
try {
layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
if (layout == null) {
gc.dispose();
return;
}
Point point = layout.getLocation(caretOffset, false);
coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
} finally {
if (layout != null) {
layout.dispose();
}
if (gc != null) {
gc.dispose();
}
}
}
Aggregations