org.pentaho.reporting.engine.classic.core.util
Class PageFormatFactory

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.util.PageFormatFactory

public final class PageFormatFactory
extends Object

The PageFormatFactory is used to create PageFormats on a higher level. The Factory contains templates for all PageSizes defined by Adobe:

Postscript Specifications

Usage for creating an printjob on A4 paper with 2.5 cm border:

 Paper paper = PageFormatFactory.createPaper (PageSize.A4);
 PageFormatFactory.setBordersMm (paper, 25, 25, 25, 25);
 PageFormat format = PageFormatFactory.createPageFormat (paper, PageFormat.PORTRAIT);
 
 

Defining a pageformat can be an ugly task and full of dependencies. The call to PageFormatFactory.setBorders(...) will setup the paper's border and always assumes that the paper is laid out in Portrait.

Changing the PageFormat's orientation does not change the PageFormat's paper object, but it changes the way, how the paper object is interpreted.

Author:
Thomas Morgner

Method Summary
 double convertInchToPoints(double inches)
          Converts the given inch value to a valid point-value.
 double convertMmToPoints(double mm)
          Converts the given millimeter value to a valid point-value.
 PageFormat createPageFormat(Paper paper, int orientation)
          Creates a new pageformat using the given paper and the given orientation.
 Paper createPaper(double width, double height)
          Creates a paper by using the paper size in points.
 Paper createPaper(int[] papersize)
          Creates a paper by using the paper size in points found in the int-array.
 Paper createPaper(PageSize papersize)
          Creates a paper by using the paper size in points found in the int-array.
 Paper createPaper(String name)
          Creates a paper by looking up the given Uppercase name in this classes defined constants.
 double getBottomBorder(Paper p)
          Returns the bottom border of the given paper.
static PageFormatFactory getInstance()
          Returns a single instance of the factory.
 double getLeftBorder(Paper p)
          Returns the left border of the given paper.
 String getPageFormatName(double width, double height)
           
 String[] getPageFormats()
           
 Insets getPageMargins(PageFormat format)
           
 double getRightBorder(Paper p)
          Returns the right border of the given paper.
 double getTopBorder(Paper p)
          Returns the top border of the given paper.
static boolean isEqual(PageFormat pf1, PageFormat pf2)
          Tests, whether the given two page format objects are equal.
static void logPageFormat(PageFormat pf)
          Logs the page format.
static void logPaper(Paper pf)
          Logs the paper size.
 void setBorders(Paper paper, double top, double left, double bottom, double right)
          Defines the imageable area of the given paper by adjusting the border around the imagable area.
 void setBordersInch(Paper paper, double top, double left, double bottom, double right)
          Defines the imageable area of the given paper by adjusting the border around the imagable area.
 void setBordersMm(Paper paper, double top, double left, double bottom, double right)
          Defines the imageable area of the given paper by adjusting the border around the imagable area.
 void setPageMargins(PageFormat pageFormat, Insets pageMargins)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static PageFormatFactory getInstance()
Returns a single instance of the factory.

Returns:
an instance of a PageFormatFactory.

createPaper

public Paper createPaper(int[] papersize)
Creates a paper by using the paper size in points found in the int-array. The array must have a length of 2 and the first value of this array has to contain the width and the second the height parameter. The created Paper has no ImagableArea defined.

Parameters:
papersize - the definition of the papersize in a 2-element int-array
Returns:
the created paper

createPaper

public Paper createPaper(PageSize papersize)
Creates a paper by using the paper size in points found in the int-array. The array must have a length of 2 and the first value of this array has to contain the width and the second the height parameter. The created Paper has no ImagableArea defined.

Parameters:
papersize - the definition of the papersize in a 2-element int-array
Returns:
the created paper

createPaper

public Paper createPaper(double width,
                         double height)
Creates a paper by using the paper size in points. The created Paper has no ImagableArea defined.

Parameters:
width - the width of the paper in points
height - the height of the paper in points
Returns:
the created paper

setBorders

public void setBorders(Paper paper,
                       double top,
                       double left,
                       double bottom,
                       double right)
Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are given in points.

Parameters:
paper - the paper that should be modified
top - the bordersize of the top-border
left - the border in points in the left
bottom - the border in points in the bottom
right - the border in points in the right

setBordersInch

public void setBordersInch(Paper paper,
                           double top,
                           double left,
                           double bottom,
                           double right)
Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are given in inches.

Parameters:
paper - the paper that should be modified
top - the bordersize of the top-border
left - the border in points in the left
bottom - the border in points in the bottom
right - the border in points in the right

setBordersMm

public void setBordersMm(Paper paper,
                         double top,
                         double left,
                         double bottom,
                         double right)
Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are given in millimeters.

Parameters:
paper - the paper that should be modified
top - the bordersize of the top-border
left - the border in points in the left
bottom - the border in points in the bottom
right - the border in points in the right

convertInchToPoints

public double convertInchToPoints(double inches)
Converts the given inch value to a valid point-value.

Parameters:
inches - the size in inch
Returns:
the size in points

convertMmToPoints

public double convertMmToPoints(double mm)
Converts the given millimeter value to a valid point-value.

Parameters:
mm - the size in inch
Returns:
the size in points

createPageFormat

public PageFormat createPageFormat(Paper paper,
                                   int orientation)
Creates a new pageformat using the given paper and the given orientation.

Parameters:
paper - the paper to use in the new pageformat
orientation - one of PageFormat.PORTRAIT, PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPE
Returns:
the created Pageformat
Throws:
NullPointerException - if the paper given was null

createPaper

public Paper createPaper(String name)
Creates a paper by looking up the given Uppercase name in this classes defined constants. The value if looked up by introspection, if the value is not defined in this class, null is returned.

Parameters:
name - the name of the constant defining the papersize
Returns:
the defined paper or null, if the name was invalid.

logPageFormat

public static void logPageFormat(PageFormat pf)
Logs the page format.

Parameters:
pf - the page format.

logPaper

public static void logPaper(Paper pf)
Logs the paper size.

Parameters:
pf - the paper size.

isEqual

public static boolean isEqual(PageFormat pf1,
                              PageFormat pf2)
Tests, whether the given two page format objects are equal.

Parameters:
pf1 - the first page format that should be compared.
pf2 - the second page format that should be compared.
Returns:
true, if both page formats are equal, false otherwise.

getLeftBorder

public double getLeftBorder(Paper p)
Returns the left border of the given paper.

Parameters:
p - the paper that defines the borders.
Returns:
the left border.

getRightBorder

public double getRightBorder(Paper p)
Returns the right border of the given paper.

Parameters:
p - the paper that defines the borders.
Returns:
the right border.

getTopBorder

public double getTopBorder(Paper p)
Returns the top border of the given paper.

Parameters:
p - the paper that defines the borders.
Returns:
the top border.

getBottomBorder

public double getBottomBorder(Paper p)
Returns the bottom border of the given paper.

Parameters:
p - the paper that defines the borders.
Returns:
the bottom border.

getPageMargins

public Insets getPageMargins(PageFormat format)

getPageFormatName

public String getPageFormatName(double width,
                                double height)

getPageFormats

public String[] getPageFormats()

setPageMargins

public void setPageMargins(PageFormat pageFormat,
                           Insets pageMargins)