Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Transform


     * Sets the current transform.
     *
     * @param t  the transform.
     */
    public void setTransform(AffineTransform t) {
        Transform transform = getSwtTransformFromPool(t);
        this.gc.setTransform(transform);
    }
View Full Code Here


     * Concatenates the specified transform to the existing transform.
     *
     * @param t  the transform.
     */
    public void transform(AffineTransform t) {
        Transform swtTransform = new Transform(this.gc.getDevice());
        this.gc.getTransform(swtTransform);
        swtTransform.multiply(getSwtTransformFromPool(t));
        this.gc.setTransform(swtTransform);
        swtTransform.dispose();
    }
View Full Code Here

     *
     * @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();
    }
View Full Code Here

     * Applies a rotation transform.
     *
     * @param theta  the angle of rotation.
     */
    public void rotate(double theta) {
        Transform swtTransform = new Transform(this.gc.getDevice());
        this.gc.getTransform(swtTransform);
        swtTransform.rotate((float) (theta * 180 / Math.PI));
        this.gc.setTransform(swtTransform);
        swtTransform.dispose();
    }
View Full Code Here

     *
     * @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();
    }
View Full Code Here

     *
     * @param shearX  the x-factor.
     * @param shearY  the y-factor.
     */
    public void shear(double shearX, double shearY) {
        Transform swtTransform = new Transform(this.gc.getDevice());
        this.gc.getTransform(swtTransform);
        Transform shear = new Transform(this.gc.getDevice(), 1f, (float) shearX,
                (float) shearY, 1f, 0, 0);
        swtTransform.multiply(shear);
        this.gc.setTransform(swtTransform);
        swtTransform.dispose();
    }
View Full Code Here

     *
     * @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);
        }
View Full Code Here

                                        / scaleFactor.y);

                        if (shouldPrint(printer.getPrinterData(), currentPage)) {
                            printer.startPage();

                            Transform printerTransform = new Transform(printer);

                            // Adjust for DPI difference between display and
                            // printer
                            printerTransform
                                    .scale(scaleFactor.x, scaleFactor.y);

                            // Adjust for margins
                            printerTransform.translate(printerClientArea.x
                                    / scaleFactor.x, printerClientArea.y
                                    / scaleFactor.y);

                            // Grid will not automatically print the pages at
                            // the left margin.
                            // Example: page 1 will print at x = 0, page 2 at x
                            // = 100, page 3 at x = 300
                            // Adjust to print from the left page margin. i.e x
                            // = 0
                            printerTransform.translate(-1 * printBounds.x, -1
                                    * printBounds.y);
                            gc.setTransform(printerTransform);

                            printLayer(gc, printBounds);

                            printFooter(gc, currentPage, printBounds);

                            printer.endPage();
                            printerTransform.dispose();
                        }
                        currentPage++;
                    }
                }

View Full Code Here

                if (numberOfNewLines == 1) {
                    int contentWidth = Math.min(getLengthFromCache(gc, text),
                            rectangle.height);

                    Transform transform = new Transform(gc.getDevice());
                    if (!isRotateClockwise()) {
                        transform.rotate(-90f);

                        int xOffset = -rectangle.x
                                + (-contentWidth - rectangle.y)
                                - CellStyleUtil.getVerticalAlignmentPadding(
                                        cellStyle, rectangle, contentWidth);
                        int yOffset = rectangle.x
                                + -rectangle.y
                                + CellStyleUtil.getHorizontalAlignmentPadding(
                                        cellStyle, rectangle, contentHeight)
                                + spacing;

                        transform.translate(xOffset, yOffset);
                    } else {
                        transform.rotate(90f);

                        int horizontalPadding = CellStyleUtil
                                .getHorizontalAlignmentPadding(cellStyle,
                                        rectangle, contentHeight);
                        if (horizontalPadding != 0) {
                            horizontalPadding += gc.getFontMetrics()
                                    .getLeading();
                        }

                        int xOffset = rectangle.y
                                - rectangle.x
                                + CellStyleUtil.getVerticalAlignmentPadding(
                                        cellStyle, rectangle, contentWidth);
                        int yOffset = -contentHeight - rectangle.y
                                - rectangle.x - horizontalPadding + spacing;

                        transform.translate(xOffset, yOffset);
                    }

                    gc.setTransform(transform);

                    gc.drawText(text, rectangle.x, rectangle.y,
                            SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);

                    if (underline || strikethrough) {
                        // check and draw underline and strikethrough separately
                        // so it is possible to combine both
                        if (underline) {
                            // y = start y of text + font height
                            // - half of the font descent so the underline is
                            // between the baseline and the bottom
                            int underlineY = rectangle.y + fontHeight
                                    - (gc.getFontMetrics().getDescent() / 2);
                            gc.drawLine(rectangle.x, underlineY, rectangle.x
                                    + gc.textExtent(text).x, underlineY);
                        }

                        if (strikethrough) {
                            // y = start y of text + half of font height +
                            // ascent so lower case characters are
                            // also strikethrough
                            int strikeY = rectangle.y + (fontHeight / 2)
                                    + (gc.getFontMetrics().getLeading() / 2);
                            gc.drawLine(rectangle.x, strikeY,
                                    rectangle.x + gc.textExtent(text).x,
                                    strikeY);
                        }
                    }
                } else {
                    // draw every line by itself because of the alignment,
                    // otherwise the whole text
                    // is always aligned right
                    int lineAdjustment = 0;
                    String[] lines = text.split("\n"); //$NON-NLS-1$
                    for (String line : lines) {
                        int lineContentWidth = Math.min(
                                getLengthFromCache(gc, line), rectangle.height);

                        Transform transform = new Transform(gc.getDevice());

                        if (!isRotateClockwise()) {
                            transform.rotate(-90f);

                            int xOffset = -rectangle.x
                                    + (-lineContentWidth - rectangle.y)
                                    - CellStyleUtil
                                            .getVerticalAlignmentPadding(
                                                    cellStyle, rectangle,
                                                    lineContentWidth);
                            int yOffset = rectangle.x
                                    + -rectangle.y
                                    + lineAdjustment
                                    + CellStyleUtil
                                            .getHorizontalAlignmentPadding(
                                                    cellStyle, rectangle,
                                                    contentHeight) + spacing;

                            transform.translate(xOffset, yOffset);
                        } else {
                            transform.rotate(90f);

                            int horizontalPadding = CellStyleUtil
                                    .getHorizontalAlignmentPadding(cellStyle,
                                            rectangle, contentHeight);
                            if (horizontalPadding != 0) {
                                horizontalPadding += gc.getFontMetrics()
                                        .getLeading();
                            }

                            int xOffset = rectangle.y
                                    - rectangle.x
                                    + CellStyleUtil
                                            .getVerticalAlignmentPadding(
                                                    cellStyle, rectangle,
                                                    lineContentWidth);
                            int yOffset = -contentHeight - rectangle.y
                                    - rectangle.x + lineAdjustment
                                    - horizontalPadding + spacing;

                            transform.translate(xOffset, yOffset);
                        }

                        gc.setTransform(transform);

                        gc.drawText(line, rectangle.x, rectangle.y,
View Full Code Here

    gc.setLineWidth(2);

    // ----- cube -----

    Transform transform = new Transform(device);
    transform.translate(width / 4 - size, height / 4 + -upDownValue);
    gc.setTransform(transform);

    gc.setLineStyle(SWT.LINE_DOT);

    // fill in left face
    gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
    gc.fillPolygon(new int[] { 0, 0, size / 3, -size / 2, size / 3, size / 2, 0, size });

    gc.setLineStyle(SWT.LINE_SOLID);

    // square
    gc.drawRectangle(0, 0, size, size);

    // next 3 solid lines
    gc.drawLine(0, 0, size / 3, -size / 2); // left
    gc.drawLine(size, 0, 4 * size / 3, -size / 2); // middle
    gc.drawLine(size, size, 4 * size / 3, size / 2); // right

    // 2 furthest solid lines
    gc.drawLine(size / 3, -size / 2, 4 * size / 3, -size / 2); // horizontal
    gc.drawLine(4 * size / 3, size / 2, 4 * size / 3, -size / 2); // vertical

    // 3 dotted lines
    gc.setLineStyle(SWT.LINE_DOT);
    gc.drawLine(0, size, size / 3, size / 2);
    gc.drawLine(size / 3, -size / 2, size / 3, size / 2);
    gc.drawLine(4 * size / 3, size / 2, size / 3, size / 2);

    // fill right side of cube
    gc.setBackground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.fillPolygon(new int[] { size, 0, 4 * size / 3, -size / 2, 4 * size / 3, size / 2, size, size });

    transform.dispose();

    // ----- pyramid -----

    transform = new Transform(device);
    transform.translate(width / 2 + size / 2, height / 4 + size + upDownValue);
    gc.setTransform(transform);

    // fill back of pyramid
    gc.fillPolygon(new int[] { size / 3, -size / 2, 6 * size / 10, -5 * size / 4, 4 * size / 3, -size / 2 });

    // fill left side of pyramid
    gc.setBackground(device.getSystemColor(SWT.COLOR_GREEN));
    gc.fillPolygon(new int[] { 0, 0, 6 * size / 10, -5 * size / 4, size / 3, -size / 2 });

    // select solid line style
    gc.setLineStyle(SWT.LINE_SOLID);

    // 2 solid lines of base
    gc.drawLine(0, 0, size, 0);
    gc.drawLine(size, 0, 4 * size / 3, -size / 2);

    // 3 solid lines of pyramid
    gc.drawLine(0, 0, 6 * size / 10, -5 * size / 4);
    gc.drawLine(size, 0, 6 * size / 10, -5 * size / 4);
    gc.drawLine(4 * size / 3, -size / 2, 6 * size / 10, -5 * size / 4);

    // select dot line style
    gc.setLineStyle(SWT.LINE_DOT);

    // 3 dotted lines
    gc.drawLine(0, 0, size / 3, -size / 2); // left
    gc.drawLine(size / 3, -size / 2, 6 * size / 10, -5 * size / 4); // to top of pyramid
    gc.drawLine(4 * size / 3, -size / 2, size / 3, -size / 2); // right

    transform.dispose();

    // ----- rectangular prism -----

    transform = new Transform(device);
    transform.translate(width / 2 + upDownValue, height / 2 + size);
    gc.setTransform(transform);

    // fill bottom
    gc.setBackground(device.getSystemColor(SWT.COLOR_BLUE));
    gc.fillPolygon(new int[] { 0, size, size / 3, size / 2, 7 * size / 3, size / 2, 2 * size, size });

    // select solid line style
    gc.setLineStyle(SWT.LINE_SOLID);

    gc.drawRectangle(0, 0, 2 * size, size);

    // next 3 solid lines
    gc.drawLine(0, 0, size / 3, -size / 2); // left
    gc.drawLine(2 * size, 0, 7 * size / 3, -size / 2); // middle
    gc.drawLine(2 * size, size, 7 * size / 3, size / 2); // right

    // 2 furthest solid lines
    gc.drawLine(size / 3, -size / 2, 7 * size / 3, -size / 2); // horizontal
    gc.drawLine(7 * size / 3, size / 2, 7 * size / 3, -size / 2); // vertical

    // 3 dotted lines
    gc.setLineStyle(SWT.LINE_DASHDOTDOT);
    gc.drawLine(0, size, size / 3, size / 2);
    gc.drawLine(size / 3, -size / 2, size / 3, size / 2);
    gc.drawLine(7 * size / 3, size / 2, size / 3, size / 2);

    // fill top
    gc.setBackground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.fillPolygon(new int[] { 0, 0, size / 3, -size / 2, 7 * size / 3, -size / 2, 2 * size, 0 });

    transform.dispose();

    // ----- triangular shape -----
    transform = new Transform(device);
    transform.translate(width / 4 - size - upDownValue, height / 2 + size + upDownValue);
    gc.setTransform(transform);

    // fill back of shape (top left)
    gc.setBackground(device.getSystemColor(SWT.COLOR_YELLOW));
    gc.fillPolygon(new int[] { 0, 0, size / 2, -size, size / 2, -size / 3 });

    // fill back of shape (bottom right)
    gc.fillPolygon(new int[] { size, 0, size / 2, size, size / 2, -size / 3 });

    // select solid line style
    gc.setLineStyle(SWT.LINE_SOLID);

    // solid lines of bottom triangle
    gc.drawLine(0, 0, size / 2, size);
    gc.drawLine(size, 0, size / 2, size);

    // solid lines of top triangle
    gc.drawLine(0, 0, size / 2, -size);
    gc.drawLine(size, 0, size / 2, -size);

    // solid lines on top
    gc.drawLine(0, 0, size / 2, -size / 3);
    gc.drawLine(size, 0, size / 2, -size / 3);
    gc.drawLine(size / 2, -size / 3, size / 2, size);
    gc.drawLine(size / 2, -size / 3, size / 2, -size);

    transform.dispose();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.Transform

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.