Class PrintManager

java.lang.Object
com.portal.common.PrintManager

public class PrintManager extends Object
Author:
Satyaraj Pantham Print manager for conducting printing operations. Developers can create an object of this class and specify the component to be printed. The print manager is responsible for setting up the printing architecture in the background. The print manager can display the preview dialog, page setup dialog or print dialog. To carry out the corresponding operations, the class provides the required methods.
  • Constructor Details

    • PrintManager

      public PrintManager()
      Constructs a print manager object that can be assigned a printable component by calling the setPrintable method.
    • PrintManager

      public PrintManager(JComponent comp)
      Constructs a print manager object to handle printing of the specified component.
      Parameters:
      comp - printable component
    • PrintManager

      public PrintManager(PrintableArrayList aList)
      Constructs a print manager object to handle printing of the ArrayList.
      Parameters:
      aList - printable ArrayList
  • Method Details

    • setPageFormat

      public void setPageFormat(HFPageFormat pf)
    • setPrintable

      public void setPrintable(JComponent comp)
      Assigns a printable component to the print manager.
      Parameters:
      comp - printable component
    • setPrintable

      public void setPrintable(PrintableArrayList aList)
      Assigns an ArrayList to the print manager. toString() method on each object will be called to print the object to a single line.
      Parameters:
      aList - printable ArrayList
    • getFormattedPagesCount

      public int getFormattedPagesCount(JComponent jc, PageFormat pf)
      Computes and returns the number of printing pages based on the printable component height and the imageable height of the page. Since we are going to scale the component to the component's width, we need to calculate the number of pages with the following algorithm: npages = ceil(subj_h/(page_h/scale)) where scale = page_w/subj_w npages = ceil(subj_h / (page_h / (page_w/subj_w))) = ceil(subj_h / (page_h * subj_w / page_w)) = ceil( (subj_h * page_w) / (page_h * subj_w) )
      Parameters:
      pf - specified page format
      compToPrint - the printable component
      Returns:
      number of pages based on format specified
    • executePrinting

      public void executePrinting() throws NullPrintableException
      Executes the printing operation. Developers must call this method inside the action handler that triggers printing operation.
      Throws:
      NullPrintableException - if the printable component is null
    • executePrinting

      public void executePrinting(JComponent waitComp) throws NullPrintableException
      Executes the printing operation. Developers must call this method inside the action handler that triggers printing operation. Throws NullPrintableExeception if the printable component is null.
      Parameters:
      panel - panel on which to set wait cursor during print preparation
      Throws:
      NullPrintableException - if the printable component is null
    • createBook

      protected Book createBook(JComponent compToPrint, HFPageFormat pf)
    • setLeftPageHeader

      public void setLeftPageHeader(String header)
      The header will be printed at north west corner of each page. Call setLeftPageHeader(null) to suppress the printing of the header.
      Parameters:
      header - the text to print.
    • setRightPageHeader

      public void setRightPageHeader(String header)
      The header will be printed at north east corner of each page. Call setRightPageHeader(null) to suppress the printing of the header.
      Parameters:
      header - the text to print.
    • setDescArray

      public void setDescArray(ArrayList descList)
    • showPageSetup

      public void showPageSetup()
      Displays the page setup dialog. Developers must call this method inside an action handler to display the page setup dialog that allows page formatting.
    • showPreview

      public void showPreview() throws NullPrintableException
      Displays the preview dialog. Developers must call this method to display the dialog showing the print preview.
      Throws:
      NullPrintableException - if the printable component is null
    • showDateAndTime

      public void showDateAndTime(boolean b)
      Displays date and time on the printable page.
      Parameters:
      b - show date and time (true), or not (false)
    • showPageNumbers

      public void showPageNumbers(boolean b)
      Displays page numbers on the printable page.
      Parameters:
      b - show page numbers (true), or not (false)
    • getPageNumbersStatus

      public boolean getPageNumbersStatus()
      Retrieves the boolean status of page numbers.
      Returns:
      whether page number are shown
    • getDateAndTimeStatus

      public boolean getDateAndTimeStatus()
      Retrieves the boolean status of date and time.
      Returns:
      whether date and time are shown
    • getDateAndTime

      public static String getDateAndTime()
      Retrieves the date and time of the current locale.
    • setPreviewDialogParent

      public void setPreviewDialogParent(JFrame frame)
      Assigns the specified parent frame for the preview dialog.
      Parameters:
      frame - any specific frame to attach the preview dialog