com.tensegrity.gui.printing
Class PrintUtil

java.lang.Object
  extended bycom.tensegrity.gui.printing.PrintUtil

public final class PrintUtil
extends java.lang.Object

Class PrintUtil provides useful methods for printing operations inside the Tensegrity API. Furthermore it defines a static BookParameter class which holds information describing how a VisualGraphView is devided into several pages of a given page format. Use the createBookParameter() methods to obtain an instance of this class. Beside that, this method contains several methods to convert mm in inch, or vice versa. It provides a predefined set of paper types and their sizes.

Version:
$Id: PrintUtil.java,v 1.18 2006/05/19 13:39:42 BurkhardWick Exp $
Author:
Gilles Iachelini, BurkhardWick

Nested Class Summary
static class PrintUtil.BookParameter
          Class PrintUtilBookParameter is used to encapsulate all the parameters needed to specify a printout.
 
Field Summary
static BasePageFormat DEFAULT_PAGEFORMAT
          The default PageFormat based on DinA4 and a Portrait orientation.
static java.util.Map paperMap
          Maps paper names to paper sizes.
static java.lang.String[] paperTypeNames
          constant list of available paper type names.
static java.lang.Object[] paperTypeSizes
          Constant list of sizes in mm of the predefined paper types.
static double PRINT_DPI
          The Java print resolution is at 72 dpi.
 
Method Summary
static void adjustBrokenMargins(BasePageFormat cpf)
          This method tries to adjust the margins of a page format, which margins seem broken.
static void adjustMargins(BasePageFormat aFormat)
          Adjusts the margins of a PageFormat to the default margins of the original imageable size, if a certain margin is out of the imageable bounds.
static PrintUtil.BookParameter calculateRowsAndColumns(BasePageFormat cpf, double pageWidth, double pageHeight, Boundary bboxComposites)
          The method calcuatRowsAndColumns calculates the required number of pages according to a page format, current page width and height, view's metrics.
static boolean checkMargins(BasePageFormat aFormat)
          This method validates the margins of the given CustomPageFormat parameter against the default PageFormat of this paper type.
static PrintUtil.BookParameter createBookParameter(BasePageFormat pageFormat, VisualGraphView view)
          Creates a BookParameter instance which describes the amount of pages needed to print the given view with the specified page format.
static PrintUtil.BookParameter createBookParameter(BasePageFormat pageFormat, VisualGraphView view, int dpi)
          Creates a BookParameter instance which describes the amount of pages needed to print the given view with the specified page format using a certain resolution.
static boolean differsFromDefaultMargin(BasePageFormat aFormat)
          Checks whether one of the margins of the given PageFormat differs from the original default margin.
static BasePageFormat getPageFormat(java.lang.String paperName, int orientation)
          Returns a PageFormat for the given Paper type, which will be validated by the PrinterJob to determine the printable area.
static double[] getPaperSize(java.lang.String key)
          Method getPaperSize fetches the array of double's holding the size of the given paper type and returns it, or null if no such type has been mapped yet.
static int getPaperTypeIndex(java.lang.String type)
          Method getPaperTypeIndex returns the index within the paperTypeNames array of the parameter type specifier.
static Renderer getRenderer(BasePageFormat cpf, double aViewscaleX, double aViewscaleY)
          Method getRenderer returns the renderer according to the parameter PageFormat quality setting.
static Boundary getViewBounds(VisualGraphView view)
          Calculates the boundaries of the view that should be used for printing
static void growBoundingBoxForStrokeZoom(VisualGraphView view, Boundary bboxComposites)
          This method resizes a bounding box to include the strokes that are lying on the border of the bounds.
static double inch2mm(double inch)
          Converts an inch value to mm.
static double mm2pt(double mm)
          Converts an mm value to point.
static double mm2px(double mm)
          This is always required when dealing with the margins of a paper.
static double px2mm(double pixel)
          Converts pixels to millimeter by using fixed resolution and constant mmPerInch.
static java.lang.String replaceIdentifier(java.lang.String text, int pageIndex, int pageCount)
          The method replaceIdentifier replaces all occurrences in the parameter String.
static boolean validMargins(BasePageFormat aFormat)
          This method simply checks whether the margins of the parameter format are greater or equal 0.0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRINT_DPI

public static final double PRINT_DPI
The Java print resolution is at 72 dpi.

See Also:
Constant Field Values

paperTypeNames

public static final java.lang.String[] paperTypeNames
constant list of available paper type names.


paperTypeSizes

public static final java.lang.Object[] paperTypeSizes
Constant list of sizes in mm of the predefined paper types.


paperMap

public static final java.util.Map paperMap
Maps paper names to paper sizes. This is a String-double[]-map.


DEFAULT_PAGEFORMAT

public static final BasePageFormat DEFAULT_PAGEFORMAT
The default PageFormat based on DinA4 and a Portrait orientation.

Method Detail

getPaperSize

public static final double[] getPaperSize(java.lang.String key)
Method getPaperSize fetches the array of double's holding the size of the given paper type and returns it, or null if no such type has been mapped yet.

Parameters:
key - the paper type of which you like to receive the size from.
Returns:
double[] the width and height of the paper in mm

getPageFormat

public static final BasePageFormat getPageFormat(java.lang.String paperName,
                                                 int orientation)
Returns a PageFormat for the given Paper type, which will be validated by the PrinterJob to determine the printable area.

Parameters:
paperName - the name as String of the PaperType as their are listed in paperTypeNames.
orientation - papers orientation.
Returns:
PageFormat a newly created PageFormat.
See Also:
PageFormat.PORTRAIT, PageFormat.LANDSCAPE

validMargins

public static boolean validMargins(BasePageFormat aFormat)
This method simply checks whether the margins of the parameter format are greater or equal 0.0.

Parameters:
aFormat - a format to check.
Returns:
true, if all margins are greater or equal 0.0.

adjustBrokenMargins

public static void adjustBrokenMargins(BasePageFormat cpf)
This method tries to adjust the margins of a page format, which margins seem broken. Broken margins are often a result, when trying to use a paper format, which isn't supported by the current selected printer. This method will try to adjust the broken margin. The opposite margin is then used as new value for the broken one. If all margins are valid, nothing is adjusted.

Parameters:
cpf - the format to adjust.

px2mm

public static double px2mm(double pixel)
Converts pixels to millimeter by using fixed resolution and constant mmPerInch. This is always required when dealing with the margins of a paper. It is absolutely required to preserve the original accuracy.

Parameters:
pixel - the number of pixels you like to convert to mm.
Returns:
pixel in millimeter.

mm2px

public static double mm2px(double mm)
This is always required when dealing with the margins of a paper. It is absolutely required to preserve the original accuracy.

Parameters:
mm - the amount of millimeter which needs to be converted to pixel.
Returns:
the amount of pixel matching the the parameter millimeter.

inch2mm

public static double inch2mm(double inch)
Converts an inch value to mm.

Parameters:
inch - The distance in inch
Returns:
The distance in mm

mm2pt

public static double mm2pt(double mm)
Converts an mm value to point.

Parameters:
mm - The distance in mm
Returns:
The distance in points

getPaperTypeIndex

public static final int getPaperTypeIndex(java.lang.String type)
                                   throws java.lang.IllegalArgumentException
Method getPaperTypeIndex returns the index within the paperTypeNames array of the parameter type specifier.

Parameters:
type - the type of paper of which you like to receive the index from.
Returns:
int the index of the type within the array.
Throws:
java.lang.IllegalArgumentException - thrown if the type is not found.

calculateRowsAndColumns

public static final PrintUtil.BookParameter calculateRowsAndColumns(BasePageFormat cpf,
                                                                    double pageWidth,
                                                                    double pageHeight,
                                                                    Boundary bboxComposites)
The method calcuatRowsAndColumns calculates the required number of pages according to a page format, current page width and height, view's metrics. The given Boundary will be fit to the page. The parameter pageWidth and pageHeight modified, so there is enough space for the optional header and footer.

According to the currently used scale mode the passed boundary instances are modified. When using the fit-to-page mode, both boundary instances are modified so, that they fit into the desired pages.

Parameters:
cpf - The PageFormat to base on.
pageWidth - the pageWidth
pageHeight - the pageHeight
bboxComposites - the boundary (will not be modified!)
Returns:
an instance of class BookParameter, which holds a factor and the amount of expected rows and columns.

createBookParameter

public static final PrintUtil.BookParameter createBookParameter(BasePageFormat pageFormat,
                                                                VisualGraphView view)
Creates a BookParameter instance which describes the amount of pages needed to print the given view with the specified page format.

Parameters:
pageFormat - The PageFormat to create the book for,
view - the view which needs to be book'ed.
Returns:
BookParameter the BookParameter for the given view based on the given PageFormat.

createBookParameter

public static final PrintUtil.BookParameter createBookParameter(BasePageFormat pageFormat,
                                                                VisualGraphView view,
                                                                int dpi)
Creates a BookParameter instance which describes the amount of pages needed to print the given view with the specified page format using a certain resolution.

Parameters:
pageFormat - The PageFormat to create the book for,
view - the view which needs to be book'ed.
dpi - the dpi of the printer
Returns:
BookParameter the BookParameter for the given view based on the given PageFormat.

checkMargins

public static final boolean checkMargins(BasePageFormat aFormat)
This method validates the margins of the given CustomPageFormat parameter against the default PageFormat of this paper type. Therefore it creates a reference PageFormat and compares the margins to each other. Is one margin of the parameter PageFormat smaller than the margin of the reference Format, false is returned.

Parameters:
aFormat - the PageFormat to check.
Returns:
true if the margins of the given PageFormat still cover the printable area of the paper.

differsFromDefaultMargin

public static final boolean differsFromDefaultMargin(BasePageFormat aFormat)
Checks whether one of the margins of the given PageFormat differs from the original default margin.

Parameters:
aFormat - a PageFormat to check.
Returns:
true, if one of the margins is != PrintUtil#defaultMargin.

adjustMargins

public static final void adjustMargins(BasePageFormat aFormat)
Adjusts the margins of a PageFormat to the default margins of the original imageable size, if a certain margin is out of the imageable bounds.

Parameters:
aFormat - the PageFormat which needs to be adjusted.

replaceIdentifier

public static java.lang.String replaceIdentifier(java.lang.String text,
                                                 int pageIndex,
                                                 int pageCount)
The method replaceIdentifier replaces all occurrences in the parameter String. Currently supported identifiers are &[Date], &[Time], &[Page] and [&PageCount].

Parameters:
text - the text to operate on.
pageIndex - the current page index.
pageCount - the total amount of pages.
Returns:
the String where all occurrences of the known tags are replaced.

getRenderer

public static final Renderer getRenderer(BasePageFormat cpf,
                                         double aViewscaleX,
                                         double aViewscaleY)
Method getRenderer returns the renderer according to the parameter PageFormat quality setting.

Parameters:
cpf - The page format
aViewscaleX - The scale in x direction
aViewscaleY - The scale in y direction
Returns:
The created renderer

growBoundingBoxForStrokeZoom

public static void growBoundingBoxForStrokeZoom(VisualGraphView view,
                                                Boundary bboxComposites)
This method resizes a bounding box to include the strokes that are lying on the border of the bounds.

Parameters:
view - The view
bboxComposites - The bounding box to extend

getViewBounds

public static Boundary getViewBounds(VisualGraphView view)
Calculates the boundaries of the view that should be used for printing

Parameters:
view - The view to get the boundaries of
Returns:
The boundaries


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