Class HFPageFormat

java.lang.Object
java.awt.print.PageFormat
com.portal.common.HFPageFormat
All Implemented Interfaces:
Printable, Cloneable

public class HFPageFormat extends PageFormat implements Printable, Cloneable
Extension of the Java default PageFormat to privide a header, footer and a description area printing capabilities.
Author:
Dachywan Wu
  • Constructor Details

    • HFPageFormat

      public HFPageFormat(PageFormat pf)
      Create the HFPageFormat using existing PageFormat. The HFPageFormat has the capabilities of printing page header, footer and a description area.
      Parameters:
      pf - the existing PageFormat.
  • Method Details

    • setPageFormat

      public void setPageFormat(PageFormat pf)
      Set the page format to print.
      Parameters:
      pf - the page format to print.
    • print

      public int print(Graphics g, PageFormat format, int pageIndex)
      Draws the header, description text area and footer.
      Specified by:
      print in interface Printable
      Parameters:
      g - the graphics context to print.
      format - the page format to print.
      pageIndex - the page index to print, starting from 0.
      Returns:
      Printable.PAGE_EXISTS if print sucessfully, else return Printable.No_SUCH_PAGE.
    • clone

      public Object clone()
      Makes a copy of this HFPageFormat with the same contents as this HFPageFormat.
      Overrides:
      clone in class PageFormat
      Returns:
      a copy of this HFPageFormat.
    • getImageableHeight

      public double getImageableHeight()
      Override the member function of PageFormat to provide the header, footer and description area support.
      Overrides:
      getImageableHeight in class PageFormat
      Returns:
      the printable area height in double.
    • getImageableY

      public double getImageableY()
      Override the member function of PageFormat to provide the header, footer and description area support.
      Overrides:
      getImageableY in class PageFormat
      Returns:
      the printable area top lefe corner Y location in double.
    • getHeaderHeight

      public int getHeaderHeight()
      Get the height of the header area in int.
      Returns:
      int the header area height.
    • getDescAreaHeight

      public int getDescAreaHeight()
      Get the height of the description area in int.
      Returns:
      int the description area height.
    • getFooterHeight

      public int getFooterHeight()
      Get the height of the footer area in int.
      Returns:
      int the footer area height.
    • setHeaderFont

      public void setHeaderFont(Font f)
      Set the font for the header.
      Parameters:
      f - the header font.
    • setDescFont

      public void setDescFont(Font f)
      Set the description area font.
      Parameters:
      f - the description font.
    • setFooterFont

      public void setFooterFont(Font f)
      Set the footer font.
      Parameters:
      f - the footer font.
    • getHeaderFont

      public Font getHeaderFont()
      Get the header font.
      Returns:
      the font of the header.
    • getDescFont

      public Font getDescFont()
      Get the font for the description area.
      Returns:
      the description font.
    • getFooterFont

      public Font getFooterFont()
      Get the footer font.
      Returns:
      the footer font.
    • setLeftHeaderText

      public void setLeftHeaderText(String text)
      Set the header text at the left margin.
      Parameters:
      text - the left header text.
    • setRightHeaderText

      public void setRightHeaderText(String text)
      Set the right header text.
      Parameters:
      text - the right header text.
    • setDescArray

      public void setDescArray(ArrayList descList)
      Set the description array which will be printed in the description area. The toString() for each item in the list will be called to print the item.
      Parameters:
      descList - the Arraylist to be printed.
    • setLeftFooterText

      public void setLeftFooterText(String text)
      Set the left footer text.
      Parameters:
      text - the left footer text.
    • setRightFooterText

      public void setRightFooterText(String text)
      Set the right footer text.
      Parameters:
      text - the right footer text.
    • getLeftHeaderText

      public String getLeftHeaderText()
      Get the left header text.
      Returns:
      the left header text.
    • getRightHeaderText

      public String getRightHeaderText()
      Get the right header text.
      Returns:
      the right header text.
    • getDescArray

      public ArrayList getDescArray()
      Get the description array.
      Returns:
      the ArrayList of the description array.
    • getLeftFooterText

      public String getLeftFooterText()
      Get the left footer text.
      Returns:
      the left footer text.
    • getRightFooterText

      public String getRightFooterText()
      Get the right footer text.
      Returns:
      the right footer text.
    • paintHeader

      protected void paintHeader(Graphics g, PageFormat format, int pageIndex)
      Print the header.
      Parameters:
      g - the graphics context.
      format - the pageformat.
      pageIndex - the page index starting from 0.
    • paintDescriptionArea

      protected void paintDescriptionArea(Graphics g, PageFormat format, int pageIndex)
      Print the description area.
      Parameters:
      g - the graphics context.
      format - the PageFormat to print.
      pageIndex - the page index.
    • paintFooter

      protected void paintFooter(Graphics g, PageFormat format, int pageIndex)
      Print the footer.
      Parameters:
      g - the graphics context.
      format - the PageFormat to print.
      pageIndex - the page index.