Oracle™ Business Intelligence Beans Java API Reference
Release 10
g (9.0.4)
Part number B12159_01


oracle.dss.crosstab
Class CrosstabPrinter

java.lang.Object
  |
  +--oracle.dss.dataView.ViewPrinter
        |
        +--oracle.dss.gridView.GridViewPrinter
              |
              +--oracle.dss.crosstab.CrosstabPrinter
All Implemented Interfaces:
java.awt.print.Printable

public class CrosstabPrinter
extends GridViewPrinter

Printer for a Crosstab. This printer can print a Crosstab onto multiple physical pages. In this case, this CrosstabPrinter takes responsibility for the print job, including pagination and fitting the Crosstab to the physical pages. You also use this printer to print a Crosstab to a Graphics object, when you want responsibility for the print job. For example, you take responsibility for the print job when you print more than one view on a physical page.

When you give this CrosstabPrinter responsibility for the print job, you can use the PrintDialog object from the oracle.dss.dataView.gui package, to set up full-page and multiple-page printing very easily. You can alternatively use your own UI, calling methods on this CrosstabPrinter to specify how to print a Crosstab, and to print the Crosstab. If you assume responsibility for page layout and calculation, you cannot use the PrintDialog; you must call methods on this CrosstabPrinter to print.

The following example shows how to print a Crosstab, using the oracle.dss.dataView.gui.PrintDialog.

    CrosstabPrinter printer = new CrosstabPrinter();
    //One way to get a frame in which to display the Print dialog
    Frame frame = oracle.bali.ewt.util.WindowUtils.parentFrame(crosstab);
    PrintDialog dialog = new PrintDialog(frame, printer);
    dialog.show();
    dialog.dispose();
    dialog = null;

The following code shows how to print a single view on one or more pages, when you use your own UI and not the PrintDialog from the dataView.gui package. The example shows how to print all logical pages of a Crosstab, fitting each logical page on two physical pages, broken vertically. The CrosstabPrinter assumes responsibility for the print job.

 CrosstabPrinter printer = new CrosstabPrinter(crosstab);
    //invoke the standard Print dialog box
    if(printer.showPrintJob())
       {
        //set the margins
        printer.setLeftMargin(78);
        printer.setTopMargin(50);
        printer.setBottomMargin(30);
        printer.setRightMargin(50);

        //set the scale type to fit each logical page on two physical pages
        printer.setPrintScaleType(SCALE_TO_FIT_PAGES);
        printer.setFitToNumPagesTall(2);
        printer.setFitToNumPagesWide(1);

        //if you want to print at 75 percent, you would use the following:
        //printer.setPrintScaleType(SCALE_TO_ZOOM_FACTOR);
        //printer.setPrintZoomFactor(75);

        //set the range to print all logical pages
        printer.setRangeType(ALL_LOGICAL_PAGES);

        //display a string in the upper left header
        printer.getHeaderAndFooterPainter(ViewPrinter.HEADER_LEFT).setContentType(ViewPrinter.STRINGS);
        printer.getHeaderAndFooterPainter(ViewPrinter.HEADER_LEFT).setStrings("My Crosstab");
        //display the date in the left footer
        printer.getHeaderAndFooterPainter(ViewPrinter.FOOTER_LEFT).setContentType(ViewPrinter.DATE);
        //display the page number in the right footer
        printer.getHeaderAndFooterPainter(ViewPrinter.FOOTER_RIGHT).setContentType(ViewPrinter.PAGE_NUMBER);

        //save the original state of the view while printing, print, then
        //restore the original state
        printer.startPrint();
        printer.print();
        printer.endPrint();
        }

In the following example, the application takes responsibility for the print job. Suppose that you have a very small crosstab and a very small table in an application. The following code shows you you would print both the views on the same page.

 CrosstabPrinter cPrinter = new CrosstabPrinter(crosstab);
 TablePrinter tPrinter = new TablePrinter(table);

    cPrinter.setRepeatHeaders(true);
    cPrinter.setPrintScaleType(CrosstabPrinter.ORIGINAL_SIZE);
    tPrinter.setPrintScaleType(TablePrinter.ORIGINAL_SIZE);
    cPrinter.setRangeType(CURRENT_LOGICAL_PAGE);
    tPrinter.setRangeType(CURRENT_LOGICAL_PAGE);

    //get print job
    PrintJob pjob = (java.awt.Toolkit.getDefaultToolkit()).getPrintJob(frame, "Printer", null);
    if(pjob != null)
       {
        //set options before calling startPrint
        Dimension pageDim = pjob.getPageDimension();
        //split the page in half, with a 1/4-inch gutter
        Dimension cDim = new Dimension(pageDim.width, (pageDim.height / 2) - 9);
        Dimension tDim = new Dimension(cDim);
        cPrinter.setViewDimension(cDim);
        tPrinter.setViewDimension(tDim);

        //print the crosstab to the print job
        cPrinter.startPrint();
        Graphics g = pjob.getGraphics();
        //go to the first physical page, even though there is only one
        cPrinter.prepareFirstPage(g);
        cPrinter.renderPage(g);
        cPrinter.endPrint();

        //reuse the Graphics object, adding a 1/4" gutter between views
        g.translate(0, crosstabDim.height + 18);

        //print the table to the print job
        tPrinter.startPrint();
        tPrinter.prepareFirstPage(g);
        tPrinter.renderPage(g);
        tPrinter.endPrint();

        //send the print job to the printer
        g.dispose();
        //end the print job
        pjob.end();
        }
See Also:
ViewPrinter, PrintDialog

Fields inherited from class oracle.dss.dataView.ViewPrinter
ADJUST_FOR_HEADERS_AND_FOOTERS, ALL_LOGICAL_PAGES, CURRENT_LOGICAL_PAGE, FOOTER_CENTER, FOOTER_LEFT, FOOTER_RIGHT, HEADER_CENTER, HEADER_LEFT, HEADER_RIGHT, HEADERS_AND_FOOTERS_ALL, HEADERS_AND_FOOTERS_NONE, IGNORE_HEADERS_AND_FOOTERS, OCCLUDE_HEADERS_AND_FOOTERS, ORIGINAL_SIZE, SCALE_TO_FIT_FULL_PAGE, SCALE_TO_FIT_PAGE, SCALE_TO_FIT_PAGES, SCALE_TO_ZOOM_FACTOR, SELECTED_LOGICAL_PAGES

 

Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS

 

Constructor Summary
CrosstabPrinter(Crosstab c)
          Constructor.

 

Method Summary
 boolean calcPageBounds(DataSubsetRecord record)
          Calculates the number of complete rows and columns that will fit in the area allotted on a page for printing the Crosstab.
 void endPrint()
          Sets the Crosstab back to its original state.
 Crosstab getCrosstab()
          Retrieves the Crosstab that this CrosstabPrinter prints.
 boolean goToFirstPage()
          Deprecated. As of 1.6.0.9, replaced by prepareFirstPage(Graphics)
 boolean goToNextPage()
          Deprecated. As of 1.6.0.9, replaced by prepareNextPage(Graphics)
 boolean goToPrevPage()
          Deprecated. As of 1.6.0.9, replaced by preparePrevPage(Graphics)
 boolean hasNextPage()
          Indicates whether the view has a physical page after the current physical page.
 boolean hasPrevPage()
          Indicates whether the view has a physical page before the current physical page.
 boolean isFirstPhysicalPage()
          Indicates whether the current physical page is the first physical page in the current logical page.
 boolean isLastPhysicalPage()
          Indicates whether the current physical page is the last physical page in the current logical page.
 boolean prepareFirstPage(java.awt.Graphics g)
          Prepares the first physical page in the crosstab for printing and makes it the current page to print.
 boolean prepareNextPage(java.awt.Graphics g)
          Prepares the next physical page for printing and makes it the current page to print.
 boolean preparePrevPage(java.awt.Graphics g)
          Prepares the previous physical page for printing and makes it the current page to print.
 boolean printPage(java.awt.Graphics g)
          Prints the Crosstab to a Graphics object.
 boolean printPage(java.awt.Graphics g, DataSubsetRecord record)
          Prints the Crosstab to a Graphics object.
 void setCrosstab(Crosstab crosstab)
          Specifies the Crosstab that this CrosstabPrinter should print.
 boolean startPrint()
          Puts the Crosstab in a state for printing.
 boolean startPrint(boolean bPreviewMode)
          Puts the Crosstab in a state for printing.

 

Methods inherited from class oracle.dss.gridView.GridViewPrinter
isRepeatHeaders, setLogicalPage, setRepeatHeaders

 

Methods inherited from class oracle.dss.dataView.ViewPrinter
getBottomMargin, getCustomHeaderAndFooterCallback, getDataview, getFitToNumPagesTall, getFitToNumPagesWide, getFooterMargin, getFooterPainter, getHeaderAndFooterPainter, getHeaderMargin, getHeaderPainter, getHeadersAndFootersUsingCallback, getLeftMargin, getLogicalPage, getMarginAdjustment, getPageFormat, getPrintJob, getPrintScaleType, getPrintZoomFactor, getRangeType, getRightMargin, getScaleFontSize, getSelectedHPos, getSequentialPageNumber, getTokenSubstitution, getTopMargin, getViewDimension, isGridlinesVisible, isPrintByColumns, print, print, renderPage, setBottomMargin, setCustomHeaderAndFooterCallback, setFitToNumPagesTall, setFitToNumPagesWide, setFooterMargin, setGridlinesVisible, setHeaderMargin, setHeadersAndFootersUsingCallback, setLeftMargin, setMarginAdjustment, setPageFormat, setPrintByColumns, setPrintJob, setPrintScaleType, setPrintZoomFactor, setRangeType, setRightMargin, setScaleFontSize, setSelectedHPos, setSequentialPageNumber, setTokenSubstitution, setTopMargin, setViewDimension, showPrintJob

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

CrosstabPrinter

public CrosstabPrinter(Crosstab c)
Constructor.
Parameters:
c - The Crosstab that this CrosstabPrinter prints.
Method Detail

startPrint

public boolean startPrint()
Puts the Crosstab in a state for printing. This method saves the original state of the crosstab, then it applies printing properties to the crosstab. It displays the offscreen image (which has the snapshot of the crosstab) on the screen, so that any modifications done to the crosstab during printing will not be seen.

Calling this method is equivalent to calling startPrint(false). It is appropriate for printing crosstabs. To preview a crosstab, call startPrint(true).

Calls to the print method belong between calls to startPrint and endPrint.

Overrides:
startPrint in class ViewPrinter
Returns:
true if the print job starts successfully, false if the data in the view is not available to this CrosstabPrinter or if there is not enough room to print the view.
See Also:
endPrint(), startPrint(boolean), printPage(java.awt.Graphics), printPage(Graphics, DataSubsetRecord), ViewPrinter.print(boolean), ViewPrinter.renderPage(java.awt.Graphics)

startPrint

public boolean startPrint(boolean bPreviewMode)
Puts the Crosstab in a state for printing. This method saves the original state of the view, then it applies printing properties to the Crosstab. It displays the offscreen image (which has the snapshot of the view) on the screen, so that any modifications done to the view during printing will not be seen.

Use this method, with the renderPage method, when you preview a crosstab. Passing true in the bPreviewMode parameter allows this ViewPrinter to cache information to improve performance.

Calls to the print method belong between calls to startPrint and endPrint.

Overrides:
startPrint in class ViewPrinter
Parameters:
bPreviewMode - true if you are previewing the print job, false if you are actually sending the print job to a printer.
Returns:
true if the print job starts successfully, false if the data in the view is not available to this CrosstabPrinter, or there is not enough space to print the view.
See Also:
endPrint(), printPage(java.awt.Graphics), printPage(Graphics, DataSubsetRecord), ViewPrinter.print(boolean), ViewPrinter.renderPage(java.awt.Graphics)

endPrint

public void endPrint()
Sets the Crosstab back to its original state. This method removes the offscreen image that the startPrint method displays, and restores the active display of the Crosstab.

Calls to the print, renderPage, or printPage methods belong between calls to startPrint and endPrint.

Overrides:
endPrint in class ViewPrinter
See Also:
startPrint(), printPage(Graphics), printPage(Graphics, DataSubsetRecord), ViewPrinter.print(boolean), ViewPrinter.renderPage(java.awt.Graphics)

isFirstPhysicalPage

public boolean isFirstPhysicalPage()
Indicates whether the current physical page is the first physical page in the current logical page. Use this method when you use the renderPage method.
Overrides:
isFirstPhysicalPage in class ViewPrinter
Returns:
true if the current physical page is the first physical page in the current logical page, false if the current physical page is not the first in the logical page.
See Also:
ViewPrinter.renderPage(java.awt.Graphics)

isLastPhysicalPage

public boolean isLastPhysicalPage()
Indicates whether the current physical page is the last physical page in the current logical page. Use this method when you use the renderPage method.
Overrides:
isLastPhysicalPage in class ViewPrinter
Returns:
true if the current physical page is the last physical page in the current logical page, false if the current physical page is not the last in the logical page.
See Also:
ViewPrinter.renderPage(java.awt.Graphics)

getCrosstab

public Crosstab getCrosstab()
Retrieves the Crosstab that this CrosstabPrinter prints.
Returns:
The Crosstab that this CrosstabPrinter prints.

setCrosstab

public void setCrosstab(Crosstab crosstab)
Specifies the Crosstab that this CrosstabPrinter should print.
Parameters:
crosstab - The Crosstab that needs to be printed.

calcPageBounds

public boolean calcPageBounds(DataSubsetRecord record)
Calculates the number of complete rows and columns that will fit in the area allotted on a page for printing the Crosstab. This method is useful when use the printPage method to print. It is useful when the view does not fit in the ViewDimension that you have allotted for it, and you want to continue printing the view in another area.

The area that this method uses for calculation is specified in the setViewDimension method.

In the DataSubsetRecord that you pass, you provide information about the rows and columns that you want to print. This method stores information about the last row and column that can be printed. If the first column does not fit in the alloted area, then this method stores information about the amount of the column that can be printed in the area. You are responsible for saving the information from the DataSubsetRecord, so that you can use it in future calls to this method.

Parameters:
record - The DataSubsetRecord that specifies where in the Crosstab the printing should begin.
Returns:
true if the page boundaries are successfully calculated, false if the data in the view is not available to this CrosstabPrinter.
See Also:
DataSubsetRecord

printPage

public boolean printPage(java.awt.Graphics g)
Prints the Crosstab to a Graphics object. This method is useful when you do not want to start with the first row and column in a crosstab. Before you call this method, call calcPageBounds.

This method renders the Crosstab in the Dimension that is specified by the ViewDimension attribute of this CrosstabPrinter. This method uses data present from the DataSubsetRecord that you pass to the calcPageBounds method.

Parameters:
g - The Graphics object to which to print the Crosstab.
Returns:
true if the print job is successful, false if the data in the view is not available to this CrosstabPrinter.
See Also:
calcPageBounds(oracle.dss.dataView.DataSubsetRecord)

printPage

public boolean printPage(java.awt.Graphics g,
DataSubsetRecord record)
Prints the Crosstab to a Graphics object. This method is useful when you do not want to start with the first row and column in a crosstab.

This method renders the Crosstab in the Dimension that is specified by the ViewDimension attribute of this CrosstabPrinter.

Use this method, rather than printPage(Graphics), when the DataSubsetRecord has changed since you called calcPageBounds.

Parameters:
g - The Graphics object to which to print the Crosstab.
record - The DataSubsetRecord that specifies the location in the Crosstab to start printing.
Returns:
true if the print job is successful, false if the data in the view is not available to this CrosstabPrinter.
See Also:
calcPageBounds(oracle.dss.dataView.DataSubsetRecord)

goToFirstPage

public boolean goToFirstPage()
Deprecated. As of 1.6.0.9, replaced by prepareFirstPage(Graphics)
The prepareFirstPage method respects the MarginAdjustment property.
Overrides:
goToFirstPage in class ViewPrinter
See Also:
ViewPrinter.setMarginAdjustment(int)

prepareFirstPage

public boolean prepareFirstPage(java.awt.Graphics g)
Prepares the first physical page in the crosstab for printing and makes it the current page to print. Call this method before you call renderPage to print. Call this method before you call any of the other methods for changing pages. Call this method, even if you only print one physical page. This method performs initialization for printing.
Overrides:
prepareFirstPage in class ViewPrinter
Parameters:
g - The Graphics object to which to print the page.
Returns:
true if the call is successful, false if the first physical page has no data.
See Also:
hasNextPage(), prepareNextPage(java.awt.Graphics), ViewPrinter.renderPage(java.awt.Graphics)

hasNextPage

public boolean hasNextPage()
Indicates whether the view has a physical page after the current physical page. Use this method when you use renderPage to print. Call this method before you call prepareNextPage.
Overrides:
hasNextPage in class ViewPrinter
Returns:
true if the view has another physical page after the current page, false if the current physical page is the last physical page.
See Also:
prepareNextPage(java.awt.Graphics), ViewPrinter.renderPage(java.awt.Graphics)

goToNextPage

public boolean goToNextPage()
Deprecated. As of 1.6.0.9, replaced by prepareNextPage(Graphics)
The prepareNextPage method respects the MarginAdjustment property.
Overrides:
goToNextPage in class ViewPrinter
See Also:
ViewPrinter.setMarginAdjustment(int)

prepareNextPage

public boolean prepareNextPage(java.awt.Graphics g)
Prepares the next physical page for printing and makes it the current page to print. Use this method when you use renderPage to print. Unless you are certain that there is a next page, you should call hasNextPage before you call this method. Also, before calling this method, call prepareFirstPage.
Overrides:
prepareNextPage in class ViewPrinter
Parameters:
g - The Graphics object to which to print the page.
Returns:
true if the call is successful, false if the next physical page has no data.
See Also:
prepareFirstPage(java.awt.Graphics), hasNextPage(), ViewPrinter.renderPage(java.awt.Graphics)

hasPrevPage

public boolean hasPrevPage()
Indicates whether the view has a physical page before the current physical page. Use this method when you use renderPage to print. Call this method before you call preparePrevPage.
Overrides:
hasPrevPage in class ViewPrinter
Returns:
true if the view has another physical page before the current page, false if the current physical page is the first physical page.
See Also:
preparePrevPage(java.awt.Graphics), ViewPrinter.renderPage(java.awt.Graphics)

goToPrevPage

public boolean goToPrevPage()
Deprecated. As of 1.6.0.9, replaced by preparePrevPage(Graphics)
The preparePrevPage method respects the MarginAdjustment property.
Overrides:
goToPrevPage in class ViewPrinter
See Also:
ViewPrinter.setMarginAdjustment(int)

preparePrevPage

public boolean preparePrevPage(java.awt.Graphics g)
Prepares the previous physical page for printing and makes it the current page to print. Use this method when you use renderPage to print. Unless you are certain that there is a previous page, you should call hasPrevPage before you call this method. Also, before calling this method, call prepareFirstPage.
Overrides:
preparePrevPage in class ViewPrinter
Parameters:
g - The Graphics object to which to print the page.
Returns:
true if the call is successful, false if the previous physical page has no data.
See Also:
prepareFirstPage(java.awt.Graphics), hasPrevPage(), ViewPrinter.renderPage(java.awt.Graphics)

Oracle™ Business Intelligence Beans Java API Reference
Release 10
g (9.0.4)
Part number B12159_01


Copyright © 2003, Oracle. All Rights Reserved.