Java Code Examples for org.eclipse.swt.printing.Printer#startJob()

The following examples show how to use org.eclipse.swt.printing.Printer#startJob() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartPrintJob.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
protected void startPrintJob(Composite elementToPrint, 
        PrinterData printerData) {
    Printer printer = new Printer(printerData);
    try {
        printer.startJob(jobName);

        GC gc = new GC(printer);
        try {
            Rectangle printArea = getPrintableArea(printer, BORDER);
            printer.startPage();
            printComposite(elementToPrint, gc, printArea);
            printer.endPage();
        } finally {
            gc.dispose();
        }
        printer.endJob();

    } finally {
        printer.dispose();
    }
}
 
Example 2
Source File: SnippetBenchmarks.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private static void benchmarkSnippet8() {
	final Printer printer = new Printer();
	printer.startJob("benchmarkSnippet8");

	final PrintJob job = new PrintJob("Snippet8", Snippet8.createPrint());

	final GC gc = new GC(printer);
	new Benchmark().setName("getPageEnumeration").setRunCount(10).execute(
			new Runnable() {
				public void run() {
					PaperClips.getPageEnumeration(job, printer, gc)
							.nextPage();
				}
			});
	gc.dispose();

	new Benchmark().setName("getPages").setRunCount(10).execute(
			new Runnable() {
				public void run() {
					PaperClips.getPages(job, printer);
				}
			});

	printer.cancelJob();
	printer.dispose();
}
 
Example 3
Source File: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
protected void startPrintJob(Composite elementToPrint, 
        PrinterData printerData) {
    Printer printer = new Printer(printerData);
    try {
        printer.startJob(jobName);

        GC gc = new GC(printer);
        try {
            Rectangle printArea = getPrintableArea(printer, BORDER);
            printer.startPage();
            printComposite(elementToPrint, gc, printArea);
            printer.endPage();
        } finally {
            gc.dispose();
        }
        printer.endJob();

    } finally {
        printer.dispose();
    }
}
 
Example 4
Source File: ChartPrintJob.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
protected void startPrintJob(Composite elementToPrint, 
        PrinterData printerData) {
    Printer printer = new Printer(printerData);
    try {
        printer.startJob(jobName);

        GC gc = new GC(printer);
        try {
            Rectangle printArea = getPrintableArea(printer, BORDER);
            printer.startPage();
            printComposite(elementToPrint, gc, printArea);
            printer.endPage();
        } finally {
            gc.dispose();
        }
        printer.endJob();

    } finally {
        printer.dispose();
    }
}
 
Example 5
Source File: ChartPrintJob.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
protected void startPrintJob(Composite elementToPrint, 
        PrinterData printerData) {
    Printer printer = new Printer(printerData);
    try {
        printer.startJob(jobName);

        GC gc = new GC(printer);
        try {
            Rectangle printArea = getPrintableArea(printer, BORDER);
            printer.startPage();
            printComposite(elementToPrint, gc, printArea);
            printer.endPage();
        } finally {
            gc.dispose();
        }
        printer.endJob();

    } finally {
        printer.dispose();
    }
}
 
Example 6
Source File: ChartPrintJob.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
protected void startPrintJob(Composite elementToPrint, 
        PrinterData printerData) {
    Printer printer = new Printer(printerData);
    try {
        printer.startJob(jobName);

        GC gc = new GC(printer);
        try {
            Rectangle printArea = getPrintableArea(printer, BORDER);
            printer.startPage();
            printComposite(elementToPrint, gc, printArea);
            printer.endPage();
        } finally {
            gc.dispose();
        }
        printer.endJob();

    } finally {
        printer.dispose();
    }
}
 
Example 7
Source File: SnippetBenchmarks.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
static void benchmarkSnippets() {
	String[] names = {"Snippet2", "Snippet3", "Snippet4", "Snippet5",
			"Snippet6", "Snippet7"};
	Print[] documents = {Snippet2.createPrint(), Snippet3.createPrint(),
			Snippet4.createPrint(), Snippet5.createPrint(),
			Snippet6.createPrint(), Snippet7.createPrint()};
	final Printer printer = new Printer();
	printer.startJob("benchmarkSnippets");
	final int RUN_COUNT = 100;

	long total = 0;
	for (int i = 0; i < documents.length; i++) {
		final PrintJob job = new PrintJob(names[i], documents[i])
				.setMargins(108);
		total += new Benchmark().setRunCount(RUN_COUNT).setName(names[i])
				.execute(new Runnable() {
					public void run() {
						PaperClips.getPages(job, printer);
					}
				});
	}

	printer.cancelJob();
	printer.dispose();

	printFinalResult(total, total / (double) (RUN_COUNT * documents.length));
}
 
Example 8
Source File: SwtChartPrinter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static void printChart( Chart chart, Printer printer ) throws ChartException
{
	// create graphics context for printer
	GC gc = new GC(printer); 	
	
	PlatformConfig config = new PlatformConfig( );
	config.setProperty( "STANDALONE", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
	IDeviceRenderer render = ChartEngine.instance( config ).getRenderer("dv.SWT"); //$NON-NLS-1$
			
	render.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, gc);

	// The input size is in points (1 inch = 72 points)
	
	Bounds bo = BoundsImpl.create(0,0,300,300);
	
	// builds and computes preferred sizes of various chart components 
	IGenerator generator = ChartEngine.instance().getGenerator();
	GeneratedChartState state = generator.build(render.getDisplayServer(), chart, bo, null, null, null);

	printer.startJob("BIRT Sample Chart");//$NON-NLS-1$
	printer.startPage();	

	// set render properties
	generator.render(render, state); 

	printer.endPage();		
	printer.endJob();
}
 
Example 9
Source File: PaperClips.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static void startJob(Printer printer, String jobName) {
	if (!printer.startJob(jobName))
		error("Unable to start print job"); //$NON-NLS-1$
}
 
Example 10
Source File: AbstractChartView.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void print ()
{
    if ( Printer.getPrinterList ().length == 0 )
    {
        MessageDialog.openInformation ( this.shell, "No printer", "No installed printer could be found" );
        return;
    }

    final PrintDialog dlg = new PrintDialog ( this.shell, SWT.APPLICATION_MODAL );

    final PrinterData initialPd = Printer.getDefaultPrinterData ();
    initialPd.orientation = PrinterData.LANDSCAPE;
    dlg.setPrinterData ( initialPd );

    final PrinterData pd = dlg.open ();

    if ( pd != null )
    {
        final Printer printer = new Printer ( pd );
        final ResourceManager rm = new DeviceResourceManager ( printer );
        try
        {
            printer.startJob ( "Chart" );
            printer.startPage ();

            final GC gc = new GC ( printer );
            try
            {
                final SWTGraphics g = new SWTGraphics ( gc, rm );
                try
                {
                    this.viewer.getChartRenderer ().paint ( g );
                }
                finally
                {
                    g.dispose ();
                }
            }
            finally
            {
                gc.dispose ();
            }

            printer.endPage ();
            printer.endJob ();
        }
        finally
        {
            rm.dispose ();
            printer.dispose ();
        }
    }
}
 
Example 11
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printPatient(final Patient patient){
	PrinterData pd = getPrinterData("Etiketten"); //$NON-NLS-1$
	if (pd != null) {
		// 25.01.2010 patch tschaller: page orientation of printer
		// driver is not handled correctly (we always get porttrait
		// even when the printer settings have landscape stored)
		Integer iOrientation = -1;
		String sOrientation = CoreHub.localCfg.get("Drucker/Etiketten/Ausrichtung", null); //$NON-NLS-1$
		try {
			iOrientation = Integer.parseInt(sOrientation);
		} catch (NumberFormatException ex) {}
		if (iOrientation != -1)
			pd.orientation = iOrientation;
		Printer prn = new Printer(pd);
		if (prn.startJob(Messages.GlobalActions_PrintLabelJobName) == true) { //$NON-NLS-1$
			GC gc = new GC(prn);
			int y = 0;
			prn.startPage();
			gc.drawString(Messages.GlobalActions_PatientIDLabelText + patient.getPatCode(), 0,
				0); //$NON-NLS-1$
			FontMetrics fmt = gc.getFontMetrics();
			y += fmt.getHeight();
			String pers = patient.getPersonalia();
			gc.drawString(pers, 0, y);
			y += fmt.getHeight();
			gc.drawString(patient.getAnschrift().getEtikette(false, false), 0, y);
			y += fmt.getHeight();
			StringBuilder tel = new StringBuilder();
			tel.append(Messages.GlobalActions_PhoneHomeLabelText)
				.append(patient.get("Telefon1")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneWorkLabelText)
				.append(patient.get("Telefon2")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneMobileLabelText)
				.append(patient.get("Natel")); //$NON-NLS-1$ //$NON-NLS-2$
			gc.drawString(tel.toString(), 0, y);
			gc.dispose();
			prn.endPage();
			prn.endJob();
			prn.dispose();
		} else {
			MessageDialog.openError(mainWindow.getShell(),
				Messages.GlobalActions_PrinterErrorTitle,
				Messages.GlobalActions_PrinterErrorMessage); //$NON-NLS-1$ //$NON-NLS-2$
			
		}
	}
}
 
Example 12
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printPatientAuftragsnummer(final Patient patient){
	PrinterData pd = getPrinterData("Etiketten"); //$NON-NLS-1$
	if (pd != null) {
		// 25.01.2010 patch tschaller: page orientation of printer
		// driver is not handled correctly (we always get porttrait
		// even when the printer settings have landscape stored)
		Integer iOrientation = -1;
		String sOrientation = CoreHub.localCfg.get("Drucker/Etiketten/Ausrichtung", null); //$NON-NLS-1$
		try {
			iOrientation = Integer.parseInt(sOrientation);
		} catch (NumberFormatException ex) {}
		if (iOrientation != -1)
			pd.orientation = iOrientation;
		Printer prn = new Printer(pd);
		if (prn.startJob(Messages.GlobalActions_PrintLabelJobName) == true) { //$NON-NLS-1$
			GC gc = new GC(prn);
			int y = 0;
			prn.startPage();
			String pid = StringTool.addModulo10(patient.getPatCode()) + "-" //$NON-NLS-1$
				+ new TimeTool().toString(TimeTool.TIME_COMPACT);
			gc.drawString(Messages.GlobalActions_OrderID + ": " + pid, 0, 0); //$NON-NLS-1$ //$NON-NLS-2$
			FontMetrics fmt = gc.getFontMetrics();
			y += fmt.getHeight();
			String pers = patient.getPersonalia();
			gc.drawString(pers, 0, y);
			y += fmt.getHeight();
			gc.drawString(patient.getAnschrift().getEtikette(false, false), 0, y);
			y += fmt.getHeight();
			StringBuilder tel = new StringBuilder();
			tel.append(Messages.GlobalActions_PhoneHomeLabelText)
				.append(patient.get("Telefon1")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneWorkLabelText)
				.append(patient.get("Telefon2")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneMobileLabelText)
				.append(patient.get("Natel")); //$NON-NLS-1$ //$NON-NLS-2$
			gc.drawString(tel.toString(), 0, y);
			gc.dispose();
			prn.endPage();
			prn.endJob();
			prn.dispose();
		} else {
			MessageDialog.openError(mainWindow.getShell(),
				Messages.GlobalActions_PrinterErrorTitle,
				Messages.GlobalActions_PrinterErrorMessage); //$NON-NLS-1$ //$NON-NLS-2$
			
		}
	}
}
 
Example 13
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printAdr(final Kontakt k){
	// 25.01.2010 patch tschaller: there was always the printer selection
	// dialog. With printEtikette it wasn't so I copied the hardcoded string
	// from there
	// PrinterData pd =
	// getPrinterData(Messages.getString("GlobalActions.printersticker"));
	// //$NON-NLS-1$
	PrinterData pd = getPrinterData("Etiketten"); //$NON-NLS-1$
	if (pd != null) {
		// 25.01.2010 patch tschaller: page orientation of printer driver is
		// not handled correctly (we always get porttrait even when the
		// printer settings have landscape stored)
		Integer iOrientation = -1;
		String sOrientation = CoreHub.localCfg.get("Drucker/Etiketten/Ausrichtung", null); //$NON-NLS-1$
		try {
			iOrientation = Integer.parseInt(sOrientation);
		} catch (NumberFormatException ex) {}
		if (iOrientation != -1)
			pd.orientation = iOrientation;
		Printer prn = new Printer(pd);
		if (prn.startJob("Etikette drucken") == true) { //$NON-NLS-1$
			GC gc = new GC(prn);
			int y = 0;
			prn.startPage();
			FontMetrics fmt = gc.getFontMetrics();
			String pers = k.getPostAnschrift(true);
			String[] lines = pers.split("\n"); //$NON-NLS-1$
			for (String line : lines) {
				gc.drawString(line, 0, y);
				y += fmt.getHeight();
			}
			gc.dispose();
			prn.endPage();
			prn.endJob();
			prn.dispose();
		} else {
			MessageDialog.openError(mainWindow.getShell(),
				Messages.GlobalActions_PrinterErrorTitle,
				Messages.GlobalActions_PrinterErrorMessage); //$NON-NLS-1$ //$NON-NLS-2$
			
		}
		
	}
}