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

The following examples show how to use org.eclipse.swt.printing.Printer#dispose() . 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: 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 2
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 3
Source File: GridLayerPrinter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: TableControlPanel.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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();

}
 
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: GridLayerPrinter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 7
Source File: TableControlPanel.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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();

}
 
Example 8
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 9
Source File: PrintAction.java    From http4e with Apache License 2.0 6 votes vote down vote up
void print( Shell shell){
   PrintDialog printDialog = new PrintDialog(shell, SWT.NONE);
   printDialog.setText("Print Http Packets");
   PrinterData printerData = printDialog.open();
   if (!(printerData == null)) {
      final Printer printer = new Printer(printerData);
      
      Thread printingThread = new Thread("Printing") {
         public void run(){
            try {
               new PrinterFacade(getTextToPrint(), printer).print();
            } catch (Exception e) {
               ExceptionHandler.handle(e);
            } finally {
               printer.dispose();
            }
         }
      };
      printingThread.start();         
   }
}
 
Example 10
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 11
Source File: GanttChartPrinter.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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.
 */
protected Printer setupPrinter(final Shell shell) {
	//Calculate the number of pages by using the full image
	//This is because on setup we want to show how many pages the full print would be
	Printer defaultPrinter = new Printer();
	Point pageCount = getFullPageCount(defaultPrinter);
	defaultPrinter.dispose();

	final PrintDialog printDialog = new PrintDialog(shell);
	
	PrinterData data = new PrinterData();
	data.orientation = PrinterData.LANDSCAPE;
	data.startPage = 1;
	data.endPage = pageCount.x * pageCount.y;
	data.scope = PrinterData.ALL_PAGES;
	printDialog.setPrinterData(data);

	PrinterData printerData = printDialog.open();
	if (printerData == null){
		return null;
	}
	return new Printer(printerData);
}
 
Example 12
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 13
Source File: PrintCommand.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void printQuery ( final AbstractQueryBuffer query )
{
    final List<ValueInformation> vis = query.getValueInformation ();
    final Map<String, List<Double>> values = query.getValues ();

    final PrintDialog dlg = new PrintDialog ( getWorkbenchWindow ().getShell () );

    final PrinterData printerData = dlg.open ();

    if ( printerData == null )
    {
        return;
    }

    printerData.orientation = PrinterData.LANDSCAPE;

    final Printer printer = new Printer ( printerData );

    try
    {
        final PrintProcessor processor = new PrintProcessor ( vis, values );
        processor.print ( printer );
    }
    finally
    {
        printer.dispose ();
    }
}
 
Example 14
Source File: ImageCaptureExample.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Demonstrate capturing the pages of a print to in-memory images.
 * 
 * @param args
 *            command-line arguments (ignored)
 */
public static void main(String[] args) {
	Display display = new Display();
	Point displayDPI = display.getDPI();
	display.dispose();

	Printer printer = new Printer(new PrinterData());
	Point printerDPI = printer.getDPI();

	try {
		PrintJob job = new PrintJob("ImageCapture.java", createPrint());

		PrintPiece[] pages = PaperClips.getPages(job, printer);

		ImageLoader imageLoader = new ImageLoader();
		for (int i = 0; i < pages.length; i++) {
			PrintPiece page = pages[i];
			Point pageSize = page.getSize();
			pageSize.x = pageSize.x * displayDPI.x / printerDPI.x;
			pageSize.y = pageSize.y * displayDPI.y / printerDPI.y;
			ImageData pageImage = captureImageData(printer, page, pageSize);

			// Do something with the image
			pageImage.scanlinePad = 1;

			imageLoader.data = new ImageData[] { pageImage };
			imageLoader.save(getImageName(i), SWT.IMAGE_JPEG);
		}

	} finally {
		printer.dispose();
	}
}
 
Example 15
Source File: JaretTablePrintDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 16
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 17
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$
			
		}
		
	}
}
 
Example 18
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 19
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 20
Source File: PaperClips.java    From nebula with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Prints the print job to the given printer. This method constructs a
 * Printer, forwards to {@link #print(PrintJob, Printer)}, and disposes the
 * printer before returning.
 * 
 * @param printJob
 *            the print job.
 * @param printerData
 *            the PrinterData of the selected printer.
 */
public static void print(PrintJob printJob, PrinterData printerData) {
	Printer printer = new Printer(printerData);
	try {
		print(printJob, printer);
	} finally {
		printer.dispose();
	}
}