Package com.portal.common
Class PrintManager
java.lang.Object
com.portal.common.PrintManager
- 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 Summary
ConstructorsConstructorDescriptionConstructs a print manager object that can be assigned a printable component by calling the setPrintable method.PrintManager(PrintableArrayList aList) Constructs a print manager object to handle printing of the ArrayList.PrintManager(JComponent comp) Constructs a print manager object to handle printing of the specified component. -
Method Summary
Modifier and TypeMethodDescriptionprotected BookcreateBook(JComponent compToPrint, HFPageFormat pf) voidExecutes the printing operation.voidexecutePrinting(JComponent waitComp) Executes the printing operation.static StringRetrieves the date and time of the current locale.booleanRetrieves the boolean status of date and time.intComputes and returns the number of printing pages based on the printable component height and the imageable height of the page.booleanRetrieves the boolean status of page numbers.voidsetDescArray(ArrayList descList) voidsetLeftPageHeader(String header) The header will be printed at north west corner of each page.voidvoidsetPreviewDialogParent(JFrame frame) Assigns the specified parent frame for the preview dialog.voidsetPrintable(PrintableArrayList aList) Assigns an ArrayList to the print manager.voidsetPrintable(JComponent comp) Assigns a printable component to the print manager.voidsetRightPageHeader(String header) The header will be printed at north east corner of each page.voidshowDateAndTime(boolean b) Displays date and time on the printable page.voidshowPageNumbers(boolean b) Displays page numbers on the printable page.voidDisplays the page setup dialog.voidDisplays the preview dialog.
-
Constructor Details
-
PrintManager
public PrintManager()Constructs a print manager object that can be assigned a printable component by calling the setPrintable method. -
PrintManager
Constructs a print manager object to handle printing of the specified component.- Parameters:
comp- printable component
-
PrintManager
Constructs a print manager object to handle printing of the ArrayList.- Parameters:
aList- printable ArrayList
-
-
Method Details
-
setPageFormat
-
setPrintable
Assigns a printable component to the print manager.- Parameters:
comp- printable component
-
setPrintable
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
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 formatcompToPrint- the printable component- Returns:
- number of pages based on format specified
-
executePrinting
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
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
-
setLeftPageHeader
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
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
-
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
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
Retrieves the date and time of the current locale. -
setPreviewDialogParent
Assigns the specified parent frame for the preview dialog.- Parameters:
frame- any specific frame to attach the preview dialog
-