PrintPreview pp = new PrintPreview(VisualDCT.this, pi.getPageable(), "VisualDCT Print Preview"+addedToTitle); pp.setLocationRelativeTo(VisualDCT.this); pp.setVisible(true);
PrinterJob printerJob = PrinterJob.getPrinterJob(); printerJob.setJobName(getTitle()); printerJob.setPageable(pi.getPageable());  if (lastPrintService != null) { try { printerJob.setPrintService(lastPrintService); } catch (PrinterException e) { handleException(e); } }  if(!printerJob.printDialog(printRequestAttributeSet)) { lastPrintService = printerJob.getPrintService(); return; }  lastPrintService = printerJob.getPrintService();  int pageFormatOrientation = PageFormat.PORTRAIT;  OrientationRequested orientationRequested = (OrientationRequested) printRequestAttributeSet.get(OrientationRequested.class);  if(orientationRequested != null) { if(orientationRequested.equals(OrientationRequested.LANDSCAPE)) pageFormatOrientation = PageFormat.LANDSCAPE; else if(orientationRequested.equals(OrientationRequested.REVERSE_LANDSCAPE)) pageFormatOrientation = PageFormat.REVERSE_LANDSCAPE; }  pi.getPageable().getPageFormat(0).setOrientation(pageFormatOrientation);  MediaPrintableArea mediaPrintableArea = (MediaPrintableArea) printRequestAttributeSet.get(MediaPrintableArea.class);  Paper paper = pi.getPageable().getPageFormat(0).getPaper();  paper.setImageableArea(mediaPrintableArea.getX(MediaPrintableArea.INCH) * 72.0, mediaPrintableArea.getY(MediaPrintableArea.INCH) * 72.0, mediaPrintableArea.getWidth(MediaPrintableArea.INCH) * 72, mediaPrintableArea.getHeight(MediaPrintableArea.INCH) * 72);  pi.getPageable().getPageFormat(0).setPaper(paper);   com.cosylab.vdct.graphics.printing.Page.setPageFormat(pi.getPageable().getPageFormat(0));  setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
			public void run() {				PrintPreview pp = new PrintPreview(VisualDCT.this, pi.getPageable(), "VisualDCT Print Preview"+addedToTitle);				pp.setLocationRelativeTo(VisualDCT.this);				pp.setVisible(true);				Thread.yield();				pp.loadPreview();			}