Search in sources :

Example 6 with PrinterData

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

the class Test_org_eclipse_swt_printing_Printer method test_isAutoScalable.

@Test
public void test_isAutoScalable() {
    PrinterData data = Printer.getDefaultPrinterData();
    // if there aren't any printers, don't do this test
    if (data == null)
        return;
    Printer printer = new Printer(data);
    boolean isAutoScalable = printer.isAutoScalable();
    assertFalse("SWT doesnot auto-scale for Printer devices", isAutoScalable);
    printer.dispose();
}
Also used : PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) Test(org.junit.Test)

Example 7 with PrinterData

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

the class Test_org_eclipse_swt_printing_Printer method test_getDPI.

@Test
public void test_getDPI() {
    PrinterData data = Printer.getDefaultPrinterData();
    // if there aren't any printers, don't do this test
    if (data == null)
        return;
    Printer printer = new Printer(data);
    Point dpi = printer.getDPI();
    assertTrue("dpi x or y is zero", dpi.x > 0 && dpi.y > 0);
    printer.dispose();
}
Also used : PrinterData(org.eclipse.swt.printing.PrinterData) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer) Test(org.junit.Test)

Example 8 with PrinterData

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

the class Test_org_eclipse_swt_printing_Printer method test_getPrinterList.

@Test
public void test_getPrinterList() {
    PrinterData data = Printer.getDefaultPrinterData();
    if (data == null) {
        /* If there aren't any printers, verify that the
		 * printer list is empty.
		 */
        PrinterData[] list = Printer.getPrinterList();
        if (list.length == 1) {
            if (SWT.getPlatform().equals("gtk")) {
                /* Even though there is no default printer data,
				 * on GTK it is still possible to have a print
				 * to file backend
				 */
                assertTrue(list[0].driver.equals("GtkPrintBackendFile"));
            }
        } else {
            assertTrue("printer list contains items even though there are no printers", list.length == 0);
        }
    } else {
        /* If there is at least a default printer, verify
		 * that the printer list is not empty.
		 */
        PrinterData[] list = Printer.getPrinterList();
        assertTrue("printer list is empty", list.length > 0);
    }
}
Also used : PrinterData(org.eclipse.swt.printing.PrinterData) Test(org.junit.Test)

Example 9 with PrinterData

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

the class ERDEditorPart method printDiagram.

public void printDiagram() {
    GraphicalViewer viewer = getGraphicalViewer();
    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    PrinterData data = dialog.open();
    if (data != null) {
        IFigure rootFigure = rootPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE_LAYERS);
        // EntityDiagramFigure diagramFigure = findFigure(rootFigure, EntityDiagramFigure.class);
        if (rootFigure != null) {
            PrintFigureOperation printOp = new PrintFigureOperation(new Printer(data), rootFigure);
            // Set print preferences
            IPreferenceStore store = ERDActivator.getDefault().getPreferenceStore();
            printOp.setPrintMode(store.getInt(ERDConstants.PREF_PRINT_PAGE_MODE));
            printOp.setPrintMargin(new Insets(store.getInt(ERDConstants.PREF_PRINT_MARGIN_TOP), store.getInt(ERDConstants.PREF_PRINT_MARGIN_LEFT), store.getInt(ERDConstants.PREF_PRINT_MARGIN_BOTTOM), store.getInt(ERDConstants.PREF_PRINT_MARGIN_RIGHT)));
            // Run print
            printOp.run("Print ER diagram");
        }
    }
// new PrintAction(this).run();
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) PrintFigureOperation(org.eclipse.draw2d.PrintFigureOperation) IFigure(org.eclipse.draw2d.IFigure)

Example 10 with PrinterData

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

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)

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