com.tensegrity.gui.printing
Class BasePageFormat

java.lang.Object
  extended byjava.awt.print.PageFormat
      extended bycom.tensegrity.gui.printing.BasePageFormat
All Implemented Interfaces:
java.lang.Cloneable

public abstract class BasePageFormat
extends java.awt.print.PageFormat

The BasePageFormat class extends the default PageFormat implementation about several useful features to implement sophisticated printing. While the standard PageFormat class only provides a imageableX and -Y position, this class provides you with a left, right, a top and bottom margins.

You can provide a header- and footer text (see FormatItem). Each of the these items can be separately formatted.

You can obtain a scaled version of a page format object, if you consider to use it as a basis for your (print)- preview. Set a scale factor that will get used to scale the things to be printed onto a page.

Use the build(AttributeList)method to create an instance of this class from an AttributeList, or use serialize()to create an AttributeList from your PageFormat instance.

Version:
$Id: CustomPageFormat.java,v 1.65 2005/02/15 13:18:58 BurkhardWick Exp $
Author:
Gilles Iachelini, BurkhardWick

Field Summary
static double DEFAULT_MARGIN
          Constant defines the default value for the left, top, right and bottom margins
protected  FormatItem[] footerItems
          List of items used to format the footer of this page.
protected  FormatItem[] headerItems
          List of items used to format the header of this page.
static int QUALITY_COLORED
          Constant field to describe the colored mode.
static int QUALITY_MONO
          Constant field to describe the mono mode.
static int QUALITY_WIREFRAME
          Constant field to describe the WireFrame mode.
static int SCALEMODE_FITTOPAGE_BOTH
          Constant describing the fit-to-page both scale mode.
static int SCALEMODE_FITTOPAGE_HORIZONTAL
          Constant describing the fit-to-page horizontal scale mode.
static int SCALEMODE_FITTOPAGE_VERTICAL
          Constant describing the fit-to-page vertical scale mode.
static int SCALEMODE_PERCENT
          Constant describing the percentage scale mode.
 
Fields inherited from class java.awt.print.PageFormat
LANDSCAPE, PORTRAIT, REVERSE_LANDSCAPE
 
Constructor Summary
BasePageFormat(BasePageFormat other)
          Copy constructor.
BasePageFormat(java.lang.String paperName)
          Constructor for BasePageFormat.
 
Method Summary
static BasePageFormat build(AttributeList list)
          The build method tries to retrieve all the required values from the given AttributeList by using the BuilderUtilities.getAttributeValueMayBeNull(AttributeList, String, Class) method.
 boolean compare(BasePageFormat aFormat)
          The compare method helps users of this class to compare two BasePageFormat instances.
 double getBottomMargin()
          Returns the bottomMargin.
abstract  BasePageFormat getCopy()
          Returns a copy of this BasePageFormat.
 FormatItem[] getFooter()
          The method getFooter returns the FormatItem list.
abstract  double getFooterFontHeight()
          The method getFooterFontHeight returns the maximum scaled font size of all 3 possible fonts of the footer items.
 FormatItem[] getHeader()
          The method getHeader returns the FormatItem list.
abstract  double getHeaderFontHeight()
          Returns the maximum height in pixel used by all the (scaled) header items.
 double getLeftMargin()
          Returns the leftMargin.
 int getPages()
          Deprecated. use #getPagesHorizontal(int)
 int getPagesHorizontal()
          The method getPages returns the number of pages to be used when being in SCALEMODE_FITTOPAGE.
 int getPagesVertical()
          The method getPages returns the number of pages to be used when being in SCALEMODE_FITTOPAGE.
 java.lang.String getPaperName()
          Method getName returns the human readable name of the the underlying paper type of this PageFormat.
 int getPercent()
          Method getPercent returns the percentage value to be used while in SCALE_PERCENT mode.
 int getQuality()
          Returns the quality.
 double getRightMargin()
          Returns the rightMargin.
 double getScale()
          Returns the scale.
 FontFormat getScaledFont(FontFormat font)
          Method getScaledrFont returns a vertically scaled font instance.
 FontFormat getScaledFont(FontFormat font, int dpi)
          Method getScaledFont returns a vertically scaled font instance.
 int getScalingMode()
          Method getScalingMode returns the currently set scale mode.
 double getTopMargin()
          Returns the topMargin.
 double getVerticalScaleFactor()
          Calculates a vertical scale factor.
 double getVerticalScaleFactor(int dpi)
          Calculates a vertical scale factor.
 PaintFormat getViewPaint()
          Returns the PaintFormat of a VisualGraphView.
 boolean hasFooter()
          The method hasFooter indicates whether one of the applied format items for the footer contains text.
 boolean hasHeader()
          The method hasHeader indicates whether one of the applied format items for the header contains text.
 boolean isBothFitToPage()
          Returns true if the scaling mode is FITTOPAGE_BOTH.
 boolean isGridPrinting()
          Returns true, if the grid will be printed also
 boolean isHorizontalFitToPage()
          Returns true if the scaling mode is set to FITTOPAGE_HORIZONTAL.
 boolean isPercentScaling()
          Returns true if the scale mode is set to PERCENT.
 boolean isVerticalFitToPage()
          Returns true if the scaling mode is FITTOPAGE_VERTICAL.
 boolean printEmptyPages()
          Returns the flag whether to print empty pages or not.
 boolean printShadedBackground()
          Returns the flag for printing the background or not.
 boolean printSubgraphBackground()
          Returns the flag whether to print the background of subgraphs or not.
 void resetMargins()
          Sets the margin values according to the current imageableX and -Y positions of the underlying paper.
 AttributeList serialize()
          Combine all attributes of this PageFormat instance, which differ from the PrintUtil.DEFAULT_PAGEFORMAT, into a new AttributeList.
 void setBottomMargin(double bottomMargin)
          Sets the bottomMargin.
 void setFooter(FormatItem[] items)
          The method setFooter sets the item used to format the footer.
 void setGridPrinting(boolean printGrid)
          Enables / Disables the printing of the grid
 void setHeader(FormatItem[] items)
          The method setHeader sets the items used to format the header.
 void setLeftMargin(double leftMargin)
          Sets the leftMargin.
 void setMargins(double left, double top, double right, double bottom)
          Sets the margins of this PageFormat.
 void setPages(int pages)
          Deprecated. use setPagesHorizontal(int)
 void setPagesHorizontal(int pages)
          The method setPages sets the number of pages used when being in SCALEMODE_FITTOPAGE mode.
 void setPagesVertical(int pages)
          The method setPages sets the number of pages used when being in SCALEMODE_FITTOPAGE mode.
 void setPaperName(java.lang.String name)
          Sets the name of this PageFormat.
 void setPercent(int percent)
          Method setPercent sets the percent value to be used while in SCALE_PERCENT mode.
 void setPrintEmptyPages(boolean b)
          Set the flag to indicate whether empty pages will be printed or not.
 void setPrintShadedBackground(boolean b)
          Toggles the shaded background flag.
 void setPrintSubgraphBackground(boolean b)
          Set the flag to indicate whether subgraph background will be printed or not.
 void setQuality(int quality)
          Sets the quality.
 void setRightMargin(double rightMargin)
          Sets the rightMargin.
 void setScale(double scale)
          Sets the scale.
 void setScalingMode(int mode)
          Method setScalingMode sets the current mode which will used to scale the printable element.
 void setTopMargin(double topMargin)
          Sets the topMargin and corrects the imageable area of the underlying paper instance.
 void setViewPaint(PaintFormat format)
          Sets the PaintFormat.
 java.lang.String toString()
          Returns a human readable description of this BasePageFormat instance.
 
Methods inherited from class java.awt.print.PageFormat
clone, getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY, getMatrix, getOrientation, getPaper, getWidth, setOrientation, setPaper
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

headerItems

protected FormatItem[] headerItems
List of items used to format the header of this page.


footerItems

protected FormatItem[] footerItems
List of items used to format the footer of this page.


SCALEMODE_PERCENT

public static final int SCALEMODE_PERCENT
Constant describing the percentage scale mode.

See Also:
Constant Field Values

SCALEMODE_FITTOPAGE_HORIZONTAL

public static final int SCALEMODE_FITTOPAGE_HORIZONTAL
Constant describing the fit-to-page horizontal scale mode.

See Also:
Constant Field Values

SCALEMODE_FITTOPAGE_VERTICAL

public static final int SCALEMODE_FITTOPAGE_VERTICAL
Constant describing the fit-to-page vertical scale mode.

See Also:
Constant Field Values

SCALEMODE_FITTOPAGE_BOTH

public static final int SCALEMODE_FITTOPAGE_BOTH
Constant describing the fit-to-page both scale mode.

See Also:
Constant Field Values

QUALITY_COLORED

public static final int QUALITY_COLORED
Constant field to describe the colored mode.

See Also:
Constant Field Values

QUALITY_MONO

public static final int QUALITY_MONO
Constant field to describe the mono mode.

See Also:
Constant Field Values

QUALITY_WIREFRAME

public static final int QUALITY_WIREFRAME
Constant field to describe the WireFrame mode.

See Also:
Constant Field Values

DEFAULT_MARGIN

public static final double DEFAULT_MARGIN
Constant defines the default value for the left, top, right and bottom margins

See Also:
Constant Field Values
Constructor Detail

BasePageFormat

public BasePageFormat(java.lang.String paperName)
Constructor for BasePageFormat. Creates a new BasePageFormat. The name of the BasePageFormat reflects a certain paper type. See com.tensegrity.gui.swing.print.PrintUtil#paperTypeNamesfor available paper types.

Parameters:
paperName - a name of paper as String.

BasePageFormat

public BasePageFormat(BasePageFormat other)
Copy constructor.

Parameters:
other - the format instance to obtain the values from.
Method Detail

build

public static final BasePageFormat build(AttributeList list)
The build method tries to retrieve all the required values from the given AttributeList by using the BuilderUtilities.getAttributeValueMayBeNull(AttributeList, String, Class) method. This means, an empty AttributeList would result in the creation of the PrintUtil.DEFAULT_PAGEFORMATitem. Each successful read value from the list, will be set on the default item.

Parameters:
list - an AttributeList which contains several Attributes concerning the BasePageFormat class.
Returns:
a new instance of BasePageFormat.

serialize

public final AttributeList serialize()
Combine all attributes of this PageFormat instance, which differ from the PrintUtil.DEFAULT_PAGEFORMAT, into a new AttributeList.

Returns:
an AttributeList containing all the required elements to describe this BasePageFormat.

compare

public boolean compare(BasePageFormat aFormat)
The compare method helps users of this class to compare two BasePageFormat instances. Unlike a String.compare method, this method will return a boolean.

Parameters:
aFormat - the format to compare to.
Returns:
true to indicate that the two PageFormats are equal after comparing all the relevant values.

setHeader

public void setHeader(FormatItem[] items)
The method setHeader sets the items used to format the header.

Parameters:
items - the list of items to use for the header.

setFooter

public void setFooter(FormatItem[] items)
The method setFooter sets the item used to format the footer.

Parameters:
items - the list of items to use for the footer.

getHeader

public FormatItem[] getHeader()
The method getHeader returns the FormatItem list.

Returns:
the header items.

getFooter

public FormatItem[] getFooter()
The method getFooter returns the FormatItem list.

Returns:
the footer items.

hasHeader

public boolean hasHeader()
The method hasHeader indicates whether one of the applied format items for the header contains text.

Returns:
true, if one of the header items contains text.

hasFooter

public boolean hasFooter()
The method hasFooter indicates whether one of the applied format items for the footer contains text.

Returns:
true, if one of the footer items contains text.

isHorizontalFitToPage

public boolean isHorizontalFitToPage()
Returns true if the scaling mode is set to FITTOPAGE_HORIZONTAL.

Returns:
true to indicate the fit to page horizontal mode.

isVerticalFitToPage

public boolean isVerticalFitToPage()
Returns true if the scaling mode is FITTOPAGE_VERTICAL.

Returns:
true to indicate the fit to page vertical mode.

isBothFitToPage

public boolean isBothFitToPage()
Returns true if the scaling mode is FITTOPAGE_BOTH.

Returns:
true to indicate the fit to page both mode.

isPercentScaling

public boolean isPercentScaling()
Returns true if the scale mode is set to PERCENT.

Returns:
true to indicate the percent scale mode.

getFooterFontHeight

public abstract double getFooterFontHeight()
The method getFooterFontHeight returns the maximum scaled font size of all 3 possible fonts of the footer items. As default 0 is returned. NOTE: this method is intended to be overwritten by sublcasses in order to provide usefull values.

Returns:
the maximum font size.

getHeaderFontHeight

public abstract double getHeaderFontHeight()
Returns the maximum height in pixel used by all the (scaled) header items. As default 0 is returned. NOTE: this method is intended to be overwritten by sublcasses in order to provide usefull values.

Returns:
the maximum font size.

getCopy

public abstract BasePageFormat getCopy()
Returns a copy of this BasePageFormat.

Returns:
a copy of this BasePageFormat.

getPaperName

public java.lang.String getPaperName()
Method getName returns the human readable name of the the underlying paper type of this PageFormat.

Returns:
String the name of this Page paper.

getScaledFont

public FontFormat getScaledFont(FontFormat font)
Method getScaledrFont returns a vertically scaled font instance. Useful if you want to display the text in preview panes with the correct (scaled) size.

Parameters:
font - the font you want to scale.
Returns:
Font the scaled font to be used while previewing this PageFormat.

getScaledFont

public FontFormat getScaledFont(FontFormat font,
                                int dpi)
Method getScaledFont returns a vertically scaled font instance. Useful if you want to display the text in preview panes with the correct (scaled) size.

Parameters:
font - the font you want to scale.
dpi - the device resolution
Returns:
Font the scaled font to be used while previewing this PageFormat.

getVerticalScaleFactor

public double getVerticalScaleFactor()
Calculates a vertical scale factor. Useful to determine correct font size for example when used in preview context.

Returns:
double the current vertical scale factor.

getVerticalScaleFactor

public double getVerticalScaleFactor(int dpi)
Calculates a vertical scale factor. Useful to determine correct font size for example when used in preview context.

Parameters:
dpi - the device resolution
Returns:
double the current vertical scale factor.

getBottomMargin

public double getBottomMargin()
Returns the bottomMargin.

Returns:
double the bottom margin as double.

getLeftMargin

public double getLeftMargin()
Returns the leftMargin.

Returns:
double the left margin as double.

getRightMargin

public double getRightMargin()
Returns the rightMargin.

Returns:
double the right margin as double.

getTopMargin

public double getTopMargin()
Returns the topMargin.

Returns:
double the topMargin as double.

setLeftMargin

public void setLeftMargin(double leftMargin)
Sets the leftMargin.

Parameters:
leftMargin - The leftMargin to set

setTopMargin

public void setTopMargin(double topMargin)
Sets the topMargin and corrects the imageable area of the underlying paper instance.

Parameters:
topMargin - The topMargin to set

setRightMargin

public void setRightMargin(double rightMargin)
Sets the rightMargin.

Parameters:
rightMargin - The rightMargin to set

setBottomMargin

public void setBottomMargin(double bottomMargin)
Sets the bottomMargin.

Parameters:
bottomMargin - The bottomMargin to set

setMargins

public void setMargins(double left,
                       double top,
                       double right,
                       double bottom)
Sets the margins of this PageFormat. Invokes #updatePaper()after assigning the values.

Parameters:
left - margin to the left.
top - margin on top.
right - margin to the right.
bottom - margin to the bottom.

resetMargins

public void resetMargins()
Sets the margin values according to the current imageableX and -Y positions of the underlying paper.


getScale

public double getScale()
Returns the scale. The scale of a PageFormat describes how many pixels should be used per mm.

Returns:
int the scale factor as double.

setScale

public void setScale(double scale)
Sets the scale.

Parameters:
scale - The scale value to set.

setScalingMode

public void setScalingMode(int mode)
Method setScalingMode sets the current mode which will used to scale the printable element.

Parameters:
mode - the new scaling mode.
See Also:
SCALEMODE_FITTOPAGE_HORIZONTAL, SCALEMODE_FITTOPAGE_VERTICAL, SCALEMODE_FITTOPAGE_BOTH, SCALEMODE_PERCENT

getScalingMode

public int getScalingMode()
Method getScalingMode returns the currently set scale mode. This is either one of the predefined modes. (see above)

Returns:
int the current mode identifier for scaling.

getPercent

public int getPercent()
Method getPercent returns the percentage value to be used while in SCALE_PERCENT mode.

Returns:
int the percentage value as int.

setPercent

public void setPercent(int percent)
Method setPercent sets the percent value to be used while in SCALE_PERCENT mode.

Parameters:
percent - the percent value between 0 and 100.

setPaperName

public void setPaperName(java.lang.String name)
Sets the name of this PageFormat.

Parameters:
name - The name to set

getQuality

public int getQuality()
Returns the quality.

Returns:
int the quality identifier.

setQuality

public void setQuality(int quality)
Sets the quality.

Parameters:
quality - The quality to set
See Also:
QUALITY_COLORED, QUALITY_MONO, QUALITY_WIREFRAME

getPagesHorizontal

public int getPagesHorizontal()
The method getPages returns the number of pages to be used when being in SCALEMODE_FITTOPAGE. Either this describes the number of pages horizontal or vertical depending on the mode.

Returns:
the number of pages.

setPagesHorizontal

public void setPagesHorizontal(int pages)
The method setPages sets the number of pages used when being in SCALEMODE_FITTOPAGE mode. For example: If you want to scale your print to 4 Pages horizontal setScalingMode(SCALEMODE_FITTOPAGE_HORIZONTAL); setPages(4);

Parameters:
pages - number of pages to use while scaling as int.

getPagesVertical

public int getPagesVertical()
The method getPages returns the number of pages to be used when being in SCALEMODE_FITTOPAGE. Either this describes the number of pages vertical or vertical depending on the mode.

Returns:
the number of pages.

setPagesVertical

public void setPagesVertical(int pages)
The method setPages sets the number of pages used when being in SCALEMODE_FITTOPAGE mode. For example: If you want to scale your print to 4 Pages vertical setScalingMode(SCALEMODE_FITTOPAGE_VERTICAL); setPages(4);

Parameters:
pages - number of pages to use while scaling as int.

setPages

public void setPages(int pages)
Deprecated. use setPagesHorizontal(int)

The method setPages sets the number of pages used when being in SCALEMODE_FITTOPAGE mode. For example: If you want to scale your print to 4 Pages horizontal setScalingMode(SCALEMODE_FITTOPAGE_HORIZONTAL); setPages(4);

Parameters:
pages - number of pages to use while scaling as int.

getPages

public int getPages()
Deprecated. use #getPagesHorizontal(int)

The method getPages returns the number of pages to be used when being in SCALEMODE_FITTOPAGE. Either this describes the number of pages horizontal or vertical depending on the mode.

Returns:
the number of pages.

toString

public java.lang.String toString()
Returns a human readable description of this BasePageFormat instance. Contains paper name, sizes and margins.

See Also:
Object.toString()

printShadedBackground

public boolean printShadedBackground()
Returns the flag for printing the background or not.

Returns:
true, to indicate that the shaded background of the view should be printed, false otherwise.

setPrintShadedBackground

public void setPrintShadedBackground(boolean b)
Toggles the shaded background flag.

Parameters:
b - the flag to indicate the "print shaded background" toggle.

setPrintSubgraphBackground

public void setPrintSubgraphBackground(boolean b)
Set the flag to indicate whether subgraph background will be printed or not.

Parameters:
b - set to true, to indicate that the background of the subgraphs should be printed. false to turn that off.

printSubgraphBackground

public boolean printSubgraphBackground()
Returns the flag whether to print the background of subgraphs or not.

Returns:
true to indicate that the backgrounds of subgraphs are printed, false otherwise.

setPrintEmptyPages

public void setPrintEmptyPages(boolean b)
Set the flag to indicate whether empty pages will be printed or not.

Parameters:
b - set to true, to indicate that empty pages should be printed. false to turn that off.

printEmptyPages

public boolean printEmptyPages()
Returns the flag whether to print empty pages or not.

Returns:
true to indicate that empty pages should be printed.

getViewPaint

public PaintFormat getViewPaint()
Returns the PaintFormat of a VisualGraphView. Use this instance to restore the background.

Returns:
The PaintFormat used by the View.

setViewPaint

public void setViewPaint(PaintFormat format)
Sets the PaintFormat.

Parameters:
format - the new PaintFormat to store.

setGridPrinting

public void setGridPrinting(boolean printGrid)
Enables / Disables the printing of the grid

Parameters:
printGrid - true, to enable printing of the grid

isGridPrinting

public boolean isGridPrinting()
Returns true, if the grid will be printed also

Returns:
true, if the grid will be printed also


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.