org.eclipse.swt.printing.PrintDialog Java Examples

The following examples show how to use org.eclipse.swt.printing.PrintDialog. 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: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
protected void print() {
	if (mainfolder.getSelection() != null && mainfolder.getSelection().getControl() instanceof TabTextView) {
		PrintDialog dialog = new PrintDialog(shell);
		PrinterData data = dialog.open();

		if (data != null) {
			StyledTextPrintOptions options = new StyledTextPrintOptions();
			options.footer = "\t\t<page>";
			options.jobName = "RepDev - " + mainfolder.getSelection().getText();
			options.printLineBackground = false;
			options.printTextFontStyle = true;
			options.printTextForeground = true;
			options.printTextBackground = true;

			Runnable runnable = ((TabTextView) mainfolder.getSelection().getControl()).getStyledText().print(new Printer(data), options);
			runnable.run();
		}
	}
}
 
Example #2
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 #3
Source File: TutorialExample2.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Prints a table of vital (haha) statistics about Matthew Hall.
 * 
 * @param args
 *            command-line parameters
 */
public static void main(String[] args) {
	// Show the print dialog
	Display display = new Display();
	Shell shell = new Shell(display);
	PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
	PrinterData printerData = dialog.open();
	shell.dispose();
	display.dispose();

	// Print the document to the printer the user selected.
	if (printerData != null) {
		PrintJob job = new PrintJob("TutorialExample2.java", createPrint());
		job.setMargins(72);
		PaperClips.print(job, printerData);
	}
}
 
Example #4
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 #5
Source File: TutorialExample1.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Prints the words, "Hello PaperClips!"
 * 
 * @param args
 *            command-line arguments.
 */
public static void main(String[] args) {
	// Create the document
	TextPrint text = new TextPrint("Hello PaperClips!");

	// Show the print dialog
	Display display = new Display();
	Shell shell = new Shell(display);
	PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
	PrinterData printerData = dialog.open();
	shell.dispose();
	display.dispose();

	// Print the document to the printer the user selected.
	if (printerData != null) {
		PrintJob job = new PrintJob("TutorialExample1.java", text);
		job.setMargins(72);
		PaperClips.print(job, printerData);
	}
}
 
Example #6
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 #7
Source File: PrintImageAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void run() {
    GraphicalViewer viewer;
    viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);

    final PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    final PrinterData data = dialog.open();

    if (data != null) {
        final Printer printer = new Printer(data);
        final PrintGraphicalViewerOperation op = new PrintERDiagramOperation(printer, viewer);

        op.run(getWorkbenchPart().getTitle());
    }
}
 
Example #8
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 #9
Source File: DiskExplorerTab.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Print the file listing for this disk. 
 */
protected void print() {
	PrintDialog printDialog = new PrintDialog(shell);
	PrinterData printerData = printDialog.open();
	if (printerData == null) {
		// cancelled
		return;
	}
	final Printer printer = new Printer(printerData);
	new Thread() {
		public void run() {
			new Printing(printer).run();
			printer.dispose();
		}
	}.start();
}
 
Example #10
Source File: Snippet6.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet6.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet6.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example #11
Source File: PrinterPreferencePage.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e){
	PrintDialog pd = new PrintDialog(getShell());
	PrinterData pdata = pd.open();
	if (pdata != null) {
		Text tx = (Text) ((Button) e.getSource()).getData();
		tx.setText(pdata.name);
		tx.setData(pdata);
	}
}
 
Example #12
Source File: ChartPrintJob.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #13
Source File: ChartPrintJob.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #14
Source File: ChartPrintJob.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #15
Source File: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #16
Source File: SwtUtil.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Display the Print dialog helper method. 
 */
public static Printer showPrintDialog(Control control) {
	PrintDialog dialog = new PrintDialog(control.getShell());
	PrinterData printerData = dialog.open();
	if (printerData == null) return null;
	return new Printer(printerData);
}
 
Example #17
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 #18
Source File: Snippet5.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet5.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet5.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example #19
Source File: AlignPrintExample.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Prints the BreakPrintExample to the default printer.
 * 
 * @param args
 *            command-line args
 */
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display, SWT.SHELL_TRIM);
	PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
	PrinterData printerData = dialog.open();
	shell.dispose();
	display.dispose();
	if (printerData != null)
		PaperClips.print(new PrintJob("AlignPrintExample.java",
				createPrint()), printerData);
}
 
Example #20
Source File: Snippet2.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet2.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet2.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example #21
Source File: ChartPrintJob.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #22
Source File: PrintDialogExample.java    From http4e with Apache License 2.0 4 votes vote down vote up
PrintDialogExample() {
  d = new Display();
  s = new Shell(d);
  s.setSize(400, 400);
  
  s.setText("A PrintDialog Example");
  s.setLayout(new FillLayout(SWT.VERTICAL));
  final Text t = new Text(s, SWT.BORDER | SWT.MULTI);
  final Button b = new Button(s, SWT.PUSH | SWT.BORDER);
  b.setText("Print");
  b.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
      PrintDialog printDialog = new PrintDialog(s, SWT.NONE);
      printDialog.setText("Print");
      PrinterData printerData = printDialog.open();
      if (!(printerData == null)) {
        Printer p = new Printer(printerData);
        p.startJob("PrintJob");
        p.startPage();
        Rectangle trim = p.computeTrim(0, 0, 0, 0);
        Point dpi = p.getDPI();
        int leftMargin = dpi.x + trim.x;
        int topMargin = dpi.y / 2 + trim.y;
        GC gc = new GC(p);
        Font font = gc.getFont();
        String printText = t.getText();
        Point extent = gc.stringExtent(printText);
        gc.drawString(printText, leftMargin, topMargin
            + font.getFontData()[0].getHeight());
        p.endPage();
        gc.dispose();
        p.endJob();
        p.dispose();
      }
    }
  });
  s.open();

  while (!s.isDisposed()) {
    if (!d.readAndDispatch())
      d.sleep();
  }
  d.dispose();
}
 
Example #23
Source File: PrintAction.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(final Event event) throws Exception {
    final PrintDialog dialog = new PrintDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 0);
    dialog.open();
}
 
Example #24
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 #25
Source File: SWTPrinterChooser.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void choose(UIPrinterChooserHandler selectionHandler) {
	PrintDialog dialog = new PrintDialog(this.window.getControl(), SWT.NULL);
	PrinterData printerData = dialog.open();
	
	selectionHandler.onSelectPrinter(printerData != null ? new SWTPrinter(printerData) : null); 
}
 
Example #26
Source File: SDPrintDialogUI.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Handle selection of print button.
 */
public void printButtonSelected() {
    PrintDialog printer = new PrintDialog(getShell());
    if (fAllPages.getSelection()) {
        printer.setScope(PrinterData.ALL_PAGES);
    }
    if (fCurrentPage.getSelection()) {
        printer.setScope(PrinterData.SELECTION);
    }
    if (fPageList.getSelection()) {
        printer.setScope(PrinterData.SELECTION);
    }
    if (fPageRange.getSelection()) {
        printer.setScope(PrinterData.PAGE_RANGE);
        fFrom = Integer.valueOf(fFromPage.getText()).intValue();
        fTo = Integer.valueOf(fToPage.getText()).intValue();
        printer.setStartPage(fFrom);
        printer.setEndPage(fTo);
    }

    PrinterData newPrinterData = printer.open();
    if (newPrinterData != null) {
        fPrinterData = newPrinterData;
    }
    updatePrinterStatus();

    if (printer.getScope() == PrinterData.ALL_PAGES) {
        fAllPages.setSelection(true);
        fCurrentPage.setSelection(false);
        fPageList.setSelection(false);
        fPageRange.setSelection(false);
        fHorPagesNum.setEnabled(false);
        fVertPagesNum.setEnabled(false);
    }
    if (printer.getScope() == PrinterData.PAGE_RANGE) {
        fAllPages.setSelection(false);
        fCurrentPage.setSelection(false);
        fPageList.setSelection(false);
        fPageRange.setSelection(true);
        fFromPage.setEnabled(true);
        fToPage.setEnabled(true);
        fFromPage.setText((Integer.valueOf(printer.getStartPage())).toString());
        fToPage.setText((Integer.valueOf(printer.getEndPage())).toString());
    }
    computeStepXY();
    fOverviewCanvas.redraw();
}
 
Example #27
Source File: PrintAction.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Event event) throws Exception {
    final PrintDialog dialog = new PrintDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 0);
    dialog.open();
}
 
Example #28
Source File: GridPrintCellClippingAllowClipFirstRow.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Display display = new Display();

	final Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setLayout(new GridLayout());
	shell.setSize(600, 600);

	final PrintJob job = new PrintJob(
			"GridPrintCellClippingAllowClipFirstRow", createPrint());

	Composite buttons = new Composite(shell, SWT.NONE);
	buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	buttons.setLayout(new RowLayout(SWT.HORIZONTAL));

	final Button prev = new Button(buttons, SWT.PUSH);
	prev.setText("<< Prev");
	prev.setEnabled(false);

	final Button next = new Button(buttons, SWT.PUSH);
	next.setText("Next >>");

	final Button print = new Button(buttons, SWT.PUSH);
	print.setText("Print..");

	final PrintPreview preview = new PrintPreview(shell, SWT.BORDER);
	preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	preview.setPrintJob(job);
	next.setEnabled(preview.getPageCount() > 1);

	Listener listener = event -> {
		int newIndex = preview.getPageIndex();
		if (event.widget == prev)
			newIndex--;
		else
			newIndex++;
		preview.setPageIndex(newIndex);
		prev.setEnabled(newIndex > 0);
		next.setEnabled(newIndex < preview.getPageCount() - 1);
	};
	prev.addListener(SWT.Selection, listener);
	next.addListener(SWT.Selection, listener);

	print.addListener(SWT.Selection, event -> {
		PrinterData printerData = new PrintDialog(shell).open();
		if (printerData != null) {
			PaperClips.print(job, printerData);
		}
	});

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();
}
 
Example #29
Source File: Snippet1.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet1.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print the table");

	final Table table = new Table(shell, SWT.BORDER);
	table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	// Set up Table widget with dummy data.
	for (int i = 0; i < 5; i++)
		new TableColumn(table, SWT.LEFT).setText("Column " + i);

	for (int row = 0; row < 100; row++) {
		TableItem item = new TableItem(table, SWT.NONE);
		for (int col = 0; col < 5; col++)
			item.setText(col, "Cell [" + col + ", " + row + "]");
	}

	table.setHeaderVisible(true);
	TableColumn[] columns = table.getColumns();
	for (int i = 0; i < columns.length; i++)
		columns[i].pack();

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null) {
			Print print = createPrint(table);
			PaperClips.print(
					new PrintJob("Snippet1.java", print).setMargins(72),
					printerData);
		}
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example #30
Source File: StyledTextPrintExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Executes the StyledTextPrint example.
 *
 * @param args
 *            the command line arguments.
 */
public static void main(String[] args) {
	final Display display = new Display();

	final Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setText("StyledTextPrintExample.java");
	shell.setLayout(new GridLayout());
	shell.setSize(600, 800);

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

	Composite buttonPanel = new Composite(shell, SWT.NONE);
	buttonPanel
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	buttonPanel.setLayout(new RowLayout(SWT.HORIZONTAL));

	final PrintPreview preview = new PrintPreview(shell, SWT.BORDER);

	Button prev = new Button(buttonPanel, SWT.PUSH);
	prev.setText("<< Prev");
	prev.addListener(SWT.Selection, event -> {
		preview.setPageIndex(Math.max(preview.getPageIndex() - 1, 0));
	});

	Button next = new Button(buttonPanel, SWT.PUSH);
	next.setText("Next >>");
	next.addListener(SWT.Selection, event -> {
		preview.setPageIndex(Math.min(preview.getPageIndex() + 1,
				preview.getPageCount() - 1));
	});

	Button print = new Button(buttonPanel, SWT.PUSH);
	print.setText("Print");
	print.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(job, printerData);
	});

	preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	preview.setFitHorizontal(true);
	preview.setFitVertical(true);
	preview.setPrintJob(job);

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}