Search in sources :

Example 96 with Point

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

the class AutoResizeColumnAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int column = CellEdgeDetectUtil.getColumnPositionToResize(natTable, clickPoint);
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(natTable, column, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeColumnsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeColumnsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 97 with Point

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

the class AutoResizeRowAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int row = CellEdgeDetectUtil.getRowPositionToResize(natTable, clickPoint);
    InitializeAutoResizeRowsCommand command = new InitializeAutoResizeRowsCommand(natTable, row, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeRowsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeRowsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 98 with Point

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

the class GridLayerPrinter method getPageCount.

/**
	 * Calculate number of horizontal and vertical pages needed
	 * to print the entire grid.
	 */
private Point getPageCount(Printer printer) {
    Rectangle gridArea = getTotalGridArea();
    Rectangle printArea = computePrintArea(printer);
    Point scaleFactor = computeScaleFactor(printer);
    int numOfHorizontalPages = gridArea.width / (printArea.width / scaleFactor.x);
    int numOfVerticalPages = gridArea.height / (printArea.height / scaleFactor.y);
    // Adjusting for 0 index
    return new Point(numOfHorizontalPages + 1, numOfVerticalPages + 1);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 99 with Point

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

the class GridLayerPrinter method setupPrinter.

private Printer setupPrinter(final Shell shell) {
    Printer defaultPrinter = new Printer();
    Point pageCount = getPageCount(defaultPrinter);
    defaultPrinter.dispose();
    final PrintDialog printDialog = new PrintDialog(shell);
    printDialog.setStartPage(1);
    printDialog.setEndPage(pageCount.x * pageCount.y);
    printDialog.setScope(PrinterData.ALL_PAGES);
    PrinterData printerData = printDialog.open();
    if (printerData == null) {
        return null;
    }
    return new Printer(printerData);
}
Also used : PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer)

Example 100 with Point

use of org.eclipse.swt.graphics.Point 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)

Aggregations

Point (org.eclipse.swt.graphics.Point)583 Rectangle (org.eclipse.swt.graphics.Rectangle)132 SelectionEvent (org.eclipse.swt.events.SelectionEvent)83 FormData (org.eclipse.swt.layout.FormData)82 Composite (org.eclipse.swt.widgets.Composite)81 GC (org.eclipse.swt.graphics.GC)79 GridData (org.eclipse.swt.layout.GridData)78 Button (org.eclipse.swt.widgets.Button)78 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 Control (org.eclipse.swt.widgets.Control)75 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)64 CLabel (org.eclipse.swt.custom.CLabel)53 GridLayout (org.eclipse.swt.layout.GridLayout)49 Node (org.talend.designer.core.ui.editor.nodes.Node)49 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)45 Event (org.eclipse.swt.widgets.Event)43 Label (org.eclipse.swt.widgets.Label)42 Text (org.eclipse.swt.widgets.Text)42 ArrayList (java.util.ArrayList)41 TableItem (org.eclipse.swt.widgets.TableItem)40