Search in sources :

Example 16 with Rectangle

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

the class ImageViewCanvas method fitCanvas.

/**
	 * Fit the image onto the canvas
	 */
public void fitCanvas() {
    if (sourceImage == null)
        return;
    Rectangle imageBound = sourceImage.getBounds();
    Rectangle destRect = getClientArea();
    double sx = (double) destRect.width / (double) imageBound.width;
    double sy = (double) destRect.height / (double) imageBound.height;
    double s = Math.min(sx, sy);
    double dx = 0.5 * destRect.width;
    double dy = 0.5 * destRect.height;
    centerZoom(dx, dy, s, new AffineTransform());
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform)

Example 17 with Rectangle

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

the class ImageViewCanvas method zoomIn.

/**
	 * Zoom in around the center of client Area.
	 */
public void zoomIn() {
    if (sourceImage == null)
        return;
    Rectangle rect = getClientArea();
    int w = rect.width, h = rect.height;
    double dx = ((double) w) / 2;
    double dy = ((double) h) / 2;
    centerZoom(dx, dy, ZOOMIN_RATE, transform);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 18 with Rectangle

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

the class ImageViewUtil method transformRect.

/**
     * Given an arbitrary rectangle, get the rectangle with the given transform.
     * The result rectangle is positive width and positive height.
     *
     * @param af  AffineTransform
     * @param src source rectangle
     * @return rectangle after transform with positive width and height
     */
public static Rectangle transformRect(AffineTransform af, Rectangle src) {
    Rectangle dest = new Rectangle(0, 0, 0, 0);
    src = absRect(src);
    Point p1 = new Point(src.x, src.y);
    p1 = transformPoint(af, p1);
    dest.x = p1.x;
    dest.y = p1.y;
    dest.width = (int) (src.width * af.getScaleX());
    dest.height = (int) (src.height * af.getScaleY());
    return dest;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 19 with Rectangle

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

the class DatabaseNavigatorTree method renameItem.

private void renameItem(final TreeItem item) {
    // Clean up any previous editor control
    disposeOldEditor();
    if (item.isDisposed()) {
        return;
    }
    final DBNNode node = (DBNNode) item.getData();
    Text text = new Text(treeViewer.getTree(), SWT.BORDER);
    text.setText(node.getNodeName());
    text.selectAll();
    text.setFocus();
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            disposeOldEditor();
        }
    });
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR) {
                Text text = (Text) treeEditor.getEditor();
                final String newName = text.getText();
                disposeOldEditor();
                treeViewer.getTree().setFocus();
                if (!CommonUtils.isEmpty(newName) && !newName.equals(node.getNodeName())) {
                    NavigatorHandlerObjectRename.renameNode(DBeaverUI.getActiveWorkbenchWindow(), node, newName);
                }
            } else if (e.keyCode == SWT.ESC) {
                disposeOldEditor();
                treeViewer.getTree().setFocus();
            }
        }
    });
    final Rectangle itemBounds = item.getBounds(0);
    final Rectangle treeBounds = treeViewer.getTree().getBounds();
    treeEditor.minimumWidth = Math.max(itemBounds.width, 50);
    treeEditor.minimumWidth = Math.min(treeEditor.minimumWidth, treeBounds.width - (itemBounds.x - treeBounds.x) - item.getImageBounds(0).width - 4);
    treeEditor.setEditor(text, item, 0);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 20 with Rectangle

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

the class SmileyCellRenderer method draw.

/**
     * {@inheritDoc}
     */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    Object value = column.getValue(row);
    if (value != null) {
        saveGCAttributes(gc);
        int val = ((Integer) value).intValue();
        _brModel.setValue(val);
        calcSmileFactor();
        if (_forceCircle) {
            int a = Math.min(rect.width, rect.height);
            Rectangle nrect = new Rectangle(0, 0, a, a);
            nrect.x = rect.x + (rect.width - a) / 2;
            nrect.y = rect.y + (rect.height - a) / 2;
            rect = nrect;
        }
        int width = rect.width;
        int height = rect.height;
        int offx = rect.x;
        int offy = rect.y;
        float foffx = (float) offx;
        float foffy = (float) offy;
        int lineWidth = height / 40;
        if (!_colorChange) {
            gc.setBackground(_neutral);
        } else {
            if (_currentValue >= 0) {
                // positive
                gc.setBackground(calcColor(_positive, printing));
            } else {
                // negative
                gc.setBackground(calcColor(_negative, printing));
            }
        }
        Device device = printing ? _printer : Display.getCurrent();
        Path p = new Path(device);
        p.addArc(foffx + 0 + lineWidth / 2, foffy + 0 + lineWidth / 2, width - 1 - lineWidth, height - 1 - lineWidth, 0, 360);
        gc.fillPath(p);
        gc.setForeground(_black);
        gc.setLineWidth(lineWidth);
        gc.drawPath(p);
        p.dispose();
        // eyes
        int y = height / 3;
        int x1 = width / 3;
        int x2 = width - width / 3;
        int r = width / 30;
        // eyes have a minimal size
        if (r == 0) {
            r = 1;
        }
        gc.setBackground(_black);
        gc.fillOval(offx + x1 - r, offy + y - r, 2 * r, 2 * r);
        gc.fillOval(offx + x2 - r, offy + y - r, 2 * r, 2 * r);
        // eye brows
        if (_eyeBrows) {
            gc.setLineWidth(lineWidth / 2);
            int ebWidth = width / 10;
            int yDist = height / 13;
            int yOff = (int) (_currentValue * (double) height / 30);
            int xShift = (int) (_currentValue * (double) width / 90);
            p = new Path(device);
            p.moveTo(foffx + x1 - ebWidth / 2 + xShift, foffy + y - yDist + yOff);
            p.lineTo(foffx + x1 + ebWidth / 2 - xShift, foffy + y - yDist - yOff);
            gc.drawPath(p);
            p.dispose();
            p = new Path(device);
            p.moveTo(foffx + x2 - ebWidth / 2 + xShift, foffy + y - yDist - yOff);
            p.lineTo(foffx + x2 + ebWidth / 2 - xShift, foffy + y - yDist + yOff);
            gc.drawPath(p);
            p.dispose();
        }
        // mouth
        gc.setLineWidth(lineWidth);
        x1 = (int) (width / 4.5);
        x2 = width - x1;
        y = height - height / 3;
        int midX = width / 2;
        int offset = (int) (_currentValue * (double) height / 3);
        p = new Path(Display.getCurrent());
        p.moveTo(foffx + x1, foffy + y);
        p.quadTo(foffx + midX, foffy + y + offset, foffx + x2, foffy + y);
        gc.drawPath(p);
        p.dispose();
        restoreGCAttributes(gc);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle)

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