Search in sources :

Example 31 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JaretTable method preparePaint.

/**
     * Calculate the layout of the table area rectangles.
     * 
     * @param width width of the table
     * @param height height of the table
     */
private void preparePaint(int width, int height) {
    if (_drawHeader) {
        _headerRect = new Rectangle(0, 0, width, _headerHeight);
    } else {
        _headerRect = new Rectangle(0, 0, 0, 0);
    }
    if (_autoFilterEnabled) {
        // preferred height of the autofilters
        int autoFilterHeight = getPreferredAutoFilterHeight();
        _autoFilterRect = new Rectangle(0, _headerRect.y + _headerRect.height, _headerRect.width, autoFilterHeight);
        _tableRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width, height - _autoFilterRect.height);
    } else {
        _tableRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, height - _headerRect.height);
    }
    // do we have fixed cols? correct other rects and calc fixed col rect
    if (_fixedColumns > 0) {
        int fWidth = getFixedColumnsWidth();
        _headerRect.x = _headerRect.x + fWidth;
        _headerRect.width = _headerRect.width - fWidth;
        if (_autoFilterEnabled) {
            _autoFilterRect.x = _headerRect.x;
            _autoFilterRect.width = _headerRect.width;
        }
        _tableRect.x = _headerRect.x;
        _tableRect.width = _headerRect.width;
        _fixedColRect = new Rectangle(0, _tableRect.y, fWidth, _tableRect.height);
    } else {
        _fixedColRect = new Rectangle(_tableRect.x, _tableRect.y, 0, _tableRect.height);
    }
    // do we have fixed rows? correct other rects nd setup the fixed row rect
    if (_fixedRows > 0) {
        int fHeight = getFixedRowsHeight();
        if (_autoFilterEnabled) {
            _fixedRowRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width, getFixedRowsHeight());
        } else {
            _fixedRowRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, getFixedRowsHeight());
        }
        _tableRect.y = _tableRect.y + fHeight;
        _tableRect.height = _tableRect.height - fHeight;
        if (_fixedColumns > 0) {
            _fixedColRect.y = _tableRect.y;
            _fixedColRect.height = _tableRect.height;
        }
    } else {
        // ensure fixed Row rect is available
        _fixedRowRect = new Rectangle(_tableRect.x, _tableRect.y, _tableRect.width, 0);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 32 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JaretTable method startEditing.

/**
     * Start editing of a specified cell if it is editable.
     * 
     * @param row row
     * @param col column
     * @param typedKey key typed
     */
public void startEditing(IRow row, IColumn col, char typedKey) {
    if (isEditing()) {
        stopEditing(true);
    }
    if (!_model.isEditable(row, col)) {
        return;
    }
    clearSelection();
    if (row != null && col != null) {
        _editor = getCellEditor(row, col);
        if (_editor != null) {
            _editorControl = _editor.getEditorControl(this, row, col, typedKey);
            if (_editorControl != null) {
                Rectangle bounds = getCellBounds(row, col);
                // TODO borderwidth
                bounds.x += 1;
                bounds.width -= 1;
                bounds.y += 1;
                if (_editor.getPreferredHeight() == -1 || _editor.getPreferredHeight() < bounds.height) {
                    bounds.height -= 1;
                } else {
                    bounds.height = _editor.getPreferredHeight();
                }
                _editorControl.setBounds(bounds);
                _editorControl.setVisible(true);
                _editorControl.forceFocus();
            }
            _editorRow = row;
        } else {
        // System.out.println("no cell editor found!");
        }
    }
    if (_editorControl == null) {
        stopEditing(true);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 33 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JaretTable method getToolTipText.

/**
     * Supply tooltip text for a position in the table.
     * 
     * @param x x coordinate
     * @param y y coordinate
     * @return tooltip text or <code>null</code>
     */
private String getToolTipText(int x, int y) {
    IJaretTableCell cell = getCell(x, y);
    if (cell != null) {
        Rectangle bounds = getCellBounds(cell);
        ICellRenderer renderer = getCellRenderer(cell.getRow(), cell.getColumn());
        if (renderer != null) {
            String tt = renderer.getTooltip(this, bounds, cell.getRow(), cell.getColumn(), x, y);
            if (tt != null) {
                return tt;
            }
        }
    }
    return null;
}
Also used : ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell)

Example 34 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JaretTable method mousePressed.

/**
     * Handle mouse pressed.
     * 
     * @param x x coordinate
     * @param y y coordinate
     * @param popuptrigger true if the button pressed was the popup trigger
     * @param stateMask statemask from the event
     */
private void mousePressed(int x, int y, boolean popuptrigger, int stateMask) {
    // check for location over drag marker and start fill drag if necessary
    if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
        _isFillDrag = true;
        _firstFillDragSelect = _selectedIdxRectangle;
        return;
    }
    IRow row = rowByBottomBorder(y);
    if (row != null && _rowResizeAllowed && (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR) && (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect.contains(x, y)))) {
        _heightDraggedRowInfo = getRowInfo(row);
        return;
    } else {
        IColumn col = colByRightBorder(x);
        if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col) && (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
            _widthDraggedColumn = getColInfo(col);
            return;
        }
    }
    // check header drag
    if (_headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
        _headerDragged = true;
        return;
    }
    // handle mouse press for selection
    boolean doSelect = true;
    // check focus set
    if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y)) || (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
        setFocus(x, y);
        doSelect = !handleEditorSingleClick(x, y);
    }
    // check hierarchy
    if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y)) || (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
        IRow xrow = rowForY(y);
        IColumn xcol = colForX(x);
        if (xrow != null && xcol != null && isHierarchyColumn(xrow, xcol)) {
            Rectangle rect = getCellBounds(xrow, xcol);
            IHierarchyRenderer hrenderer = (IHierarchyRenderer) getCellRenderer(xrow, xcol);
            if (hrenderer.isInActiveArea(xrow, rect, x, y)) {
                toggleExpanded(xrow);
            }
        }
    }
    // check header sorting clicks
    IColumn xcol = colForX(x);
    if (_allowSorting && _headerRect.contains(x, y) && _headerRenderer.isSortingClick(getHeaderDrawingArea(xcol), xcol, x, y)) {
        _tvs.setSorting(xcol);
    } else if (doSelect) {
        // selection can be intercepted by editor clicks
        handleSelection(x, y, stateMask, false);
    }
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) IHierarchyRenderer(de.jaret.util.ui.table.renderer.IHierarchyRenderer)

Example 35 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JaretTable method handleVerticalScroll.

/**
     * Handle a selection on the vertical scroll bar (a vertical scroll).
     * 
     * @param event selection
     */
private void handleVerticalScroll(SelectionEvent event) {
    int value = getVerticalBar().getSelection() + getFixedRowsHeight();
    int rowidx = getRowIdxForAbsY(value);
    int offset = value - getAbsBeginYForRowIdx(rowidx);
    int oldFirstIdx = _firstRowIdx;
    int oldPixelOffset = _firstRowPixelOffset;
    int diff = _oldVerticalScroll - value;
    if (Math.abs(diff) > _tableRect.height / 2 || _oldVerticalScroll == -1 || !_optimizeScrolling) {
        update();
        _firstRowIdx = rowidx;
        _firstRowPixelOffset = offset;
        // kill the cache
        _rowInfoCache = null;
        redraw();
    } else {
        Rectangle completeArea = new Rectangle(_fixedColRect.x, _tableRect.y, _fixedColRect.width + _tableRect.width, _tableRect.height);
        if (diff > 0) {
            scroll(0, completeArea.y + diff, 0, completeArea.y, getWidth(), completeArea.height - diff, false);
        } else {
            diff = -diff;
            scroll(0, completeArea.y, 0, completeArea.y + diff, getWidth(), completeArea.height - diff, false);
        }
        _firstRowIdx = rowidx;
        _firstRowPixelOffset = offset;
        // kill the cache
        _rowInfoCache = null;
    }
    _oldVerticalScroll = value;
    firePropertyChange(PROPERTYNAME_FIRSTROWIDX, oldFirstIdx, _firstRowIdx);
    firePropertyChange(PROPERTYNAME_FIRSTROWPIXELOFFSET, oldPixelOffset, _firstRowPixelOffset);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)651 Point (org.eclipse.swt.graphics.Point)370 Image (org.eclipse.swt.graphics.Image)114 GC (org.eclipse.swt.graphics.GC)104 Test (org.junit.Test)80 Color (org.eclipse.swt.graphics.Color)61 Shell (org.eclipse.swt.widgets.Shell)54 Composite (org.eclipse.swt.widgets.Composite)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)51 TableItem (org.eclipse.swt.widgets.TableItem)47 GridLayout (org.eclipse.swt.layout.GridLayout)44 Display (org.eclipse.swt.widgets.Display)44 Button (org.eclipse.swt.widgets.Button)42 Menu (org.eclipse.swt.widgets.Menu)40 GridData (org.eclipse.swt.layout.GridData)38 Label (org.eclipse.swt.widgets.Label)37 SWT (org.eclipse.swt.SWT)34 Event (org.eclipse.swt.widgets.Event)34 Font (org.eclipse.swt.graphics.Font)30 Listener (org.eclipse.swt.widgets.Listener)29