Search in sources :

Example 1 with Printer

use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.

the class JaretTablePrintDialog method createParameterArea.

protected void createParameterArea(Composite parent) {
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    parent.setLayout(gl);
    _repeatHeader = new Button(parent, SWT.CHECK);
    _repeatHeader.setSelection(_configuration.getRepeatHeader());
    _repeatHeader.setText("Repeat header");
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    _repeatHeader.setLayoutData(gd);
    final Label scaleText = new Label(parent, SWT.RIGHT);
    scaleText.setText(getScaleText());
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    scaleText.setLayoutData(gd);
    final Scale scale = new Scale(parent, SWT.HORIZONTAL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    scale.setLayoutData(gd);
    scale.setMaximum(1000);
    scale.setMinimum(10);
    scale.setSelection((int) (_configuration.getScale() * 100));
    scale.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent ev) {
            int val = scale.getSelection();
            double s = (double) val / 100.0;
            _configuration.setScale(s);
            scaleText.setText(getScaleText());
            updateConf();
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    _pagesLabel = new Label(parent, SWT.RIGHT);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    _pagesLabel.setLayoutData(gd);
    _printerData = _pdatas[_printerCombo.getSelectionIndex()];
    Printer printer = new Printer(_printerData);
    _tablePrinter.setPrinter(printer);
    Point pages = _tablePrinter.calculatePageCount(_configuration);
    printer.dispose();
    _pagesLabel.setText(getPagesText(pages));
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Scale(org.eclipse.swt.widgets.Scale) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer) JaretTablePrinter(de.jaret.util.ui.table.JaretTablePrinter) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with Printer

use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.

the class JaretTablePrintDialog method updateConf.

private void updateConf() {
    _configuration.setRepeatHeader(_repeatHeader.getSelection());
    Printer printer = new Printer(_printerData);
    _tablePrinter.setPrinter(printer);
    Point pages = _tablePrinter.calculatePageCount(_configuration);
    printer.dispose();
    _pagesLabel.setText(getPagesText(pages));
}
Also used : Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer) JaretTablePrinter(de.jaret.util.ui.table.JaretTablePrinter)

Example 3 with Printer

use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.

the class TableControlPanel method print.

public void print() {
    JaretTablePrinter jtp = new JaretTablePrinter(null, _table);
    JaretTablePrintDialog pDialog = new JaretTablePrintDialog(Display.getCurrent().getActiveShell(), null, jtp, null);
    pDialog.open();
    if (pDialog.getReturnCode() == Dialog.OK) {
        PrinterData pdata = pDialog.getPrinterData();
        JaretTablePrintConfiguration conf = pDialog.getConfiguration();
        Printer printer = new Printer(pdata);
        jtp.setPrinter(printer);
        jtp.print(conf);
        printer.dispose();
    }
    jtp.dispose();
}
Also used : JaretTablePrintDialog(de.jaret.util.ui.table.print.JaretTablePrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) JaretTablePrintConfiguration(de.jaret.util.ui.table.print.JaretTablePrintConfiguration) JaretTablePrinter(de.jaret.util.ui.table.JaretTablePrinter) Printer(org.eclipse.swt.printing.Printer) JaretTablePrinter(de.jaret.util.ui.table.JaretTablePrinter)

Example 4 with Printer

use of org.eclipse.swt.printing.Printer 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 5 with Printer

use of org.eclipse.swt.printing.Printer 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

Printer (org.eclipse.swt.printing.Printer)7 Point (org.eclipse.swt.graphics.Point)4 PrinterData (org.eclipse.swt.printing.PrinterData)4 JaretTablePrinter (de.jaret.util.ui.table.JaretTablePrinter)3 PrintDialog (org.eclipse.swt.printing.PrintDialog)3 JaretTablePrintConfiguration (de.jaret.util.ui.table.print.JaretTablePrintConfiguration)1 JaretTablePrintDialog (de.jaret.util.ui.table.print.JaretTablePrintDialog)1 Insets (org.eclipse.draw2d.geometry.Insets)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Transform (org.eclipse.swt.graphics.Transform)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Label (org.eclipse.swt.widgets.Label)1 Scale (org.eclipse.swt.widgets.Scale)1 Shell (org.eclipse.swt.widgets.Shell)1