Search in sources :

Example 1 with Transform

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

the class GridLayerPrinter method print.

public void print(final Shell shell) {
    final Printer printer = setupPrinter(shell);
    if (printer == null) {
        return;
    }
    setGridLayerSize(printer.getPrinterData());
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            if (printer.startJob("NatTable")) {
                final Rectangle printerClientArea = computePrintArea(printer);
                final Point scaleFactor = computeScaleFactor(printer);
                final Point pageCount = getPageCount(printer);
                GC gc = new GC(printer);
                // Print pages Left to Right and then Top to Down
                int currentPage = 1;
                for (int verticalPageNumber = 0; verticalPageNumber < pageCount.y; verticalPageNumber++) {
                    for (int horizontalPageNumber = 0; horizontalPageNumber < pageCount.x; horizontalPageNumber++) {
                        // Calculate bounds for the next page
                        Rectangle printBounds = new Rectangle((printerClientArea.width / scaleFactor.x) * horizontalPageNumber, ((printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y) * verticalPageNumber, printerClientArea.width / scaleFactor.x, (printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / 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 nor 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);
                            printGrid(gc, printBounds);
                            printFooter(gc, currentPage, printBounds);
                            printer.endPage();
                            printerTransform.dispose();
                        }
                        currentPage++;
                    }
                }
                printer.endJob();
                gc.dispose();
                printer.dispose();
            }
            restoreGridLayerState();
        }

        private void printGrid(GC gc, Rectangle printBounds) {
            gridLayer.getLayerPainter().paintLayer(gridLayer, gc, 0, 0, printBounds, configRegistry);
        }

        private void printFooter(GC gc, int totalPageCount, Rectangle printBounds) {
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
            gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
            gc.drawLine(printBounds.x, printBounds.y + printBounds.height + 10, printBounds.x + printBounds.width, printBounds.y + printBounds.height + 10);
            gc.drawText("Page " + totalPageCount, printBounds.x, printBounds.y + printBounds.height + 15);
            // Approximate width of the date string: 140
            gc.drawText(footerDate, printBounds.x + printBounds.width - 140, printBounds.y + printBounds.height + 15);
        }
    });
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 2 with Transform

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

the class ImageTransformTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_club.jpg");
    Transform transform = new Transform(device);
    // scale image
    transform.scale(scaleSpinnerX.getSelection() / 100f, scaleSpinnerY.getSelection() / 100f);
    // translate image
    transform.translate(translateSpinnerX.getSelection(), translateSpinnerY.getSelection());
    // rotate on center of image
    Rectangle rect = image.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotateSpinner.getSelection());
    transform.translate(-rect.width / 2, -rect.height / 2);
    if (invertButton.getSelection()) {
        transform.invert();
    }
    gc.setTransform(transform);
    gc.drawImage(image, 0, 0);
    transform.dispose();
    image.dispose();
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Transform(org.eclipse.swt.graphics.Transform)

Example 3 with Transform

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

the class PathTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (fillColor.getBgColor1() != null) {
        gc.setBackground(fillColor.getBgColor1());
    } else if (fillColor.getBgImage() != null) {
        pattern = new Pattern(device, fillColor.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.setLineWidth(5);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    // arc
    Path path = new Path(device);
    path.addArc((width - 250) / 2, (height - 400) / 2, 500, 400, 90, 180);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    // shape on left
    Transform transform = new Transform(device);
    transform.translate((width - 250) / 4, height / 2 - 150);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.cubicTo(-150, 100, 150, 200, 0, 300);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    // shape on right
    path = new Path(device);
    path.moveTo(3 * (width - 250) / 4 - 25 + 250, height / 2);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 - 200);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 + 50);
    path.lineTo(3 * (width - 250) / 4 - 25 + 250, height / 2 + 150);
    path.lineTo(3 * (width - 250) / 4 + 25 + 250, height / 2 + 50);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    if (pattern != null)
        pattern.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform)

Example 4 with Transform

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

the class CardsTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    if (ace_club == null) {
        ace_club = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_club.jpg");
        ace_spade = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_spade.jpg");
        ace_diamond = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_diamond.jpg");
        ace_hearts = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_hearts.jpg");
    }
    clubWidth = ace_club.getBounds().width;
    diamondWidth = ace_diamond.getBounds().width;
    heartWidth = ace_hearts.getBounds().width;
    spadeHeight = ace_spade.getBounds().height;
    Transform transform;
    // ace of clubs
    transform = new Transform(device);
    transform.translate((int) movClubX, (int) movClubY);
    transform.scale(scaleWidth, scaleWidth);
    // rotate on center of image
    Rectangle rect = ace_club.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotationAngle);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_club, 0, 0);
    // ace of diamonds
    transform = new Transform(device);
    transform.translate((int) movDiamondX, (int) movDiamondY);
    transform.scale(scaleWidth, scaleWidth);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_diamond, 0, 0);
    // ace of hearts
    transform = new Transform(device);
    transform.translate(movHeart, height / 2);
    transform.scale(heartScale, 0.5f * scale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_hearts, 0, 0);
    // ace of spades
    transform = new Transform(device);
    transform.translate(movSpade, movSpade);
    transform.scale(0.5f * scale, spadeScale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_spade, 0, 0);
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Transform(org.eclipse.swt.graphics.Transform)

Example 5 with Transform

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

the class CurvesSWTTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Font font = new Font(device, getPlatformFont(), 16, SWT.ITALIC);
    gc.setFont(font);
    gc.setLineWidth(2);
    Transform transform;
    // ----- letter s -----
    sXPos = 4 * width / 16;
    sYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(sXPos, sYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
    Path path = new Path(device);
    path.cubicTo(-200 + sDiffX1, 50 + sDiffY1, 200 + sDiffX2, 100 + sDiffY2, 0, 150);
    gc.drawPath(path);
    path.dispose();
    // draw the spline points
    gc.setTransform(null);
    gc.drawRectangle(sRect1.x + (int) sXPos, sRect1.y + (int) sYPos, sRect1.width, sRect1.height);
    gc.drawRectangle(sRect2.x + (int) sXPos, sRect2.y + (int) sYPos, sRect2.width, sRect2.height);
    // ----- letter w -----
    wXPos = 6 * width / 16;
    wYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(wXPos, wYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 110, -50, true);
    path = new Path(device);
    path.quadTo(100 + wDiffX1, 300 + wDiffY1, 100, 0);
    path.quadTo(100 + wDiffX2, 300 + wDiffY2, 200, 0);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(wRect1.x + (int) wXPos, wRect1.y + (int) wYPos, wRect1.width, wRect1.height);
    gc.drawRectangle(wRect2.x + (int) wXPos, wRect2.y + (int) wYPos, wRect2.width, wRect2.height);
    // ----- top of letter t -----
    topTXPos = 11 * width / 16;
    topTYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(topTXPos, topTYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_YELLOW));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -50, true);
    path = new Path(device);
    path.cubicTo(33 + tTopDiffX1, -20 + tTopDiffY1, 66 + tTopDiffX2, 20 + tTopDiffY2, 100, 0);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(tTopRect1.x + (int) topTXPos, tTopRect1.y + (int) topTYPos, tTopRect1.width, tTopRect1.height);
    gc.drawRectangle(tTopRect2.x + (int) topTXPos, tTopRect2.y + (int) topTYPos, tTopRect2.width, tTopRect2.height);
    // ----- vertical bar of letter t -----
    botTXPos = 12 * width / 16;
    botTYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(botTXPos, botTYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
    path = new Path(device);
    path.cubicTo(-33 + tBotDiffX1, 50 + tBotDiffY1, 33 + tBotDiffX2, 100 + tBotDiffY2, 0, 150);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(tBottomRect1.x + (int) botTXPos, tBottomRect1.y + (int) botTYPos, tBottomRect1.width, tBottomRect1.height);
    gc.drawRectangle(tBottomRect2.x + (int) botTXPos, tBottomRect2.y + (int) botTYPos, tBottomRect2.width, tBottomRect2.height);
    font.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Font(org.eclipse.swt.graphics.Font)

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