Search in sources :

Example 16 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project nebula.widgets.nattable by eclipse.

the class LayerPrinter method setupPrinter.

/**
 * Opens the PrintDialog to let the user specify the printer and print
 * configurations to use.
 *
 * @param shell
 *            The Shell which should be the parent for the PrintDialog
 * @return The selected printer with the print configuration made by the
 *         user.
 */
private Printer setupPrinter(final Shell shell) {
    final PrintDialog printDialog = new PrintDialog(shell);
    printDialog.setStartPage(1);
    printDialog.setScope(PrinterData.ALL_PAGES);
    Integer orientation = this.printTargets.get(0).configRegistry.getConfigAttribute(PrintConfigAttributes.DEFAULT_PAGE_ORIENTATION, DisplayMode.NORMAL);
    if (orientation != null) {
        printDialog.getPrinterData().orientation = orientation;
    }
    if (this.calculatePageCount) {
        // trigger content based auto-resizing
        if (LayerPrinter.this.preRender) {
            for (PrintTarget target : LayerPrinter.this.printTargets) {
                AutoResizeHelper.autoResize(target.layer, target.configRegistry);
            }
        }
        // the whole table
        for (PrintTarget target : this.printTargets) {
            target.layer.doCommand(new TurnViewportOffCommand());
        }
        try {
            Printer defaultPrinter = new Printer();
            int pageCount = getPageCount(defaultPrinter);
            defaultPrinter.dispose();
            printDialog.setEndPage(pageCount);
        } finally {
            // turn viewport on
            for (PrintTarget target : this.printTargets) {
                target.layer.doCommand(new TurnViewportOnCommand());
            }
        }
    }
    PrinterData printerData = printDialog.open();
    if (printerData == null) {
        return null;
    }
    return new Printer(printerData);
}
Also used : TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Point(org.eclipse.swt.graphics.Point)

Example 17 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project SIMVA-SoS by SESoS.

the class ChartPrintJob method print.

/**
 * Prints the specified element.
 *
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        // Anwender hat abgebrochen.
        return;
    }
    startPrintJob(elementToPrint, printerData);
}
Also used : PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData)

Example 18 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project dbeaver by serge-rider.

the class ConsoleTextPresentation method printResultSet.

@Override
public void printResultSet() {
    final Shell shell = getControl().getShell();
    StyledTextPrintOptions options = new StyledTextPrintOptions();
    options.printTextFontStyle = true;
    options.printTextForeground = true;
    if (Printer.getPrinterList().length == 0) {
        UIUtils.showMessageBox(shell, "No printers", "Printers not found", SWT.ICON_ERROR);
        return;
    }
    final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
    dialog.setPrinterData(fgPrinterData);
    final PrinterData data = dialog.open();
    if (data != null) {
        final Printer printer = new Printer(data);
        final Runnable styledTextPrinter = text.print(printer, options);
        new // $NON-NLS-1$
        Thread(// $NON-NLS-1$
        "Printing") {

            public void run() {
                styledTextPrinter.run();
                printer.dispose();
            }
        }.start();
        /*
             * FIXME:
			 * 	Should copy the printer data to avoid threading issues,
			 *	but this is currently not possible, see http://bugs.eclipse.org/297957
			 */
        fgPrinterData = data;
        fgPrinterData.startPage = 1;
        fgPrinterData.endPage = 1;
        fgPrinterData.scope = PrinterData.ALL_PAGES;
        fgPrinterData.copyCount = 1;
    }
}
Also used : StyledTextPrintOptions(org.eclipse.swt.custom.StyledTextPrintOptions) Shell(org.eclipse.swt.widgets.Shell) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer)

Example 19 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project dbeaver by serge-rider.

the class PlainTextPresentation method printResultSet.

@Override
public void printResultSet() {
    final Shell shell = getControl().getShell();
    StyledTextPrintOptions options = new StyledTextPrintOptions();
    options.printTextFontStyle = true;
    options.printTextForeground = true;
    if (Printer.getPrinterList().length == 0) {
        UIUtils.showMessageBox(shell, "No printers", "Printers not found", SWT.ICON_ERROR);
        return;
    }
    final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
    dialog.setPrinterData(fgPrinterData);
    final PrinterData data = dialog.open();
    if (data != null) {
        final Printer printer = new Printer(data);
        final Runnable styledTextPrinter = text.print(printer, options);
        new // $NON-NLS-1$
        Thread(// $NON-NLS-1$
        "Printing") {

            public void run() {
                styledTextPrinter.run();
                printer.dispose();
            }
        }.start();
        /*
             * FIXME:
			 * 	Should copy the printer data to avoid threading issues,
			 *	but this is currently not possible, see http://bugs.eclipse.org/297957
			 */
        fgPrinterData = data;
        fgPrinterData.startPage = 1;
        fgPrinterData.endPage = 1;
        fgPrinterData.scope = PrinterData.ALL_PAGES;
        fgPrinterData.copyCount = 1;
    }
}
Also used : StyledTextPrintOptions(org.eclipse.swt.custom.StyledTextPrintOptions) Shell(org.eclipse.swt.widgets.Shell) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer)

Example 20 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project dbeaver by dbeaver.

the class ConsoleTextPresentation method printResultSet.

@Override
public void printResultSet() {
    final Shell shell = getControl().getShell();
    StyledTextPrintOptions options = new StyledTextPrintOptions();
    options.printTextFontStyle = true;
    options.printTextForeground = true;
    if (Printer.getPrinterList().length == 0) {
        UIUtils.showMessageBox(shell, "No printers", "Printers not found", SWT.ICON_ERROR);
        return;
    }
    final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
    dialog.setPrinterData(fgPrinterData);
    final PrinterData data = dialog.open();
    if (data != null) {
        final Printer printer = new Printer(data);
        final Runnable styledTextPrinter = text.print(printer, options);
        new // $NON-NLS-1$
        Thread(// $NON-NLS-1$
        "Printing") {

            public void run() {
                styledTextPrinter.run();
                printer.dispose();
            }
        }.start();
        /*
             * FIXME:
			 * 	Should copy the printer data to avoid threading issues,
			 *	but this is currently not possible, see http://bugs.eclipse.org/297957
			 */
        fgPrinterData = data;
        fgPrinterData.startPage = 1;
        fgPrinterData.endPage = 1;
        fgPrinterData.scope = PrinterData.ALL_PAGES;
        fgPrinterData.copyCount = 1;
    }
}
Also used : StyledTextPrintOptions(org.eclipse.swt.custom.StyledTextPrintOptions) Shell(org.eclipse.swt.widgets.Shell) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer)

Aggregations

PrintDialog (org.eclipse.swt.printing.PrintDialog)24 PrinterData (org.eclipse.swt.printing.PrinterData)21 Printer (org.eclipse.swt.printing.Printer)19 Point (org.eclipse.swt.graphics.Point)6 Shell (org.eclipse.swt.widgets.Shell)6 Insets (org.eclipse.draw2d.geometry.Insets)4 StyledTextPrintOptions (org.eclipse.swt.custom.StyledTextPrintOptions)4 GC (org.eclipse.swt.graphics.GC)4 Image (org.eclipse.swt.graphics.Image)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 IFigure (org.eclipse.draw2d.IFigure)3 PrintFigureOperation (org.eclipse.draw2d.PrintFigureOperation)3 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 PrintGraphicalViewerOperation (org.eclipse.gef.print.PrintGraphicalViewerOperation)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 FontData (org.eclipse.swt.graphics.FontData)2 ImageLoader (org.eclipse.swt.graphics.ImageLoader)2