Example usage for org.eclipse.jface.viewers ViewerCell getBounds

List of usage examples for org.eclipse.jface.viewers ViewerCell getBounds

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Get the bounds of the cell.

Usage

From source file:net.certiv.fluentmark.tables.AbstractCellCursor.java

License:Open Source License

/**
 * @param cell/*from   ww  w.  j  a  v a  2 s  .c  o  m*/
 * @param eventTime
 */
public void setSelection(ViewerCell cell, int eventTime) {
    this.cells = new ViewerCell[] { cell };
    setBounds(cell.getBounds());
    forceFocus();
    redraw();
    activationTime = eventTime + getDisplay().getDoubleClickTime();
}

From source file:net.certiv.fluentmark.tables.FocusBorderCellHighlighter.java

License:Open Source License

@Override
protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) {
    super.focusCellChanged(newCell, oldCell);

    // Redraw new area
    if (newCell != null) {
        Rectangle rect = newCell.getBounds();
        int x = newCell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = newCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        newCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }/* w  w w  . j  av  a  2 s  .co m*/

    if (oldCell != null) {
        Rectangle rect = oldCell.getBounds();
        int x = oldCell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        oldCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }
}

From source file:net.tourbook.ui.views.ColumnViewerTourInfoToolTip.java

License:Open Source License

@Override
public Point getLocation(final Point tipSize, final Event event) {

    // try to position the tooltip at the bottom of the cell
    final ViewerCell cell = _columnViewer.getCell(new Point(event.x, event.y));

    if (cell != null) {

        final Rectangle cellBounds = cell.getBounds();
        final int cellWidth2 = cellBounds.width / 2;
        final int cellHeight = cellBounds.height;

        final int devXDefault = cellBounds.x + cellWidth2;// + cellBounds.width; //event.x;
        final int devY = cellBounds.y + cellHeight;

        /*/*from ww  w  .  ja  v a 2s  . c  o  m*/
         * check if the tooltip is outside of the tree, this can happen when the column is very
         * wide and partly hidden
         */
        final Rectangle treeBounds = _ttControl.getBounds();
        boolean isDevXAdjusted = false;
        int devX = devXDefault;

        if (devXDefault >= treeBounds.width) {
            devX = treeBounds.width - 40;
            isDevXAdjusted = true;
        }

        final Rectangle displayBounds = _ttControl.getDisplay().getBounds();

        Point ttDisplayLocation = _ttControl.toDisplay(devX, devY);
        final int tipSizeWidth = tipSize.x;
        final int tipSizeHeight = tipSize.y;

        if (ttDisplayLocation.x + tipSizeWidth > displayBounds.width) {

            /*
             * adjust horizontal position, it is outside of the display, prevent default
             * repositioning
             */

            if (isDevXAdjusted) {

                ttDisplayLocation = _ttControl.toDisplay(devXDefault - cellWidth2 + 20 - tipSizeWidth, devY);

            } else {
                ttDisplayLocation.x = ttDisplayLocation.x - tipSizeWidth;
            }
        }

        if (ttDisplayLocation.y + tipSizeHeight > displayBounds.height) {

            /*
             * adjust vertical position, it is outside of the display, prevent default
             * repositioning
             */

            ttDisplayLocation.y = ttDisplayLocation.y - tipSizeHeight - cellHeight;
        }

        return fixupDisplayBoundsWithMonitor(tipSize, ttDisplayLocation);
    }

    return super.getLocation(tipSize, event);
}

From source file:org.csstudio.scan.ui.scantree.gui.ScanTreeGUI.java

License:Open Source License

/** Determine where mouse pointer is relative to a tree item
 *  @param x Mouse coordinate/*from   w w w.  jav  a  2  s  .  co  m*/
 *  @param y Mouse coordinate
 *  @return {@link TreeItemInfo} or <code>null</code>
 */
private TreeItemInfo getTreeItemInfo(final int x, final int y) {
    // Get cell under mouse pointer
    final Control tree = tree_view.getControl();
    final Point point = tree.getDisplay().map(null, tree, x, y);
    final ViewerCell cell = tree_view.getCell(point);
    if (cell == null)
        return null;

    final ScanCommand command = (ScanCommand) cell.getElement();

    final Rectangle bounds = cell.getBounds();
    // Determine if we are in upper, middle or lower 1/3 of the cell
    if (point.y < bounds.y + bounds.height / 3)
        return new TreeItemInfo(command, TreeItemInfo.Section.UPPER);
    else if (point.y > bounds.y + 2 * bounds.height / 3)
        return new TreeItemInfo(command, TreeItemInfo.Section.LOWER);
    else
        return new TreeItemInfo(command, TreeItemInfo.Section.CENTER);
}

From source file:org.eclipse.egit.ui.internal.history.CommitGraphTableHoverManager.java

License:Open Source License

private Information computeInformationForRef(SWTCommit commit, ViewerCell cell, MouseEvent e) {
    if (commit.getRefCount() == 0)
        return null;
    Rectangle itemBounds = cell.getBounds();
    int relativeX = e.x - itemBounds.x;
    for (int i = 0; i < commit.getRefCount(); i++) {
        Ref ref = commit.getRef(i);
        Point textSpan = renderer.getRefHSpan(ref);
        if ((textSpan != null) && (relativeX >= textSpan.x && relativeX <= textSpan.y)) {

            String hoverText = getHoverText(ref, i, commit);
            int x = itemBounds.x + textSpan.x;
            int width = textSpan.y - textSpan.x;
            Rectangle rectangle = new Rectangle(x, itemBounds.y, width, itemBounds.height);
            return new Information(hoverText, rectangle);
        }/* w w w  . ja  va  2s.  c  om*/
    }
    return null;
}

From source file:org.eclipse.egit.ui.internal.history.CommitGraphTableHoverManager.java

License:Open Source License

private Information computeInformationForName(PersonIdent ident, ViewerCell cell) {
    String nameWithEmail = ident.getName() + " <" + ident.getEmailAddress() + ">"; //$NON-NLS-1$ //$NON-NLS-2$
    return new Information(nameWithEmail, cell.getBounds());
}

From source file:org.eclipse.egit.ui.internal.history.CommitGraphTableHoverManager.java

License:Open Source License

private Information computeInformationForDate(PersonIdent ident, ViewerCell cell) {
    String formattedDate = dateFormatter.formatDate(ident);
    return new Information(formattedDate, cell.getBounds());
}

From source file:org.eclipse.emf.examples.library.databinding.common.FocusCellOwnerDrawHighlighter.java

License:Open Source License

protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) {
    super.focusCellChanged(newCell, oldCell);

    // Redraw new area
    if (newCell != null) {
        Rectangle rect = newCell.getBounds();
        int x = newCell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = newCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        newCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }/* w ww  .j av a2 s .  com*/

    if (oldCell != null) {
        Rectangle rect = oldCell.getBounds();
        int x = oldCell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        oldCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }
}

From source file:org.eclipse.jface.snippets.viewers.FocusBorderCellHighlighter.java

License:Open Source License

@Override
protected void focusCellChanged(ViewerCell cell) {
    super.focusCellChanged(cell);

    // Redraw new area
    if (cell != null) {
        Rectangle rect = cell.getBounds();
        int x = cell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = cell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        cell.getControl().redraw(x, rect.y, width, rect.height, true);
    }/*from  w  w  w .  java  2s. c  o  m*/

    if (oldCell != null) {
        Rectangle rect = oldCell.getBounds();
        int x = oldCell.getColumnIndex() == 0 ? 0 : rect.x;
        int width = oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        oldCell.getControl().redraw(x, rect.y, width, rect.height, true);
    }

    this.oldCell = cell;
}

From source file:org.eclipse.jface.snippets.viewers.TableCursor.java

License:Open Source License

@Override
protected void paint(Event event) {
    if (getSelectedCells().length == 1 && getSelectedCells()[0] == null)
        return;/*from  w w  w.j av  a2  s.com*/
    ViewerCell cell = getSelectedCells()[0];

    GC gc = event.gc;
    Display display = getDisplay();
    gc.setBackground(getBackground());
    gc.setForeground(getForeground());
    gc.fillRectangle(event.x, event.y, event.width, event.height);
    int x = 0;
    Point size = getSize();
    Image image = cell.getImage();
    if (image != null) {
        Rectangle imageSize = image.getBounds();
        int imageY = (size.y - imageSize.height) / 2;
        gc.drawImage(image, x, imageY);
        x += imageSize.width;
    }
    String text = cell.getText();
    if (text != "") { //$NON-NLS-1$
        Rectangle bounds = cell.getBounds();
        Point extent = gc.stringExtent(text);
        // Temporary code - need a better way to determine table trim
        if (Util.isWin32()) {
            if (((Table) getParent()).getColumnCount() == 0 || cell.getColumnIndex() == 0) {
                x += 2;
            } else {
                int alignmnent = ((Table) getParent()).getColumn(cell.getColumnIndex()).getAlignment();
                switch (alignmnent) {
                case SWT.LEFT:
                    x += 6;
                    break;
                case SWT.RIGHT:
                    x = bounds.width - extent.x - 6;
                    break;
                case SWT.CENTER:
                    x += (bounds.width - x - extent.x) / 2;
                    break;
                }
            }
        } else {
            if (((Table) getParent()).getColumnCount() == 0) {
                x += 5;
            } else {
                int alignmnent = ((Table) getParent()).getColumn(cell.getColumnIndex()).getAlignment();
                switch (alignmnent) {
                case SWT.LEFT:
                    x += 5;
                    break;
                case SWT.RIGHT:
                    x = bounds.width - extent.x - 2;
                    break;
                case SWT.CENTER:
                    x += (bounds.width - x - extent.x) / 2 + 2;
                    break;
                }
            }
        }
        int textY = (size.y - extent.y) / 2;
        gc.drawString(text, x, textY);
    }
    if (isFocusControl()) {
        gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
        gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        gc.drawFocus(0, 0, size.x, size.y);
    }
}