Search in sources :

Example 1 with JaretTableCellImpl

use of de.jaret.util.ui.table.model.JaretTableCellImpl in project translationstudio8 by heartsome.

the class JaretTable method getCell.

/**
     * Retrieve TableXCell for given pixel coordinates.
     * 
     * @param x pixel coordinate x
     * @param y pixel coordinate y
     * @return table cel if found or <code>null</code> if no cell can be found
     */
public IJaretTableCell getCell(int x, int y) {
    if (_tableRect.contains(x, y)) {
        IRow row = rowForY(y);
        IColumn col = colForX(x);
        if (row == null || col == null) {
            return null;
        }
        return new JaretTableCellImpl(row, col);
    }
    return null;
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn)

Example 2 with JaretTableCellImpl

use of de.jaret.util.ui.table.model.JaretTableCellImpl in project translationstudio8 by heartsome.

the class JaretTable method ensureSelectionContainsRegion.

/**
     * Ensures the selection contains the cells in the rectangle given by first*, *Idx. If the rectangle given by
     * first*, last* is larger than the other rectangle is is ensured that the additional cells are not in the
     * selection.
     * 
     * @param firstCellSelectX begin x index of selected cell rectangle
     * @param firstCellSelectY begin y index of selected cell rectangle
     * @param colIdx end x index of selected cell rectangle
     * @param rowIdx end y index of selected cell rectangle
     * @param lastCellSelectX may be -1 for no last selection
     * @param lastCellSelectY may be -1 for no last selection
     */
private void ensureSelectionContainsRegion(int firstCellSelectX, int firstCellSelectY, int colIdx, int rowIdx, int lastCellSelectX, int lastCellSelectY) {
    int firstx = Math.min(firstCellSelectX, colIdx);
    int endx = Math.max(firstCellSelectX, colIdx);
    int firsty = Math.min(firstCellSelectY, rowIdx);
    int endy = Math.max(firstCellSelectY, rowIdx);
    for (int x = firstx; x <= endx; x++) {
        for (int y = firsty; y <= endy; y++) {
            IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
            if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
                _selectionModel.addSelectedCell(cell);
            }
        }
    }
    // last sel rect
    if (lastCellSelectX != -1) {
        int lfx = Math.min(firstCellSelectX, lastCellSelectX);
        int lex = Math.max(firstCellSelectX, lastCellSelectX);
        int lfy = Math.min(firstCellSelectY, lastCellSelectY);
        int ley = Math.max(firstCellSelectY, lastCellSelectY);
        for (int x = lfx; x <= lex; x++) {
            for (int y = lfy; y <= ley; y++) {
                if (!(x >= firstx && x <= endx && y >= firsty && y <= endy)) {
                    IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
                    _selectionModel.remSelectedCell(cell);
                }
            }
        }
    }
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Example 3 with JaretTableCellImpl

use of de.jaret.util.ui.table.model.JaretTableCellImpl in project translationstudio8 by heartsome.

the class JaretTable method ensureSelectionContainsRegion.

/**
     * Ensures the selection contains the cells in the rectangle given by firstIdxRect, *Idx. If the rectangle given by
     * first*, last* is larger than the other rectangle is is ensured that the additional cells are not in the
     * selection.
     * 
     * @param firstIdxRect rectangle containing the indizes of the originating rect
     * @param colIdx new end x index for the selected rectangle
     * @param rowIdx new end y index for teh selecetd rectangle
     * @param lastCellSelectX may be -1 for no last selection
     * @param lastCellSelectY may be -1 for no last selection
     */
private void ensureSelectionContainsRegion(Rectangle firstIdxRect, int colIdx, int rowIdx, int lastCellSelectX, int lastCellSelectY) {
    int firstx = Math.min(firstIdxRect.x, colIdx);
    int endx = Math.max(firstIdxRect.x + firstIdxRect.width - 1, colIdx);
    int firsty = Math.min(firstIdxRect.y, rowIdx);
    int endy = Math.max(firstIdxRect.y + firstIdxRect.height - 1, rowIdx);
    for (int x = firstx; x <= endx; x++) {
        for (int y = firsty; y <= endy; y++) {
            IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
            if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
                _selectionModel.addSelectedCell(cell);
            }
        }
    }
    // last sel rect
    if (lastCellSelectX != -1 && lastCellSelectY != -1) {
        int lfx = Math.min(firstIdxRect.x, lastCellSelectX);
        int lex = Math.max(firstIdxRect.x + firstIdxRect.width - 1, lastCellSelectX);
        int lfy = Math.min(firstIdxRect.y, lastCellSelectY);
        int ley = Math.max(firstIdxRect.y + firstIdxRect.height - 1, lastCellSelectY);
        for (int x = lfx; x <= lex; x++) {
            for (int y = lfy; y <= ley; y++) {
                if (!(x >= firstx && x <= endx && y >= firsty && y <= endy)) {
                    IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
                    _selectionModel.remSelectedCell(cell);
                }
            }
        }
    }
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Example 4 with JaretTableCellImpl

use of de.jaret.util.ui.table.model.JaretTableCellImpl in project translationstudio8 by heartsome.

the class JaretTable method handleSelection.

/**
     * Handle selection operations.
     * 
     * @param x x
     * @param y y
     * @param stateMask key state mask
     * @param dragging true when dragging
     */
private void handleSelection(int x, int y, int stateMask, boolean dragging) {
    // a mouse select always ends a shift-arrow select
    _lastKeySelect = null;
    _firstKeySelect = null;
    _firstKeyColSelectIdx = -1;
    _lastKeyColSelectIdx = -1;
    _firstKeyRowSelectIdx = -1;
    _lastKeyRowSelectIdx = -1;
    IRow row = rowForY(y);
    int rowIdx = row != null ? _rows.indexOf(row) : -1;
    IColumn col = colForX(x);
    int colIdx = getColumnIdx(col);
    // check fill dragging
    if (dragging && _isFillDrag) {
        if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
            if (col != null && row != null) {
                if (_firstCellSelectX == -1) {
                    _firstCellSelectX = colIdx;
                    _firstCellSelectY = rowIdx;
                }
                if (Math.abs(_firstCellSelectX - colIdx) > Math.abs(_firstCellSelectY - rowIdx)) {
                    rowIdx = _firstCellSelectY;
                    row = rowForIdx(rowIdx);
                    _horizontalFillDrag = false;
                } else {
                    colIdx = _firstCellSelectX;
                    col = colForIdx(colIdx);
                    _horizontalFillDrag = true;
                }
                ensureSelectionContainsRegion(_firstFillDragSelect, colIdx, rowIdx, _lastCellSelectX, _lastCellSelectY);
                // ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx,
                // _lastCellSelectX, _lastCellSelectY);
                _lastCellSelectX = colIdx;
                _lastCellSelectY = rowIdx;
                // a newly selected cell will always be the focussed cell (causes scrolling this cell to be
                // completely visible)
                setFocus(row, col);
            }
        }
        return;
    }
    // check row selection
    if (row != null && _selectionModel.isFullRowSelectionAllowed() && (isRowSelection(x, y) || _selectionModel.isOnlyRowSelectionAllowed() || _firstRowSelectIdx != -1)) {
        if (_firstRowSelectIdx == -1) {
            _firstRowSelectIdx = rowIdx;
        }
        if ((stateMask & SWT.CONTROL) != 0) {
            if (!_selectionModel.getSelection().getSelectedRows().contains(row)) {
                _selectionModel.addSelectedRow(row);
            } else {
                _selectionModel.remSelectedRow(row);
            }
            _lastSelectType = SelectType.ROW;
        } else if (dragging) {
            ensureSelectionContainsRowRegion(_firstRowSelectIdx, rowIdx, _lastRowSelectIdx);
            _lastRowSelectIdx = rowIdx;
            _lastSelectType = SelectType.ROW;
        } else {
            _selectionModel.clearSelection();
            _selectionModel.addSelectedRow(row);
            _lastSelectType = SelectType.ROW;
        }
        _lastRowSelectIdx = rowIdx;
        return;
    }
    // check column selection
    if (_selectionModel.isFullColumnSelectionAllowed() && (isColumnSelection(x, y) || _firstColSelectIdx != -1)) {
        if (_firstColSelectIdx == -1) {
            _firstColSelectIdx = colIdx;
        }
        if ((stateMask & SWT.CONTROL) != 0) {
            if (!_selectionModel.getSelection().getSelectedColumns().contains(col)) {
                _selectionModel.addSelectedColumn(col);
            } else {
                _selectionModel.remSelectedColumn(col);
            }
            _lastSelectType = SelectType.COLUMN;
        } else if (dragging) {
            ensureSelectionContainsColRegion(_firstColSelectIdx, colIdx, _lastColSelectIdx);
            _lastColSelectIdx = colIdx;
            _lastSelectType = SelectType.COLUMN;
        } else {
            _selectionModel.clearSelection();
            _selectionModel.addSelectedColumn(col);
            _lastSelectType = SelectType.COLUMN;
        }
        _lastColSelectIdx = colIdx;
        return;
    }
    // check cell selection
    if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
        if (col != null && row != null) {
            IJaretTableCell cell = new JaretTableCellImpl(row, col);
            if (_firstCellSelectX == -1) {
                _firstCellSelectX = colIdx;
                _firstCellSelectY = rowIdx;
            }
            if ((stateMask & SWT.CONTROL) != 0) {
                if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
                    _selectionModel.addSelectedCell(cell);
                } else {
                    _selectionModel.remSelectedCell(cell);
                }
                _lastSelectType = SelectType.CELL;
            } else if (dragging) {
                ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx, _lastCellSelectX, _lastCellSelectY);
                _lastCellSelectX = colIdx;
                _lastCellSelectY = rowIdx;
                _lastSelectType = SelectType.CELL;
            } else {
                _selectionModel.clearSelection();
                _selectionModel.addSelectedCell(cell);
                _lastSelectType = SelectType.CELL;
            }
            // a newly selected cell will always be the focussed cell (causes scrolling this cell to be completely
            // visible)
            setFocus(row, col);
        }
    }
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Aggregations

JaretTableCellImpl (de.jaret.util.ui.table.model.JaretTableCellImpl)4 IJaretTableCell (de.jaret.util.ui.table.model.IJaretTableCell)3 Point (org.eclipse.swt.graphics.Point)3 IColumn (de.jaret.util.ui.table.model.IColumn)2 IRow (de.jaret.util.ui.table.model.IRow)2