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

The following examples show how to use org.eclipse.swt.printing.Printer#startPage() . 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: 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 3
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 4
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 5
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 6
Source File: PaperClips.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static void printPages(final Printer printer, final GC gc,
		final PrintPiece[] pages, final int startPage, final int endPage,
		final int collatedCopies, final int noncollatedCopies) {
	disposeUnusedPages(pages, startPage, endPage);

	Rectangle paperBounds = getPaperBounds(printer);
	final int x = paperBounds.x;
	final int y = paperBounds.y;

	try {
		for (int collated = 0; collated < collatedCopies; collated++) {
			for (int pageIndex = startPage; pageIndex <= endPage; pageIndex++) {
				for (int noncollated = 0; noncollated < noncollatedCopies; noncollated++) {
					if (printer.startPage()) {
						pages[pageIndex].paint(gc, x, y);
						pages[pageIndex].dispose();
						printer.endPage();
					} else {
						error("Unable to start page " + pageIndex); //$NON-NLS-1$
					}
				}
			}
		}
	} finally {
		PaperClipsUtil.dispose(pages);
	}
}
 
Example 7
Source File: PrinterFacade.java    From http4e with Apache License 2.0 5 votes vote down vote up
private void printText( Printer printer){
   printer.startPage();
   wordBuffer = new StringBuilder();
   x = leftMargin;
   y = topMargin;
   index = 0;
   end = textToPrint.length();
   while (index < end) {
      char c = textToPrint.charAt(index);
      index++;
      if (c != 0) {
         if (c == 0x0a || c == 0x0d) {
            if (c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a) {
               index++; // if this is cr-lf, skip the lf
            }
            printWordBuffer(printer);
            newline(printer);
         } else {
            if (c != '\t') {
               wordBuffer.append(c);
            }
            if (Character.isWhitespace(c)) {
               printWordBuffer(printer);
               if (c == '\t') {
                  x += tabWidth;
               }
            }
         }
      }
   }
   if (y + lineHeight <= bottomMargin) {
      printer.endPage();
   }
}
 
Example 8
Source File: PrinterFacade.java    From http4e with Apache License 2.0 5 votes vote down vote up
private void newline( Printer printer){
   x = leftMargin;
   y += lineHeight;
   if (y + lineHeight > bottomMargin) {
      printer.endPage();
      if (index + 1 < end) {
         y = topMargin;
         printer.startPage();
      }
   }
}
 
Example 9
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 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$
			
		}
		
	}
}