Search in sources :

Example 11 with Transform

use of org.eclipse.swt.graphics.Transform in project netxms by netxms.

the class Title method drawVerticalTitle.

/**
 * Draws the vertical title.
 *
 * @param gc
 *            The graphics context
 */
private void drawVerticalTitle(GC gc) {
    boolean useStyleRanges = styleRanges != null;
    int textWidth;
    int textHeight;
    if (useStyleRanges) {
        textWidth = textLayout.getBounds().width;
        textHeight = textLayout.getBounds().height;
    } else {
        textWidth = gc.textExtent(text).x;
        textHeight = gc.textExtent(text).y;
    }
    // create image to draw text
    Image image = new Image(Display.getCurrent(), textWidth, textHeight);
    GC tmpGc = new GC(image);
    if (useStyleRanges) {
        textLayout.draw(tmpGc, 0, 0);
    } else {
        tmpGc.setForeground(getForeground());
        tmpGc.setBackground(getBackground());
        tmpGc.setFont(getFont());
        tmpGc.drawText(text, 0, 0);
    }
    // set transform to rotate
    Transform transform = new Transform(gc.getDevice());
    transform.translate(0, textWidth);
    transform.rotate(270);
    gc.setTransform(transform);
    // draw the image on the rotated graphics context
    int height = getSize().y;
    int y = (int) (height / 2d - textWidth / 2d);
    if (y < 0) {
        y = 0;
    }
    gc.drawImage(image, -y, 0);
    // dispose resources
    tmpGc.dispose();
    transform.dispose();
    image.dispose();
}
Also used : Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 12 with Transform

use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method scale.

/**
 * Applies a scale transform.
 *
 * @param scaleX  the scale factor along the x-axis.
 * @param scaleY  the scale factor along the y-axis.
 */
public void scale(double scaleX, double scaleY) {
    Transform swtTransform = new Transform(this.gc.getDevice());
    this.gc.getTransform(swtTransform);
    swtTransform.scale((float) scaleX, (float) scaleY);
    this.gc.setTransform(swtTransform);
    swtTransform.dispose();
}
Also used : Transform(org.eclipse.swt.graphics.Transform) AffineTransform(java.awt.geom.AffineTransform)

Example 13 with Transform

use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method translate.

/**
 * Applies a translation.
 *
 * @param x  the translation along the x-axis.
 * @param y  the translation along the y-axis.
 */
public void translate(int x, int y) {
    Transform swtTransform = new Transform(this.gc.getDevice());
    this.gc.getTransform(swtTransform);
    swtTransform.translate(x, y);
    this.gc.setTransform(swtTransform);
    swtTransform.dispose();
}
Also used : Transform(org.eclipse.swt.graphics.Transform) AffineTransform(java.awt.geom.AffineTransform)

Example 14 with Transform

use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method getSwtTransformFromPool.

/**
 * Internal method to convert a AWT transform object into
 * a SWT transform resource. If a corresponding SWT transform
 * instance is already in the pool, it will be used
 * instead of creating a new one. This is used in
 * {@link #setTransform()} for instance.
 *
 * @param awtTransform The AWT transform to convert.
 * @return A SWT transform instance.
 */
private Transform getSwtTransformFromPool(AffineTransform awtTransform) {
    Transform t = (Transform) this.transformsPool.get(awtTransform);
    if (t == null) {
        t = new Transform(this.gc.getDevice());
        double[] matrix = new double[6];
        awtTransform.getMatrix(matrix);
        t.setElements((float) matrix[0], (float) matrix[1], (float) matrix[2], (float) matrix[3], (float) matrix[4], (float) matrix[5]);
        addToResourcePool(t);
        this.transformsPool.put(awtTransform, t);
    }
    return t;
}
Also used : Transform(org.eclipse.swt.graphics.Transform) AffineTransform(java.awt.geom.AffineTransform)

Example 15 with Transform

use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method getTransform.

/**
 * Returns the current transform.
 *
 * @return The current transform.
 */
public AffineTransform getTransform() {
    Transform swtTransform = new Transform(this.gc.getDevice());
    this.gc.getTransform(swtTransform);
    AffineTransform awtTransform = toAwtTransform(swtTransform);
    swtTransform.dispose();
    return awtTransform;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) Transform(org.eclipse.swt.graphics.Transform) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

Transform (org.eclipse.swt.graphics.Transform)34 Device (org.eclipse.swt.graphics.Device)11 Path (org.eclipse.swt.graphics.Path)10 Point (org.eclipse.swt.graphics.Point)9 Font (org.eclipse.swt.graphics.Font)7 Image (org.eclipse.swt.graphics.Image)7 Rectangle (org.eclipse.swt.graphics.Rectangle)7 AffineTransform (java.awt.geom.AffineTransform)6 GC (org.eclipse.swt.graphics.GC)6 Pattern (org.eclipse.swt.graphics.Pattern)6 Color (org.eclipse.swt.graphics.Color)3 Cursor (org.eclipse.swt.graphics.Cursor)2 FontData (org.eclipse.swt.graphics.FontData)2 Region (org.eclipse.swt.graphics.Region)2 TextLayout (org.eclipse.swt.graphics.TextLayout)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)1 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)1 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)1 SWTException (org.eclipse.swt.SWTException)1 Printer (org.eclipse.swt.printing.Printer)1