Search in sources :

Example 21 with PrinterData

use of org.eclipse.swt.printing.PrinterData in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_printing_PrinterData method test_toString.

@Test
public void test_toString() {
    PrinterData data = new PrinterData();
    assertNotNull(data.toString());
    assertTrue(data.toString().length() > 0);
}
Also used : PrinterData(org.eclipse.swt.printing.PrinterData) Test(org.junit.Test)

Example 22 with PrinterData

use of org.eclipse.swt.printing.PrinterData in project org.csstudio.display.builder by kasemir.

the class PrintAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    // Get snapshot. Disposed at end of printing
    final Image snapshot = media_pool.get(ImageConverter.convertToSWT(graph.getImage()));
    if (snapshot == null) {
        Logger.getLogger(getClass().getName()).fine("Cannot obtain image");
        return;
    }
    // Printer GUI
    final PrintDialog dlg = new PrintDialog(shell);
    PrinterData data = dlg.open();
    if (data == null) {
        Logger.getLogger(getClass().getName()).fine("Cannot obtain printer");
        snapshot.dispose();
        return;
    }
    // At least on Linux, access to SWT Printer must be on UI thread.
    // Printing in other thread can deadlock with UI thread.
    final Printer printer = new Printer(data);
    try {
        if (!printer.startJob("Data Browser")) {
            Logger.getLogger(getClass().getName()).fine("Cannot start print job");
            return;
        }
        try {
            // Printer page info
            final Rectangle area = printer.getClientArea();
            final Rectangle trim = printer.computeTrim(0, 0, 0, 0);
            final Point dpi = printer.getDPI();
            // Compute layout
            final Rectangle image_rect = snapshot.getBounds();
            // Leave one inch on each border.
            // (copied the computeTrim stuff from an SWT example.
            // Really no clue...)
            final int left_right = dpi.x + trim.x;
            final int top_bottom = dpi.y + trim.y;
            final int printed_width = area.width - 2 * left_right;
            // Try to scale height according to on-screen aspect ratio.
            final int max_height = area.height - 2 * top_bottom;
            final int printed_height = Math.min(max_height, image_rect.height * printed_width / image_rect.width);
            // Print one page
            printer.startPage();
            final GC gc = new GC(printer);
            gc.drawImage(snapshot, 0, 0, image_rect.width, image_rect.height, left_right, top_bottom, printed_width, printed_height);
            printer.endPage();
        } finally {
            printer.endJob();
        }
    } finally {
        printer.dispose();
        snapshot.dispose();
    }
}
Also used : PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Printer(org.eclipse.swt.printing.Printer) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 23 with PrinterData

use of org.eclipse.swt.printing.PrinterData in project jbosstools-hibernate by jbosstools.

the class PrintDiagramViewerAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
public void run() {
    GraphicalViewer viewer;
    viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class);
    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    PrinterData data = dialog.open();
    if (data != null) {
        PrintDiagramViewerOperation op = new PrintDiagramViewerOperation(new Printer(data), viewer);
        DiagramViewer dv = (DiagramViewer) getWorkbenchPart();
        op.setZoom(dv.getZoom());
        if (Math.abs(dv.getZoom() - dv.getFitHeightZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_HEIGHT);
        } else if (Math.abs(dv.getZoom() - dv.getFitWidthZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_WIDTH);
        } else if (Math.abs(dv.getZoom() - dv.getFitPageZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_PAGE);
        } else {
            op.setPrintMode(PrintGraphicalViewerOperation.TILE);
        }
        op.run(getWorkbenchPart().getTitle());
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) PrintDiagramViewerOperation(org.jboss.tools.hibernate.ui.diagram.print.PrintDiagramViewerOperation)

Example 24 with PrinterData

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

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

Aggregations

PrinterData (org.eclipse.swt.printing.PrinterData)26 Printer (org.eclipse.swt.printing.Printer)22 PrintDialog (org.eclipse.swt.printing.PrintDialog)16 Test (org.junit.Test)9 Point (org.eclipse.swt.graphics.Point)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 Shell (org.eclipse.swt.widgets.Shell)4 Insets (org.eclipse.draw2d.geometry.Insets)3 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 StyledTextPrintOptions (org.eclipse.swt.custom.StyledTextPrintOptions)3 GC (org.eclipse.swt.graphics.GC)3 Image (org.eclipse.swt.graphics.Image)3 IFigure (org.eclipse.draw2d.IFigure)2 PrintFigureOperation (org.eclipse.draw2d.PrintFigureOperation)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ImageLoader (org.eclipse.swt.graphics.ImageLoader)2 JaretTablePrinter (de.jaret.util.ui.table.JaretTablePrinter)1 JaretTablePrintConfiguration (de.jaret.util.ui.table.print.JaretTablePrintConfiguration)1 JaretTablePrintDialog (de.jaret.util.ui.table.print.JaretTablePrintDialog)1 File (java.io.File)1