int (final Graphics g, final PageFormat pageFormat, final int pageIndex) { myPerformActualDrawing = false; if (myProgress.isCanceled()) { return NO_SUCH_PAGE; } final Graphics2D g2d = (Graphics2D)g; if (myNumberOfPages < 0) { myProgress.setText(EditorBundle.message("print.file.calculating.number.of.pages.progress")); if (!calculateNumberOfPages(g2d, pageFormat)) { return NO_SUCH_PAGE; } } if (pageIndex >= myNumberOfPages) { return NO_SUCH_PAGE; } isPrintingPass = !isPrintingPass; if (!isPrintingPass) { while(++myPageIndex < pageIndex) { if (!printPageInReadAction(g2d, pageFormat, "print.skip.page.progress")) { return NO_SUCH_PAGE; } } return ReadAction.compute(() -> isValidRange(myRangeToPrint) ? PAGE_EXISTS : NO_SUCH_PAGE); } else { myPerformActualDrawing = true; printPageInReadAction(g2d, pageFormat, "print.file.page.progress"); return PAGE_EXISTS; } }