Side of Software
Print Preview Library 1.8.1

sos.preview
Class CachingPageable

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

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

A java.awt.print.Pageable wrapper that caches page images rendered at 100%. This class can be used when page rendering is slow. With this class, page rendering is done once, and the images are cached. Caching is done lazily, that is, only when actual rendering is needed. This is in contrast to the behavior of PageableAdapter, which caches all pages up front.

Since cached page images occupy a lot of memory, this class has an option to be memory sensitive. If set to true, this class uses soft references to store cached images. When memory is in demand, these soft references are cleared, and images are re-cached.

To convert an existing pageable to a caching pageable, create an instance of CachingPageable, passing the pageable object and a flag indicating whether or not it should be memory sensitive.

An instance of CachingPageable can be used anywhere a Pageable object is accepted. For instance, it can be passed to JPrintPreviewPane.setPageable(java.awt.print.Pageable).

Since CachingPageable renders images at 100%, pages will appear pixilated if used in a print preview panel at zoom levels other than 100%. For smooth zooming while still using a cache, use BasicPrintPreviewPageUI.CACHING_POLICY_KEY instead of this class.

Since:
1.8
See Also:
PageableAdapter, BasicPrintPreviewPageUI.CACHING_POLICY_KEY

Field Summary
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Constructor Summary
CachingPageable(java.awt.print.Pageable pageable)
          Creates a new instance of CachingPageable
CachingPageable(java.awt.print.Pageable pageable, boolean memorySensitive)
           
 
Method Summary
 int getNumberOfPages()
          Returns the number of pages in the set.
 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

CachingPageable

public CachingPageable(java.awt.print.Pageable pageable)
Creates a new instance of CachingPageable


CachingPageable

public CachingPageable(java.awt.print.Pageable pageable,
                       boolean memorySensitive)
Method Detail

getNumberOfPages

public int getNumberOfPages()
Returns the number of pages in the set. To enable advanced printing features, it is recommended that Pageable implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant.

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

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
Parameters:
pageIndex - the zero based index of the page whose PageFormat is being requested
Returns:
the PageFormat describing the size and orientation.
Throws:
java.lang.IndexOutOfBoundsException - if the Pageable does not contain the requested 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
Parameters:
pageIndex - the zero based index of the page whose Printable is being requested
Returns:
the Printable that renders the page.
Throws:
java.lang.IndexOutOfBoundsException - if the Pageable does not contain the requested page.

Side of Software
Print Preview Library 1.8.1

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