Search this API

y.view
Class Graph2DPrinter

java.lang.Object
  extended by y.view.Graph2DPrinter
All Implemented Interfaces:
java.awt.print.Printable

public class Graph2DPrinter
extends java.lang.Object
implements java.awt.print.Printable

This class is responsible for printing the contents of a Graph2DView on one or more pages. This class implements the Printable interface and can thus be passed to a PrinterJob instance for printing.

 

Nested Class Summary
static class Graph2DPrinter.AbstractFooterDrawable
          Abstract footer drawable that defines the position of the footer on a page and manages the background color.
static class Graph2DPrinter.AbstractTextBarDrawable
          Abstract base drawable for titles and footers.
static class Graph2DPrinter.AbstractTitleDrawable
          Abstract title drawable that defines the position of the footer on a page and manages the background color.
static class Graph2DPrinter.DefaultFooterDrawable
          Default footer drawable implementation.
static class Graph2DPrinter.DefaultTitleDrawable
          Default title drawable implementation.
static interface Graph2DPrinter.FooterDrawable
          Interface for classes that want to add a footer to the printed page.
static class Graph2DPrinter.PrintContext
          Class that encapsulates contextual information when printing a page.
static class Graph2DPrinter.RepeatingFooterDrawable
          A footer drawable that paints a footer on every page.
static class Graph2DPrinter.RepeatingTitleDrawable
          A title drawable that paints a footer on every page.
static interface Graph2DPrinter.TitleDrawable
          Interface for classes that want to add a title to the printed page.
 
Field Summary
static byte CLIP_CUSTOM
          Clip type specifier constant.
static byte CLIP_GRAPH
          Clip type specifier constant.
static byte CLIP_VIEW
          Clip type specifier constant.
static byte SCALING_AUTO
          Scaling type specifier constant.
static byte SCALING_FIX
          Scaling type specifier constant.
static byte TITLE_AND_FOOTER_FOR_ENTIRE_POSTER
           
static byte TITLE_AND_FOOTER_FOR_EVERY_PAGE
           
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
Graph2DPrinter(Graph2DView view)
          Instantiates a new Graph2DPrinter for the given Graph2DView.
 
Method Summary
protected  GraphicsContext createGraphicsContext(Graph2DView view, java.awt.Graphics2D g2d)
          Creates the GraphicsContext that will be used for the graphics object during printing.
 byte getClipType()
          Returns the clipping type to be applied for printing.
 java.awt.geom.Rectangle2D getCustomClip()
          Returns the custom area clip measured in world coordinates.
 java.awt.Dimension getFixedScalingPosterDimension(java.awt.print.PageFormat pf)
          Returns the best-fit poster dimension measured in number of page columns and page rows.
 Graph2DPrinter.FooterDrawable getFooterDrawable()
          Returns the footer drawable of this class.
 int getPosterColumns()
          Returns the number of page columns to be used for printing.
 int getPosterRows()
          Returns the number of page rows to be used for printing.
 boolean getPrintPosterCoords()
          Whether or not to number the pages by poster coordinates.
 java.awt.RenderingHints getRenderingHints()
          Returns the default rendering hints to be used when printing the graph.
 double getScalingFactor()
          Returns the scale factor which is used when scale type is set to SCALING_FIX.
 byte getScalingType()
          Sets the scaling type to be applied for printing.
 byte getTextBarType()
          Returns the type of title and footer.
 Graph2DPrinter.TitleDrawable getTitleDrawable()
          Returns the title drawable of this class.
protected  void initializePosterCoordsFont(java.awt.Graphics2D gfx, Graph2DPrinter.PrintContext context)
          Initialize the font for the page's coordinates (column, row) in the poster that are drawn in the upper left corner of the page.
 boolean isCenterContentsOnPageEnabled()
          Whether or not to center the contents on the page(s).
 int print(java.awt.Graphics g1d, java.awt.print.PageFormat pf, int pi)
          Printable implementation.
protected  void printGraph(java.awt.Graphics2D gfx, Graph2DView view, java.awt.Rectangle area)
          Renders the content of the given view for printing.
protected  void printPosterCoords(java.awt.Graphics2D gfx, Graph2DPrinter.PrintContext context)
          Draws the page's coordinates (column, row) in the poster in the upper left corner of the page.
 void setCenterContentsOnPageEnabled(boolean centerOnPage)
          Whether or not to center the contents on the page(s).
 void setClipType(byte clipType)
          Sets the clipping type to be applied for printing.
 void setCustomClip(java.awt.geom.Rectangle2D clip)
          Sets the custom area clip measured in world coordinates.
 void setFooterDrawable(Graph2DPrinter.FooterDrawable fd)
          Sets the footer drawable of this class.
 void setPosterColumns(int columns)
          Sets the number of page columns to be used for printing.
 void setPosterRows(int rows)
          Sets the number of page rows to be used for printing.
 void setPrintPosterCoords(boolean ppc)
          Whether or not to number the pages by poster coordinates.
 void setRenderingHints(java.awt.RenderingHints renderingHints)
          Sets the default rendering hints to be used when printing the graph.
 void setScalingFactor(double scalingFactor)
          Sets the scale factor which is used when the scaling type is set to SCALING_FIX.
 void setScalingType(byte scalingType)
          Sets the scaling type to be applied for printing.
 void setTextBarType(byte type)
          Sets the type of title and footer.
 void setTitleDrawable(Graph2DPrinter.TitleDrawable td)
          Sets the title drawable of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TITLE_AND_FOOTER_FOR_ENTIRE_POSTER

public static final byte TITLE_AND_FOOTER_FOR_ENTIRE_POSTER
See Also:
Constant Field Values

TITLE_AND_FOOTER_FOR_EVERY_PAGE

public static final byte TITLE_AND_FOOTER_FOR_EVERY_PAGE
See Also:
Constant Field Values

SCALING_AUTO

public static final byte SCALING_AUTO
Scaling type specifier constant. The document is scaled automatically to fit in the defined poster size.

See Also:
Constant Field Values

SCALING_FIX

public static final byte SCALING_FIX
Scaling type specifier constant. The document is scaled according to a user-defined scale factor. This scaling policy implies that the number of poster columns and rows will be chosen automatically to fit the scaled graph on the poster.

See Also:
setScalingFactor(double), Constant Field Values

CLIP_VIEW

public static final byte CLIP_VIEW
Clip type specifier constant. Prints the part of the document that is currently seen through the viewport of the associated view.

See Also:
setClipType(byte), Constant Field Values

CLIP_GRAPH

public static final byte CLIP_GRAPH
Clip type specifier constant. Prints the complete Document viewable with the associated Graph2DView.

See Also:
setClipType(byte), Constant Field Values

CLIP_CUSTOM

public static final byte CLIP_CUSTOM
Clip type specifier constant. Prints a rectangular area that can be specified with method setCustomClip(Rectangle2D)

See Also:
setClipType(byte), Constant Field Values
Constructor Detail

Graph2DPrinter

public Graph2DPrinter(Graph2DView view)
Instantiates a new Graph2DPrinter for the given Graph2DView.

Method Detail

setPrintPosterCoords

public void setPrintPosterCoords(boolean ppc)
Whether or not to number the pages by poster coordinates. This feature is not set by default.


getPrintPosterCoords

public boolean getPrintPosterCoords()
Whether or not to number the pages by poster coordinates.

See Also:
setPrintPosterCoords(boolean)

setCenterContentsOnPageEnabled

public void setCenterContentsOnPageEnabled(boolean centerOnPage)
Whether or not to center the contents on the page(s). When enabled the print contents will be printed centered on the page. Otherwise the contents top-left corner will be aligned with the to top-left corner of the page. This feature is enabled by default.

See Also:
isCenterContentsOnPageEnabled()

isCenterContentsOnPageEnabled

public boolean isCenterContentsOnPageEnabled()
Whether or not to center the contents on the page(s). When enabled the print contents will be printed centered on the page. Otherwise the contents top-left corner will be aligned with the to top-left corner of the page. This feature is enabled by default.

See Also:
setCenterContentsOnPageEnabled(boolean)

setPosterRows

public void setPosterRows(int rows)
Sets the number of page rows to be used for printing. By default 1 page row is used


setPosterColumns

public void setPosterColumns(int columns)
Sets the number of page columns to be used for printing. By default 1 page row is used


getPosterRows

public int getPosterRows()
Returns the number of page rows to be used for printing.

See Also:
setPosterRows(int)

getPosterColumns

public int getPosterColumns()
Returns the number of page columns to be used for printing.

See Also:
setPosterColumns(int)

setClipType

public void setClipType(byte clipType)
Sets the clipping type to be applied for printing. By default CLIP_GRAPH is set.

Parameters:
clipType - One of CLIP_VIEW, CLIP_GRAPH.

getClipType

public byte getClipType()
Returns the clipping type to be applied for printing.

See Also:
setClipType(byte)

setScalingFactor

public void setScalingFactor(double scalingFactor)
Sets the scale factor which is used when the scaling type is set to SCALING_FIX.

Parameters:
scalingFactor - scale factor, must be positive.

getScalingFactor

public double getScalingFactor()
Returns the scale factor which is used when scale type is set to SCALING_FIX.

Returns:
a positive value.
See Also:
setScalingFactor(double)

setScalingType

public void setScalingType(byte scalingType)
Sets the scaling type to be applied for printing.

Parameters:
scalingType - One of SCALING_AUTO, SCALING_FIX.

getScalingType

public byte getScalingType()
Sets the scaling type to be applied for printing.

Returns:
One of SCALING_AUTO, SCALING_FIX.
See Also:
setScalingType(byte)

setCustomClip

public void setCustomClip(java.awt.geom.Rectangle2D clip)
Sets the custom area clip measured in world coordinates. The custom clip has only meaning if the clip type CLIP_CUSTOM is specified.


getCustomClip

public java.awt.geom.Rectangle2D getCustomClip()
Returns the custom area clip measured in world coordinates. The custom clip has only meaning if the clip type CLIP_CUSTOM is specified.


getTextBarType

public byte getTextBarType()
Returns the type of title and footer.

Returns:
either TITLE_AND_FOOTER_FOR_ENTIRE_POSTER or TITLE_AND_FOOTER_FOR_EVERY_PAGE.

setTextBarType

public void setTextBarType(byte type)
Sets the type of title and footer.

Parameters:
type - either TITLE_AND_FOOTER_FOR_ENTIRE_POSTER or TITLE_AND_FOOTER_FOR_EVERY_PAGE.

print

public int print(java.awt.Graphics g1d,
                 java.awt.print.PageFormat pf,
                 int pi)
          throws java.awt.print.PrinterException
Printable implementation. This agent will produce getPosterColumns()*getPosterRows() number of pages. The clipped part of the document will be printed centered on these pages with maximum uniform scaling applied.

This method can also be used to produce (print) preview images. In such cases it is important that there is a clip defined on the given graphics context.

Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

printGraph

protected void printGraph(java.awt.Graphics2D gfx,
                          Graph2DView view,
                          java.awt.Rectangle area)
Renders the content of the given view for printing.

Called from print(Graphics, PageFormat, int).

Parameters:
gfx - the configured graphics context associated with the print operation.
view - the view whose content has to be rendered.
area - the area in view coordinates that should be rendered.

printPosterCoords

protected void printPosterCoords(java.awt.Graphics2D gfx,
                                 Graph2DPrinter.PrintContext context)
Draws the page's coordinates (column, row) in the poster in the upper left corner of the page.

This method may be overwritten to customize poster coordinates printing.

Parameters:
gfx - the current graphics context
context - information about the page to be printed

initializePosterCoordsFont

protected void initializePosterCoordsFont(java.awt.Graphics2D gfx,
                                          Graph2DPrinter.PrintContext context)
Initialize the font for the page's coordinates (column, row) in the poster that are drawn in the upper left corner of the page.

This implementation takes the current font of the graphics context and sets its size to 11. It may be overwritten to set a customized font for poster coordinates printing.

Parameters:
gfx - the current graphics context
context - information about the page to be printed

getFixedScalingPosterDimension

public java.awt.Dimension getFixedScalingPosterDimension(java.awt.print.PageFormat pf)
Returns the best-fit poster dimension measured in number of page columns and page rows.

Returns:
poster columns x poster rows

createGraphicsContext

protected GraphicsContext createGraphicsContext(Graph2DView view,
                                                java.awt.Graphics2D g2d)
Creates the GraphicsContext that will be used for the graphics object during printing. This implementation sets the GraphicsContext.isPrinting() property to true.

Parameters:
view - the view that will be used for the painting.
g2d - the graphics object to use for the painting
Returns:
the context to register with the graphics object or null.

setTitleDrawable

public void setTitleDrawable(Graph2DPrinter.TitleDrawable td)
Sets the title drawable of this class.


getTitleDrawable

public Graph2DPrinter.TitleDrawable getTitleDrawable()
Returns the title drawable of this class.


setFooterDrawable

public void setFooterDrawable(Graph2DPrinter.FooterDrawable fd)
Sets the footer drawable of this class.


getFooterDrawable

public Graph2DPrinter.FooterDrawable getFooterDrawable()
Returns the footer drawable of this class.


setRenderingHints

public void setRenderingHints(java.awt.RenderingHints renderingHints)
Sets the default rendering hints to be used when printing the graph. By default the following rendering hints are set: RenderingHints.KEY_FRACTIONALMETRICS = RenderingHints.VALUE_FRACTIONALMETRICS_ON.

See Also:
getRenderingHints()

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
Returns the default rendering hints to be used when printing the graph. By default the following rendering hints are set: RenderingHints.KEY_FRACTIONALMETRICS = RenderingHints.VALUE_FRACTIONALMETRICS_ON.


© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.