/** * Executes the GridPrint example. * * @param args the command line arguments. */ public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setText("GridPrintVerticalAlignmentExample.java"); shell.setLayout(new GridLayout()); shell.setSize(600, 800); final PrintJob job = new PrintJob("GridPrintVerticalAlignmentExample.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, new Listener() { public void handleEvent(Event event) { preview.setPageIndex(Math.max(preview.getPageIndex() - 1, 0)); } }); Button next = new Button(buttonPanel, SWT.PUSH); next.setText("Next >>"); next.addListener( SWT.Selection, new Listener() { public void handleEvent(Event 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, new Listener() { public void handleEvent(Event event) { PaperClips.print(job, new 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(); }
public Control createControl(Composite parent) { Composite shell = new Composite(parent, SWT.None); final PrintJob job = new PrintJob("GridPrintVerticalAlignmentExample.java", createPrint()); shell.setLayout(new org.eclipse.swt.layout.GridLayout()); 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, new Listener() { public void handleEvent(Event event) { preview.setPageIndex(Math.max(preview.getPageIndex() - 1, 0)); } }); Button next = new Button(buttonPanel, SWT.PUSH); next.setText("Next >>"); next.addListener( SWT.Selection, new Listener() { public void handleEvent(Event 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, new Listener() { public void handleEvent(Event event) { PaperClips.print(job, new PrinterData()); } }); preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); preview.setFitHorizontal(true); preview.setFitVertical(true); preview.setPrintJob(job); return shell; }