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


oracle.dss.graph
Class GraphPrinter

java.lang.Object
  |
  +--oracle.dss.dataView.ViewPrinter
        |
        +--oracle.dss.graph.GraphPrinter
All Implemented Interfaces:
java.awt.print.Printable

public class GraphPrinter
extends ViewPrinter

Printer for a Graph. When you use the PrintDialog object from the oracle.dss.dataView.gui package, you do not need to call the methods in this class. When you use your own UI, you call methods on this GraphPrinter to specify how to print a Graph and to print the Graph. If you assume responsibility for page layout and calculation, you cannot use the PrintDialog; you must call methods on this GraphPrinter to print.

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

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

The following code shows how to print all logical pages of a single Graph, each logical page on its own physical page, when you use your own UI and not the PrintDialog from the dataView.gui package. The example prints each page of the Graph so that it fills the page but keeps the proportions that it has on the screen. The GraphPrinter assumes responsibility for the print job.

 GraphPrinter printer = new GraphPrinter(graph);
    //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 the graph on the page,
        //while keeping the on-screen proportion
        printer.setPrintScaleType(SCALE_TO_FIT_PAGE);

        //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 Graph");
        //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();
        }

The following code shows how to print two logical pages of a Graph on the same printed page. This code must assume responsibility for the print job. This example assumes a graph that has two logical pages.

 GraphPrinter printer = new GraphPrinter(graph);
 //set the space available for the View in a page
 printer.setViewDimension(new Dimension(300,300));
 //print graph to the full size of ViewDimension
 printer.setPrintScaleType(GraphPrinter.SCALE_TO_FIT_FULL_PAGE);

 //get print job
 PrintJob pjob = (java.awt.Toolkit.getDefaultToolkit()).getPrintJob(frame, "Printer", null);
 if(pjob != null)
 {
     printer.startPrint();
     //get the hierarchical position of the first page
     DataAccess dataAccess = printer.getGraph().getGraphModel().getDataAccess();
     int[] hPosFirst = dataAccess.getFirstHPos(oracle.dss.util.DataDirector.PAGE_EDGE);
     //set the logical page to the first page
     printer.setLogicalPage(hPosFirst);
     Graphics g = pjob.getGraphics();
     //translate to the point where graph should be printed
     g.translate(20,20);
     printer.printPage(g);
     //translate to the point so that another logical page is printed
     //below first logical page with a gap of 50 pixels
     g.translate(0, 350);
     //set to the next logical page
     int[] hPosNext = dataAccess.getNextHPos(oracle.dss.util.DataDirector.PAGE_EDGE);
     printer.setLogicalPage(hPosNext);
     printer.printPage(g);

     g.dispose();

     pjob.end();
     printer.endPrint();//call endPrint() at the 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
GraphPrinter(Graph g)
          Constructor.

 

Method Summary
 void endPrint()
          Sets the Graph back to its original state.
 Graph getGraph()
          Retrieves the Graph that this GraphPrinter prints.
 int getScaleFontSize()
          Retrieves which text components should be resized when the Graph is scaled to a different size for printing.
 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 graph 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 Graph to a Graphics object.
 void setGraph(Graph graph)
          Specifies the Graph that this GraphPrinter should print.
 boolean setLogicalPage(int[] hPos)
          Specifies the logical page to print, when you use the printPage method to print.
 void setScaleFontSize(int mask)
          Specifies which text components should be resized when the graph is scaled to a different size for printing.
 boolean startPrint()
          Puts the Graph in a state for printing.
 boolean startPrint(boolean bPreviewMode)
          Puts the Graph in a state for printing.

 

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, getSelectedHPos, getSequentialPageNumber, getTokenSubstitution, getTopMargin, getViewDimension, isGridlinesVisible, isPrintByColumns, isRepeatHeaders, print, print, renderPage, setBottomMargin, setCustomHeaderAndFooterCallback, setFitToNumPagesTall, setFitToNumPagesWide, setFooterMargin, setGridlinesVisible, setHeaderMargin, setHeadersAndFootersUsingCallback, setLeftMargin, setMarginAdjustment, setPageFormat, setPrintByColumns, setPrintJob, setPrintScaleType, setPrintZoomFactor, setRangeType, setRepeatHeaders, setRightMargin, setSelectedHPos, setSequentialPageNumber, setTokenSubstitution, setTopMargin, setViewDimension, showPrintJob

 

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

 

Constructor Detail

GraphPrinter

public GraphPrinter(Graph g)
Constructor.
Parameters:
g - The Graph that this GraphPrinter prints.
Method Detail

startPrint

public boolean startPrint()
Puts the Graph in a state for printing. This method saves the original state of the view, then it applies printing properties to the Graph. 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.

Calling this method is equivalent to calling startPrint(false). It is appropriate for printing or previewing graphs, or printing tables and crosstabs. To preview a table or 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 GraphPrinter.
See Also:
endPrint(), startPrint(boolean), printPage(java.awt.Graphics), ViewPrinter.print(boolean), ViewPrinter.renderPage(java.awt.Graphics)

startPrint

public boolean startPrint(boolean bPreviewMode)
Puts the Graph in a state for printing. This method saves the original state of the view, then it applies printing properties to the Graph. 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.

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 GraphPrinter.
See Also:
endPrint(), startPrint(boolean), printPage(java.awt.Graphics), ViewPrinter.print(boolean), ViewPrinter.renderPage(java.awt.Graphics)

endPrint

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

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

Overrides:
endPrint in class ViewPrinter
See Also:
startPrint(), ViewPrinter.print(boolean)

isFirstPhysicalPage

public boolean isFirstPhysicalPage()
Indicates whether the current physical page is the first physical page in the current logical page. In graph printing, each logical page is always printed on a single physical page, so this method always returns true.
Overrides:
isFirstPhysicalPage in class ViewPrinter
Returns:
true if the current physical page is the first physical page in the current logical page, false if it is not.
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. In graph printing, each logical page is always printed on a single physical page, so this method always returns true.
Overrides:
isLastPhysicalPage in class ViewPrinter
Returns:
true if the current physical page is the last physical page in the current logical page, false if it is not.
See Also:
ViewPrinter.renderPage(java.awt.Graphics)

getGraph

public Graph getGraph()
Retrieves the Graph that this GraphPrinter prints.
Returns:
The Graph that this GraphPrinter prints.

setGraph

public void setGraph(Graph graph)
Specifies the Graph that this GraphPrinter should print.
Parameters:
graph - The Graph that needs to be printed.

setScaleFontSize

public void setScaleFontSize(int mask)
Specifies which text components should be resized when the graph is scaled to a different size for printing.
Overrides:
setScaleFontSize in class ViewPrinter
Parameters:
mask - A constant that represents the set of components to scale with the graph. The constants are defined in the Graph class, and they start with TEXT_COMPONENTS.
See Also:
Graph.TEXT_COMPONENTS_ALL, Graph.TEXT_COMPONENTS_NONE

getScaleFontSize

public int getScaleFontSize()
Retrieves which text components should be resized when the Graph is scaled to a different size for printing.
Overrides:
getScaleFontSize in class ViewPrinter
Returns:
A constant that represents which text components should be resized when the Graph is scaled to a different size for printing. The constants are defined in the Graph class, and they start with TEXT_COMPONENTS.
See Also:
Graph.TEXT_COMPONENTS_ALL, Graph.TEXT_COMPONENTS_NONE

printPage

public boolean printPage(java.awt.Graphics g)
Prints the Graph to a Graphics object. This method is useful only when you assume responsibility for the print job.

This method renders the Graph in the Dimension that is specified by the ViewDimension attribute of this GraphPrinter.

Parameters:
g - The Graphics object to which to print the Graph.
Returns:
true if the print job is successful, false if the data in the view is not available to this GraphPrinter.

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 graph 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. In a graph, each logical page is printed on a single physical page, so this method checks for another logical page. Use this method, with renderPage, when you assume responsibility for the print job.
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:
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. In a graph, each logical page is printed on a single physical page, so this method changes the current logical page. 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. In a graph, each logical page is printed on a single physical page, so this method checks for another logical page. Use this method, with renderPage, when you assume responsibility for the print job.
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:
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. In a graph, each logical page is printed on a single physical page, so this method changes the current logical page. 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:
ViewPrinter.renderPage(java.awt.Graphics), prepareFirstPage(java.awt.Graphics), hasPrevPage()

setLogicalPage

public boolean setLogicalPage(int[] hPos)
Specifies the logical page to print, when you use the printPage method to print. Call this method after you call the startPrint method for each graph that you print.
Overrides:
setLogicalPage in class ViewPrinter
Parameters:
hPos - The hPos array that identifies the logical page to print.
See Also:
printPage(java.awt.Graphics), PrintDialog, DataAccess.getFirstHPos(int), DataAccess.getNextHPos(int, int[])

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


Copyright © 2003, Oracle. All Rights Reserved.