Search in sources :

Example 11 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.

the class GridColumn method isOverSortArrow.

public boolean isOverSortArrow(int x, int y) {
    if (!isSortable()) {
        return false;
    }
    Rectangle bounds = getBounds();
    if (y < bounds.y || y > bounds.y + bounds.height) {
        return false;
    }
    int arrowEnd = bounds.width - rightMargin;
    Rectangle sortBounds = GridColumnRenderer.getSortControlBounds();
    int arrowBegin = arrowEnd - sortBounds.width;
    return x >= arrowBegin && x <= arrowEnd && y < bounds.y + sortBounds.height;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 12 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.

the class GridColumn method computeCellWidth.

private int computeCellWidth(Object col, Object row) {
    int x = 0;
    x += leftMargin;
    String cellText = grid.getCellText(col, row);
    int state = grid.getContentProvider().getCellState(col, row, cellText);
    Rectangle imageBounds;
    if (GridCellRenderer.isLinkState(state)) {
        imageBounds = GridCellRenderer.LINK_IMAGE_BOUNDS;
    } else {
        DBPImage image = grid.getContentProvider().getCellImage(col, row);
        imageBounds = image == null ? null : DBeaverIcons.getImage(image).getBounds();
    }
    if (imageBounds != null) {
        x += imageBounds.width + insideMargin;
    }
    x += grid.sizingGC.textExtent(cellText).x + rightMargin;
    return x;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 13 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.

the class TabbedFolderComposite method shiftPane.

private void shiftPane(FolderPane curPane, int shift) {
    // Set current height to heightHint
    for (FolderPane pane : folderPanes) {
        Rectangle bounds = pane.editorPane.getBounds();
        GridData gd = (GridData) pane.editorPane.getLayoutData();
        gd.heightHint = bounds.height;
    }
    FolderPane nextPane = getNextFolderPane(curPane);
    ((GridData) curPane.editorPane.getLayoutData()).heightHint += shift;
    ((GridData) nextPane.editorPane.getLayoutData()).heightHint -= shift;
    compositePane.layout();
/*
        if (shift < 0) {
            // Decrease self size and increase next pane's
            //nextPane.editorPane.
        } else {
            // Increase self size and decrease next pane's
        }
*/
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GridData(org.eclipse.swt.layout.GridData)

Example 14 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.

the class ImageViewCanvas method paint.

/* Paint function */
private void paint(GC gc) {
    Rectangle clientRect = getClientArea();
    /* Canvas' painting area */
    if (sourceImage != null) {
        Rectangle imageRect = ImageViewUtil.inverseTransformRect(transform, clientRect);
        int gap = 2;
        /* find a better start point to render */
        imageRect.x -= gap;
        imageRect.y -= gap;
        imageRect.width += 2 * gap;
        imageRect.height += 2 * gap;
        Rectangle imageBound = sourceImage.getBounds();
        imageRect = imageRect.intersection(imageBound);
        Rectangle destRect = ImageViewUtil.transformRect(transform, imageRect);
        if (screenImage != null)
            screenImage.dispose();
        screenImage = new Image(getDisplay(), clientRect.width, clientRect.height);
        GC newGC = new GC(screenImage);
        newGC.setClipping(clientRect);
        newGC.drawImage(sourceImage, imageRect.x, imageRect.y, imageRect.width, imageRect.height, destRect.x, destRect.y, destRect.width, destRect.height);
        newGC.dispose();
        gc.drawImage(screenImage, 0, 0);
    } else {
        gc.setClipping(clientRect);
        gc.fillRectangle(clientRect);
        initScrollBars();
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 15 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.

the class ImageViewCanvas method syncScrollBars.

/**
	 * Synchronize the scrollbar with the image. If the transform is out
	 * of range, it will correct it. This function considers only following
	 * factors :<b> transform, image size, client area</b>.
	 */
public void syncScrollBars() {
    if (sourceImage == null) {
        redraw();
        return;
    }
    AffineTransform af = transform;
    double sx = af.getScaleX(), sy = af.getScaleY();
    double tx = af.getTranslateX(), ty = af.getTranslateY();
    if (tx > 0)
        tx = 0;
    if (ty > 0)
        ty = 0;
    ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement(getClientArea().width / 100);
    horizontal.setPageIncrement(getClientArea().width);
    Rectangle imageBound = sourceImage.getBounds();
    int cw = getClientArea().width, ch = getClientArea().height;
    if (imageBound.width * sx > cw) {
        /* image is wider than client area */
        horizontal.setMaximum((int) (imageBound.width * sx));
        horizontal.setEnabled(true);
        if (((int) -tx) > horizontal.getMaximum() - cw)
            tx = -horizontal.getMaximum() + cw;
    } else {
        /* image is narrower than client area */
        horizontal.setEnabled(false);
        //center if too small.
        tx = (cw - imageBound.width * sx) / 2;
    }
    horizontal.setSelection((int) (-tx));
    horizontal.setThumb(getClientArea().width);
    ScrollBar vertical = getVerticalBar();
    vertical.setIncrement(getClientArea().height / 100);
    vertical.setPageIncrement(getClientArea().height);
    if (imageBound.height * sy > ch) {
        /* image is higher than client area */
        vertical.setMaximum((int) (imageBound.height * sy));
        vertical.setEnabled(true);
        if (((int) -ty) > vertical.getMaximum() - ch)
            ty = -vertical.getMaximum() + ch;
    } else {
        /* image is less higher than client area */
        vertical.setEnabled(false);
        //center if too small.
        ty = (ch - imageBound.height * sy) / 2;
    }
    vertical.setSelection((int) (-ty));
    vertical.setThumb(getClientArea().height);
    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    transform = af;
    redraw();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)315 Point (org.eclipse.swt.graphics.Point)173 Image (org.eclipse.swt.graphics.Image)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Color (org.eclipse.swt.graphics.Color)31 GC (org.eclipse.swt.graphics.GC)29 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)24 TableItem (org.eclipse.swt.widgets.TableItem)23 Event (org.eclipse.swt.widgets.Event)20 Menu (org.eclipse.swt.widgets.Menu)20 ArrayList (java.util.ArrayList)18 MenuItem (org.eclipse.swt.widgets.MenuItem)18 Listener (org.eclipse.swt.widgets.Listener)17 SelectionListener (org.eclipse.swt.events.SelectionListener)15 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Composite (org.eclipse.swt.widgets.Composite)14 GridData (org.eclipse.swt.layout.GridData)13 Shell (org.eclipse.swt.widgets.Shell)13 MouseEvent (org.eclipse.swt.events.MouseEvent)12 HashMap (java.util.HashMap)10