public final class PageFormatFactory extends Object
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.
Modifier and Type | Method and Description |
---|---|
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.
|
static PageFormat |
create(PageSize papersize,
int orientation,
Insets margins) |
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.
|
static String |
printPageFormat(PageFormat pf) |
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) |
public static PageFormatFactory getInstance()
public Paper createPaper(int[] papersize)
papersize
- the definition of the papersize in a 2-element int-arraypublic Paper createPaper(PageSize papersize)
papersize
- the definition of the papersize in a 2-element int-arraypublic Paper createPaper(double width, double height)
width
- the width of the paper in pointsheight
- the height of the paper in pointspublic void setBorders(Paper paper, double top, double left, double bottom, double right)
paper
- the paper that should be modifiedtop
- the bordersize of the top-borderleft
- the border in points in the leftbottom
- the border in points in the bottomright
- the border in points in the rightpublic void setBordersInch(Paper paper, double top, double left, double bottom, double right)
paper
- the paper that should be modifiedtop
- the bordersize of the top-borderleft
- the border in points in the leftbottom
- the border in points in the bottomright
- the border in points in the rightpublic void setBordersMm(Paper paper, double top, double left, double bottom, double right)
paper
- the paper that should be modifiedtop
- the bordersize of the top-borderleft
- the border in points in the leftbottom
- the border in points in the bottomright
- the border in points in the rightpublic double convertInchToPoints(double inches)
inches
- the size in inchpublic double convertMmToPoints(double mm)
mm
- the size in inchpublic PageFormat createPageFormat(Paper paper, int orientation)
paper
- the paper to use in the new pageformatorientation
- one of PageFormat.PORTRAIT, PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPENullPointerException
- if the paper given was nullpublic Paper createPaper(String name)
name
- the name of the constant defining the papersizepublic static PageFormat create(PageSize papersize, int orientation, Insets margins)
public static void logPageFormat(PageFormat pf)
pf
- the page format.public static String printPageFormat(PageFormat pf)
public static void logPaper(Paper pf)
pf
- the paper size.public static boolean isEqual(PageFormat pf1, PageFormat pf2)
pf1
- the first page format that should be compared.pf2
- the second page format that should be compared.public double getLeftBorder(Paper p)
p
- the paper that defines the borders.public double getRightBorder(Paper p)
p
- the paper that defines the borders.public double getTopBorder(Paper p)
p
- the paper that defines the borders.public double getBottomBorder(Paper p)
p
- the paper that defines the borders.public Insets getPageMargins(PageFormat format)
public String getPageFormatName(double width, double height)
public String[] getPageFormats()
public void setPageMargins(PageFormat pageFormat, Insets pageMargins)