Side of Software
Print Preview Library 1.8.1

sos.preview
Class ComponentPageable

java.lang.Object
  |
  +--sos.preview.ComponentPageable
All Implemented Interfaces:
java.awt.print.Pageable

public class ComponentPageable
extends java.lang.Object
implements java.awt.print.Pageable

A Pageable object that breaks an arbitrary Swing component into pages for previewing and printing. This class uses the component's size and a specified page format to determine the number of pages. If the component's width and height are zero, then this class first sizes the component to its preferred size and validates it. This class has undefined results if the component's size changes from the time the constructor is called to the time the pages are rendered.

Since:
1.3
See Also:
PageableAdapter

Field Summary
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Constructor Summary
ComponentPageable(javax.swing.JComponent component, java.awt.print.PageFormat pageFormat)
          Creates an instance of ComponentPageable with the specified component and page format.
 
Method Summary
 void fit(boolean keepAspectRatio)
          Scales the component so that it fits the page.
 void fitHeight(boolean keepAspectRatio)
          Scales the component so that it fits the page height.
 void fitWidth(boolean keepAspectRatio)
          Scales the component so that it fits the page width.
 int getNumberOfPages()
          Returns the number of pages.
 java.awt.print.PageFormat getPageFormat(int pageIndex)
          Returns the PageFormat of the page specified by pageIndex.
 java.awt.print.Printable getPrintable(int pageIndex)
          Returns the Printable instance responsible for rendering the page specified by pageIndex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentPageable

public ComponentPageable(javax.swing.JComponent component,
                         java.awt.print.PageFormat pageFormat)
Creates an instance of ComponentPageable with the specified component and page format.

Parameters:
component - component to break into pages
pageFormat - the page format of each page
Throws:
java.lang.NullPointerException - if either parameter is null
Method Detail

fit

public void fit(boolean keepAspectRatio)
Scales the component so that it fits the page.

Clients should invoke only one of fit, fitWidth, and fitHeight. Repeated calls cancel previous calls.

Parameters:
keepAspectRatio - true if the component's ratio of width to height should be maintained
See Also:
fitWidth(boolean), fitHeight(boolean)

fitHeight

public void fitHeight(boolean keepAspectRatio)
Scales the component so that it fits the page height. If the component's height is already smaller than the page's imageable height, then no action is taken.

Clients should invoke only one of fit, fitWidth, and fitHeight. Repeated calls cancel previous calls.

Parameters:
keepAspectRatio - true if the component's ratio of width to height should be maintained
See Also:
fit(boolean), fitWidth(boolean)

fitWidth

public void fitWidth(boolean keepAspectRatio)
Scales the component so that it fits the page width. If the component's width is already smaller than the page's imageable width, then no action is taken.

Clients should invoke only one of fit, fitWidth, and fitHeight. Repeated calls cancel previous calls.

Parameters:
keepAspectRatio - true if the component's ratio of width to height should be maintained
See Also:
fit(boolean), fitHeight(boolean)

getNumberOfPages

public int getNumberOfPages()
Returns the number of pages.

Specified by:
getNumberOfPages in interface java.awt.print.Pageable
Returns:
the number of printable pages

getPageFormat

public java.awt.print.PageFormat getPageFormat(int pageIndex)
                                        throws java.lang.IndexOutOfBoundsException
Returns the PageFormat of the page specified by pageIndex.

Specified by:
getPageFormat in interface java.awt.print.Pageable
Returns:
the page format of the specified page
Throws:
java.lang.IndexOutOfBoundsException - if this Pageable does not contain the specified page

getPrintable

public java.awt.print.Printable getPrintable(int pageIndex)
                                      throws java.lang.IndexOutOfBoundsException
Returns the Printable instance responsible for rendering the page specified by pageIndex.

Specified by:
getPrintable in interface java.awt.print.Pageable
Returns:
the Printable for the specified page
Throws:
java.lang.IndexOutOfBoundsException - if this Pageable does not contain the specified page

Side of Software
Print Preview Library 1.8.1

Copyright 2003-07 Side of Software (SOS). All rights reserved.