Search in sources :

Example 1 with GridCellRenderer

use of org.eclipse.nebula.widgets.grid.GridCellRenderer 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);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 2 with GridCellRenderer

use of org.eclipse.nebula.widgets.grid.GridCellRenderer 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();
        }
    }
}
Also used : GridVisibleRange(org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC)

Example 3 with GridCellRenderer

use of org.eclipse.nebula.widgets.grid.GridCellRenderer in project translationstudio8 by heartsome.

the class GridCopyEnable method doMouseLocationChange.

void doMouseLocationChange(int x, int y, boolean select) {
    if (gridTable.getItems().length == 0) {
        defaultCaret.setVisible(false);
        return;
    }
    Point eventP = new Point(x, y);
    GridItem _focusItem = gridTable.getItem(eventP);
    GridColumn col = gridTable.getColumn(eventP);
    if (_focusItem == null) {
        return;
    }
    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());
    layout = cellRender.getTextLayout(gc, _focusItem, colIndex, true, false);
    if (layout == null) {
        gc.dispose();
        return;
    }
    focusContent = layout.getText();
    coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
    coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
    if (!select) {
        focusCellRect.x = cellBounds.x;
        focusCellRect.y = cellBounds.y;
        focusCellRect.height = cellBounds.height;
        focusCellRect.width = cellBounds.width;
        focusColIndex = colIndex;
        focusItemIndex = gridTable.getIndexOfItem(_focusItem);
    }
    int[] trailing = new int[1];
    int newCaretOffset = layout.getOffset(x - coordinateOffsetX, y - coordinateOffsetY, trailing);
    int newCaretLine = layout.getLineIndex(newCaretOffset + trailing[0]);
    int lineStart = layout.getLineOffsets()[newCaretLine];
    Point point = null;
    if (newCaretOffset + trailing[0] == lineStart && trailing[0] != 0) {
        newCaretOffset += trailing[0];
        newCaretOffset = layout.getPreviousOffset(newCaretOffset, SWT.MOVEMENT_CLUSTER);
        point = layout.getLocation(newCaretOffset, true);
    } else {
        newCaretOffset += trailing[0];
        point = layout.getLocation(newCaretOffset, false);
    }
    // check area, only in cell area effective
    boolean vchange = focusCellRect.y <= y && y < focusCellRect.y + focusCellRect.height;
    boolean hchange = focusCellRect.x <= x && x < focusCellRect.x + focusCellRect.width;
    if (vchange && hchange && newCaretOffset != caretOffset) {
        focusItem = _focusItem;
        caretOffset = newCaretOffset;
        if (select) {
            doMouseSelection();
        }
        defaultCaret.setVisible(true);
        Rectangle rc = layout.getLineBounds(newCaretLine);
        defaultCaret.setBounds(point.x + coordinateOffsetX, point.y + coordinateOffsetY, 0, rc.height);
    }
    if (!select) {
        caretOffset = newCaretOffset;
        clearSelection();
    }
    layout.dispose();
    layout = null;
    gc.dispose();
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Aggregations

GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)3 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)3 GridItem (org.eclipse.nebula.widgets.grid.GridItem)3 GC (org.eclipse.swt.graphics.GC)3 Point (org.eclipse.swt.graphics.Point)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 GridVisibleRange (org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange)1 TextLayout (org.eclipse.swt.graphics.TextLayout)1