Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class SchedulePrinter
- Object
- 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.
Constructors
public SchedulePrinter(Scheduler scheduler) | A printer of the view and the dates scheduler is showing. |
public SchedulePrinter(Gantt gantt) | A printer of the whole of the project gantt shows. |
Methods
public void setPageSize(int widthPixels, int heightPixels) | Sets the size of a page in pixels. |
public int getPageWidth() | |
public int getPageHeight() | |
public String getTitle() | The line at the top of every page. |
public void setTitle(String title) | Sets the line at the top of every page; null or empty prints none. |
public boolean isPageNumbers() | Whether every page says which page of how many it is. |
public void setPageNumbers(boolean pageNumbers) | |
public int getPageCount() | The number of pages the view takes at this page size. |
public Image renderPage(int page) | Renders one page, counted from 0, left to right and then top to bottom. |
public Image renderImage(int maxSide) | Renders the whole view as one image, its headers once: the picture to share or to put in a report. |
public static boolean isPdfSupported() | Whether writePdf works here: it needs the platform to encode JPEG. |
public void writePdf(String path)
throws IOException | Writes every page into one PDF document at path, a path of FileSystemStorage. |
public void print(PrintResultListener listener) | Prints every page through the platform’s print dialog. |
Inherited methods
Constructor details
SchedulePrinter
public SchedulePrinter(Scheduler scheduler)scheduler is showing.SchedulePrinter
public SchedulePrinter(Gantt gantt)gantt shows.Method details
setPageSize
public void setPageSize(int widthPixels, int heightPixels)getPageWidth
public int getPageWidth()getPageHeight
public int getPageHeight()getTitle
public String getTitle()setTitle
public void setTitle(String title)isPageNumbers
public boolean isPageNumbers()setPageNumbers
public void setPageNumbers(boolean pageNumbers)getPageCount
public int getPageCount()Throws
IllegalStateException- if it is more than a print can sensibly be; zoom the view out or set a larger page
renderPage
public Image renderPage(int page)renderImage
public Image renderImage(int maxSide)renderPage is
the one for those.Throws
IllegalStateException- if either side would pass
maxSidepixels
isPdfSupported
public static boolean isPdfSupported()writePdf works here: it needs the platform to encode JPEG.writePdf
public void writePdf(String path)
throws IOExceptionpath, a path of
FileSystemStorage. 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 (see
isPdfSupported)
public void print(PrintResultListener listener)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
listenerPrintResultListener- told how it ended, on the EDT; may be null