Class SchedulePrinter
Prints a Scheduler or a Gantt chart, or exports it as images or a PDF.
What is on screen is a window onto the view: a week scrolls under its header, a project runs off the right edge. A printer lays the whole of it out on pages instead. The view is painted off screen at the page's size, one page of content at a time, and every page gets the headers that belong to its part: the days or the time scale across the top, the hours, the resources or the task table down the side.
Scheduler scheduler = new Scheduler();
SchedulePrinter printer = new SchedulePrinter(scheduler);
printer.setTitle("This week");
printer.print(new PrintResultListener() {
public void onResult(PrintResult result) {
if (result.isFailed()) {
ToastBar.showErrorMessage(result.getError());
}
}
});
Pages run left to right, then top to bottom. getPageCount, renderPage
and renderImage give the pages to an application that would sooner
share or store them, and writePdf writes them as one document.
A scheduler prints the view and the dates it is showing; a Gantt chart prints the whole project at the zoom it is showing, so zooming out before printing is how a long project is fitted to fewer pages. The resource load under a chart is not printed.
A page is an image as large as the page, so rendering is done a page at a time and the pages are not kept. Everything here runs on the EDT.
-
Constructor Summary
ConstructorsConstructorDescriptionSchedulePrinter(Gantt gantt) A printer of the whole of the projectganttshows.SchedulePrinter(Scheduler scheduler) A printer of the view and the datesscheduleris showing. -
Method Summary
Modifier and TypeMethodDescriptionintThe number of pages the view takes at this page size.intintgetTitle()The line at the top of every page.booleanWhether every page says which page of how many it is.static booleanWhetherwritePdfworks here: it needs the platform to encode JPEG.voidprint(PrintResultListener listener) Prints every page through the platform's print dialog.renderImage(int maxSide) Renders the whole view as one image, its headers once: the picture to share or to put in a report.renderPage(int page) Renders one page, counted from 0, left to right and then top to bottom.voidsetPageNumbers(boolean pageNumbers) voidsetPageSize(int widthPixels, int heightPixels) Sets the size of a page in pixels.voidSets the line at the top of every page; null or empty prints none.voidWrites every page into one PDF document atpath, a path ofFileSystemStorage.
-
Constructor Details
-
SchedulePrinter
A printer of the view and the datesscheduleris showing. -
SchedulePrinter
A printer of the whole of the projectganttshows.
-
-
Method Details
-
setPageSize
public void setPageSize(int widthPixels, int heightPixels) Sets the size of a page in pixels. The default is a landscape sheet in the proportions of A4. Text and rows keep the size they have on screen, so a larger page holds more of the view and prints it smaller. -
getPageWidth
public int getPageWidth() -
getPageHeight
public int getPageHeight() -
getTitle
The line at the top of every page. Unless one is set, a scheduler prints the range its toolbar names and a chart prints none. -
setTitle
Sets the line at the top of every page; null or empty prints none. -
isPageNumbers
public boolean isPageNumbers()Whether every page says which page of how many it is. On by default; a single page is never numbered. -
setPageNumbers
public void setPageNumbers(boolean pageNumbers) -
getPageCount
public int getPageCount()The number of pages the view takes at this page size.
Throws
IllegalStateException: if it is more than a print can sensibly be; zoom the view out or set a larger page
-
renderPage
Renders one page, counted from 0, left to right and then top to bottom. -
renderImage
Renders the whole view as one image, its headers once: the picture to share or to put in a report. It is as large as the content, so a long project at a close zoom is a very large image;
renderPageis the one for those.Throws
IllegalStateException: if either side would passmaxSidepixels
-
isPdfSupported
public static boolean isPdfSupported()WhetherwritePdfworks here: it needs the platform to encode JPEG. -
writePdf
Writes every page into one PDF document at
path, a path ofFileSystemStorage. Each page of the document is a picture of the page, so its text cannot be selected or searched.Throws
IOException: if the file cannot be written, or the platform cannot encode JPEG (seeisPdfSupported)
- Throws:
IOException
-
print
Prints every page through the platform's print dialog.
The pages go to the printer as one PDF document. On a platform that cannot write one, a single page is printed as an image, and more than one is reported as a failure, since the platform prints one image at a time and a dialog per page is not a print.
Parameters
listener: told how it ended, on the EDT; may be null
-