lt.monarch.chart.print
Class ChartPrintable

java.lang.Object
  extended by lt.monarch.print.AbstractPrintable
      extended by lt.monarch.chart.print.ChartPrintable
All Implemented Interfaces:
java.awt.print.Printable, PrintableConstants

public class ChartPrintable
extends AbstractPrintable

Printable implementation for printing views of charts. Size of view before printing, scaling and alignment of printout can be customized using provided methods. If assigned view is instance of MultiSeriesChartBase or instance of CompositeView having an instance of MultiSeriesChartBase as subview, the visible ranges of scrollable mappers of x and y axes of chart can be adjusted or paged. Note that only one instance of ChartPrintable can be created at the same time for the same view.
After printing is finished instance of ChartPrintable must be disposed by calling the dispose() method (you shouldn't care about this only if you use ChartPrintable with SimplePrintPreviewDialog - it does this automatically).


Field Summary
Modifier and Type Field and Description
static int VIEW_SIZE_FILL_PAGES
          Indicates that view should be resized to cover entire printable area of [rows x cols] pages layouted in a grid.
static int VIEW_SIZE_ORIGINAL
          Indicates that view should be printed without changing its current size.
static int VIEW_SIZE_SPECIFIED
          Indicates that view should be resized to user-specified dimensions when printing.
static int VISIBLE_RANGE_FULL
          Indicates that full data range of scrollable (x or y) mapper should be made visible when printing the chart.
static int VISIBLE_RANGE_ORIGINAL
          Indicates that chart should be printed without changing the current visible range of scrollable (x or y) mapper.
static int VISIBLE_RANGE_PAGED
          If this mode is used, data range of scrollable (x or y) mapper is divided into subranges and one chart view is printed for each such subrange.
static int VISIBLE_RANGE_SPECIFIED
          Indicates that user-specified range should be used as visible range of scrollable mapper (x or y) when printing the chart.
 
Fields inherited from class lt.monarch.print.AbstractPrintable
headerFooterRenderer, horizontalAlignment, lastValidPageIndex, scaligFactorSpecified, scalingFitToPagesGridCols, scalingFitToPagesGridRows, scalingMode, verticalAlignment
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface lt.monarch.print.PrintableConstants
ALIGNMENT_BOTTOM, ALIGNMENT_CENTER, ALIGNMENT_LEFT, ALIGNMENT_RIGHT, ALIGNMENT_TOP, SCALING_FACTOR_SPECIFIED, SCALING_FIT_TO_PAGES
 
Constructor Summary
Constructor and Description
ChartPrintable(View viewToPrint)
          Creates new instance of ChartPrintable for printing given view.
 
Method Summary
Modifier and Type Method and Description
 void dispose()
          Clears instance of ChartPrintable.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Implements the print method of Printable interface.
 void setViewSizeFillPagesGrid(int rows, int cols)
          Defines number of rows and columns in the grid of pages, which is used, if the view sizing mode is set as ChartPrintable.VIEW_SIZE_FILL_PAGES (using the setViewSizingMode(int) method).
 void setViewSizeSpecified(int width, int height)
          The view will be resized to the specified size before printing it, if the view sizing mode is set as ChartPrintable.VIEW_SIZE_SPECIFIED (using the setViewSizingMode(int) method).
 void setViewSizingMode(int mode)
          Defines whether size of view should be changed in any way when printing the view.
 void setXVisibleRangeChangingMode(int mode)
          Defines whether visible range of scrollable x mapper should be changed in any way when printing the chart.
 void setXVisibleRangePaging(double start, double end, double step)
          This method specifies which part of x data range should be paged and what step should be used for this purpose, in case if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_PAGED (using the setXVisibleRangeChangingMode(int) method).
 void setXVisibleRangeSpecified(double min, double max)
          Specified visible range will be assigned to scrollable x mapper when printing the chart, if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setXVisibleRangeChangingMode(int) method).
 void setXVisibleRangeSpecified(java.lang.Object minObject, java.lang.Object maxObject)
          Specified visible range will be assigned to scrollable x mapper when printing the chart, if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setXVisibleRangeChangingMode(int) method).
 void setYVisibleRangeChangingMode(int mode)
          Defines whether visible range of scrollable y mapper should be changed in any way when printing the chart.
 void setYVisibleRangePaging(double start, double end, double step)
          This method specifies which part of y data range should be paged and what step should be used for this purpose, in case if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_PAGED (using the setYVisibleRangeChangingMode(int) method).
 void setYVisibleRangeSpecified(double min, double max)
          Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method).
 void setYVisibleRangeSpecified(java.lang.Object minObject, java.lang.Object maxObject)
          Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method).
 void setYVisibleRangeSpecified(java.lang.Object minObject, java.lang.Object maxObject, AbstractAxisMapper yMapper)
          Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method).
 
Methods inherited from class lt.monarch.print.AbstractPrintable
getHeaderFooterRenderer, setHeaderFooterRenderer, setHorizontalAlignment, setScalingFactorSpecified, setScalingFitToPagesGrid, setScalingMode, setVerticalAlignment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VISIBLE_RANGE_ORIGINAL

public static final int VISIBLE_RANGE_ORIGINAL
Indicates that chart should be printed without changing the current visible range of scrollable (x or y) mapper.

See Also:
Constant Field Values

VISIBLE_RANGE_FULL

public static final int VISIBLE_RANGE_FULL
Indicates that full data range of scrollable (x or y) mapper should be made visible when printing the chart.

See Also:
Constant Field Values

VISIBLE_RANGE_SPECIFIED

public static final int VISIBLE_RANGE_SPECIFIED
Indicates that user-specified range should be used as visible range of scrollable mapper (x or y) when printing the chart. Desired visible range can be specified using these methods:

See Also:
Constant Field Values

VISIBLE_RANGE_PAGED

public static final int VISIBLE_RANGE_PAGED
If this mode is used, data range of scrollable (x or y) mapper is divided into subranges and one chart view is printed for each such subrange. If x and y paging is used together, number of views produced equals to 'count of x subranges' multiplied by 'count of y subranges'. By default full range of (x or y) data is paged. Default step for paging is equal to extent of current visible range of (x or y) axis of chart (current = displayed in GUI before initializing ChartPrintable instance). To change defaults setXVisibleRangePaging(double,double,double) and setYVisibleRangePaging(double,double,double) can be used for x and y axes respectively.

See Also:
Constant Field Values

VIEW_SIZE_ORIGINAL

public static final int VIEW_SIZE_ORIGINAL
Indicates that view should be printed without changing its current size.

See Also:
Constant Field Values

VIEW_SIZE_SPECIFIED

public static final int VIEW_SIZE_SPECIFIED
Indicates that view should be resized to user-specified dimensions when printing. Desired size can be specified using the setViewSizeSpecified(int,int) method.

See Also:
Constant Field Values

VIEW_SIZE_FILL_PAGES

public static final int VIEW_SIZE_FILL_PAGES
Indicates that view should be resized to cover entire printable area of [rows x cols] pages layouted in a grid. Number of rows and columns of this grid of pages can be specified using the setViewSizeFillPagesGrid(int,int) method. By default 1 x 1 grid of pages (i.e. one page) is used.

See Also:
Constant Field Values
Constructor Detail

ChartPrintable

public ChartPrintable(View viewToPrint)
Creates new instance of ChartPrintable for printing given view. Note that only one instance of ChartPrintable can be created at the same time for the same view. After printing is finished instance of ChartPrintable must be disposed by calling the dispose() method.

Parameters:
viewToPrint - view for printing.
Method Detail

setXVisibleRangeChangingMode

public void setXVisibleRangeChangingMode(int mode)
Defines whether visible range of scrollable x mapper should be changed in any way when printing the chart. See descriptions of VISIBLE_RANGE_XXX constants.

Parameters:
mode - the constant indicating required changes to visible range when printing the chart. Possible values are:
  • ChartPrintable.VISIBLE_RANGE_ORIGINAL (default),
  • ChartPrintable.VISIBLE_RANGE_FULL,
  • ChartPrintable.VISIBLE_RANGE_SPECIFIED,
  • ChartPrintable.VISIBLE_RANGE_PAGED.

setXVisibleRangeSpecified

public void setXVisibleRangeSpecified(double min,
                                      double max)
Specified visible range will be assigned to scrollable x mapper when printing the chart, if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setXVisibleRangeChangingMode(int) method).

Parameters:
min - normalized value (in range [0.0, 1.0]) of minimum of visible range.
max - normalized value (in range [0.0, 1.0]) of maximum of visible range.

setXVisibleRangeSpecified

public void setXVisibleRangeSpecified(java.lang.Object minObject,
                                      java.lang.Object maxObject)
Specified visible range will be assigned to scrollable x mapper when printing the chart, if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setXVisibleRangeChangingMode(int) method).

Parameters:
minObject - object that can be mapped using scrollable mapper of x axis of chart and represents minimum value of desired visible range.
maxObject - object that can be mapped using scrollable mapper of x axis of chart and represents maximum value of desired visible range.

setXVisibleRangePaging

public void setXVisibleRangePaging(double start,
                                   double end,
                                   double step)
This method specifies which part of x data range should be paged and what step should be used for this purpose, in case if the changing mode of x visible range is set as ChartPrintable.VISIBLE_RANGE_PAGED (using the setXVisibleRangeChangingMode(int) method). By default 0.0d is used as start and 1.0d is used as end, i.e. full range of x data is paged. Default step is equal to extent of current visible range of x axis of chart (current = displayed in GUI before initializing ChartPrintable instance).

Parameters:
start - normalized value indicating the start of data range for paging.
end - normalized value indicating the start of data range for paging.
step - normalized value indicating the step to be used for paging of given [start,end] range into subranges.

setYVisibleRangeChangingMode

public void setYVisibleRangeChangingMode(int mode)
Defines whether visible range of scrollable y mapper should be changed in any way when printing the chart. See descriptions of VISIBLE_RANGE_XXX constants.

Parameters:
mode - the constant indicating required changes to visible range when printing the chart. Possible values are:
  • ChartPrintable.VISIBLE_RANGE_ORIGINAL (default),
  • ChartPrintable.VISIBLE_RANGE_FULL,
  • ChartPrintable.VISIBLE_RANGE_SPECIFIED,
  • ChartPrintable.VISIBLE_RANGE_PAGED.

setYVisibleRangeSpecified

public void setYVisibleRangeSpecified(double min,
                                      double max)
Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method).

Parameters:
min - normalized value (in range [0.0, 1.0]) of minimum of visible range.
max - normalized value (in range [0.0, 1.0]) of maximum of visible range.

setYVisibleRangeSpecified

public void setYVisibleRangeSpecified(java.lang.Object minObject,
                                      java.lang.Object maxObject)
Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method). This method can be used if chart contains only one scrollable y axis.

Parameters:
minObject - object that can be mapped using scrollable mapper of y axis of chart and represents minimum value of desired visible range.
maxObject - object that can be mapped using scrollable mapper of y axis of chart and represents maximum value of desired visible range.

setYVisibleRangeSpecified

public void setYVisibleRangeSpecified(java.lang.Object minObject,
                                      java.lang.Object maxObject,
                                      AbstractAxisMapper yMapper)
Specified visible range will be assigned to scrollable y mapper when printing the chart, if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_SPECIFIED (using the setYVisibleRangeChangingMode(int) method). If chart contains only one scrollable y axis, the setYVisibleRangeSpecified(Object,Object) method can be used instead of this method.

Parameters:
minObject - object that can be mapped using given yMapper and represents minimum value of desired visible range.
maxObject - object that can be mapped using given yMapper and represents maximum value of desired visible range.
yMapper - yMapper scrollable y mapper for mapping minimum and maximum objects.

setYVisibleRangePaging

public void setYVisibleRangePaging(double start,
                                   double end,
                                   double step)
This method specifies which part of y data range should be paged and what step should be used for this purpose, in case if the changing mode of y visible range is set as ChartPrintable.VISIBLE_RANGE_PAGED (using the setYVisibleRangeChangingMode(int) method). By default 0.0d is used as start and 1.0d is used as end, i.e. full range of y data is paged. Default step is equal to extent of current visible range of y axis of chart (current = displayed in GUI before initializing ChartPrintable instance).

Parameters:
start - normalized value indicating the start of data range for paging.
end - normalized value indicating the start of data range for paging.
step - normalized value indicating the step to be used for paging of given [start,end] range into subranges.

setViewSizingMode

public void setViewSizingMode(int mode)
Defines whether size of view should be changed in any way when printing the view. See descriptions of VIEW_SIZE_XXX constants.

Parameters:
mode - the constant indicating required changes to size of view when printing the view. Possible values are:
  • ChartPrintable.VIEW_SIZE_ORIGINAL (default),
  • ChartPrintable.VIEW_SIZE_SPECIFIED,
  • ChartPrintable.VIEW_SIZE_FILL_PAGE.

setViewSizeSpecified

public void setViewSizeSpecified(int width,
                                 int height)
The view will be resized to the specified size before printing it, if the view sizing mode is set as ChartPrintable.VIEW_SIZE_SPECIFIED (using the setViewSizingMode(int) method).

Parameters:
width - desired width of view when printing.
height - desired height of view when printing.

setViewSizeFillPagesGrid

public void setViewSizeFillPagesGrid(int rows,
                                     int cols)
Defines number of rows and columns in the grid of pages, which is used, if the view sizing mode is set as ChartPrintable.VIEW_SIZE_FILL_PAGES (using the setViewSizingMode(int) method). In this case the printable view is resized to cover entire printable area of [rows x cols] pages layouted in a grid. By default [1 x 1] grid of pages (i.e. one page) is used.

Parameters:
rows - positive non-zero value meaning number of rows in grid of pages.
cols - positive non-zero value meaning number of columns in grid of pages.

print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Implements the print method of Printable interface.

Parameters:
graphics - Graphics context
pageFormat - format of page
pageIndex - index of page
Returns:
Returns value showing if requested page has been rendered or not.
Throws:
java.awt.print.PrinterException

dispose

public void dispose()
Clears instance of ChartPrintable. This method must be invoked after printing of view is finished and instance of ChartPrintable is not necessary anymore.

Overrides:
dispose in class AbstractPrintable