Class SchedulePrinter

java.lang.Object
com.codename1.ui.scheduler.SchedulePrinter

public final class SchedulePrinter extends Object

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 Details

    • SchedulePrinter

      public SchedulePrinter(Scheduler scheduler)
      A printer of the view and the dates scheduler is showing.
    • SchedulePrinter

      public SchedulePrinter(Gantt gantt)
      A printer of the whole of the project gantt shows.
  • 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

      public String 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

      public void setTitle(String title)
      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

      public Image renderPage(int page)
      Renders one page, counted from 0, left to right and then top to bottom.
    • renderImage

      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. It is as large as the content, so a long project at a close zoom is a very large image; renderPage is the one for those.

      Throws
      • IllegalStateException: if either side would pass maxSide pixels
    • isPdfSupported

      public static boolean isPdfSupported()
      Whether writePdf works here: it needs the platform to encode JPEG.
    • writePdf

      public void writePdf(String path) throws IOException

      Writes every page into one PDF document at path, 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)
      Throws:
      IOException
    • print

      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
      • listener: told how it ended, on the EDT; may be null