Class TLcdComponentPrintable

java.lang.Object
com.luciad.gui.TLcdComponentPrintable
All Implemented Interfaces:
ILcdChangeSource, Printable

public class TLcdComponentPrintable extends Object implements Printable, ILcdChangeSource
Prints the contents of a given Component.
When printing a Component containing an ILcdView, consider using an ALcdViewComponentPrintable.

By default, the component is scaled to fit in the imageable part of the page. Alternatively, the scale of the component on the printer graphics can be specified explicitly (setScale(double)). If the component then no longer fits on a single page, a multi-page print is created, with optional crop marks and positioning marks indicating where and how the pages should be joined (setCropMarks(boolean), setPositioningMarks(boolean)). The method pageCount(PageFormat) allows to see how many pages will be required.

By default, the component is centered on the page or the set of pages. Alternatively, its position can also be set explicitly (setOrigin(Point)).

By default, a border is drawn around the component, but this can be switched off (setBorder(boolean)).

This class offers a regular printing mode, a rasterized printing mode, and a layered printing mode:

  • The regular printing mode has one major disadvantage: the standard printer driver rasterizes the entire print when transparent shapes are printed. The resulting print files are huge (tens to hundreds of megabytes), and the quality of the prints is low. Regular printing is therefore mostly practical for prints that do not contain rasters or transparent filled areas.
  • The rasterized printing mode tries to improve on the regular printing mode by performing the rasterization itself, at a quality that can be configured (see setRasterizedLayerQualityFactor(double)), and using strips whose maximum size can be configured (see setRasterizedLayerMaximumStripSize(int)). The size of the strips provides a way to trade off the memory and the processing time that are required by the print method. Smaller strips require less memory, while larger strips require fewer painting passes and therefore less processing time.
  • The layered printing mode employs a separate rasterized layer and a vector layer. The rasterized layer contains all images and filled areas, combined in a single raster. The vector layer contains all line elements. This technique allows to paint complex transparent shapes at an acceptable quality and with acceptable memory usage. Layered printing has one major disadvantage: all vector graphics are painted on top of all rasterized graphics. Previously hidden vector lines may therefore become visible on top of filled areas.
Rasterized printing and layered printing are only used when necessary. The modes are on by default, but they can be switched off entirely if needed (see setRasterizedRendering(boolean) and setLayeredRendering(boolean)).

Note that the effects of rounding to integer AWT coordinates during painting may become more obvious in print. The component's print method must never overwrite the transformation of the Graphics using the setTransform method. Instead, it must always use relative transformation methods, such as scale.

Notes:

  • The quality and the success of printing is largely dependent on the printer, the native printer driver, and the java interface to the driver, as provided by the java SDK. It is up to the user to make sure that at least the basic printing functionality is set up properly before attempting to use the advanced features of this class.
  • Constructor Details

    • TLcdComponentPrintable

      public TLcdComponentPrintable(Component aComponent)
      Creates a new TLcdComponentPrintable for printing the given Component.
      Parameters:
      aComponent - the component for which to create a Printable
  • Method Details

    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aListener)
      Add a PropertyChangeListener to the listener list. The listener is registered for all properties.
      Parameters:
      aListener - The PropertyChangeListener to be added
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aListener)
      Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
      Parameters:
      aListener - The PropertyChangeListener to be removed
    • firePropertyChange

      protected void firePropertyChange(PropertyChangeEvent aEvent)
      Fire an existing PropertyChangeEvent to any registered listeners. No event is fired if the given event's old and new values are equal and non-null.
      Parameters:
      aEvent - The PropertyChangeEvent object.
    • addChangeListener

      public void addChangeListener(ILcdChangeListener aListener)
      Description copied from interface: ILcdChangeSource

      Registers the given listener so it will receive change events from this source.

      In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source, you can use a ALcdWeakChangeListener instance as change listener.

      Specified by:
      addChangeListener in interface ILcdChangeSource
      Parameters:
      aListener - The listener to be notified when a change has happened.
      See Also:
    • removeChangeListener

      public void removeChangeListener(ILcdChangeListener aListener)
      Description copied from interface: ILcdChangeSource
      Removes the specified listener so it is no longer notified.
      Specified by:
      removeChangeListener in interface ILcdChangeSource
      Parameters:
      aListener - The listener to remove.
    • fireChangeEvent

      protected void fireChangeEvent(TLcdChangeEvent aEvent)
      Fire an existing TLcdChangeEvent to any registered listeners.
      Parameters:
      aEvent - The TLcdChangeEvent object.
    • setComponent

      public void setComponent(Component aComponent)
      Sets the component to be printed.
      Parameters:
      aComponent - the component to be printed.
    • getComponent

      public Component getComponent()
      Returns the component to be printed.
      Returns:
      the component to be printed.
      See Also:
    • setOrigin

      public void setOrigin(Point aOrigin)
      Sets the origin of the component on the page. The default is null, meaning that the component is automatically centered on the page.
      Parameters:
      aOrigin - the origin of the component on the page.
    • getOrigin

      public Point getOrigin()
      Returns the origin of the component on the page.
      Returns:
      the origin of the component on the page.
      See Also:
    • setScale

      public void setScale(double aScale)
      Sets the scale of the component on the page. A scale of 1.0 maps one unit of the component (a pixel) to one unit of the printer graphics (typically 1/72"). Larger scales increase the size of the component on the print, smaller scales decrease the size. A value of 0.0 automatically scales the component so that it fits on the imageable part of the paper. This is also the default.
      Parameters:
      aScale - the scale of the component on the page.
    • getScale

      public double getScale()
      Returns the scale of the component on the page.
      Returns:
      the scale of the component on the page.
      See Also:
    • setBorder

      public void setBorder(boolean aBorder)
      Specifies whether to draw a border around the component. The default is true.
      Parameters:
      aBorder - true to draw a border around the component.
    • getBorder

      public boolean getBorder()
      Returns whether a border is drawn around the component.
      Returns:
      whether a border is drawn around the component.
    • setCropMarks

      public void setCropMarks(boolean aCropMarks)
      Specifies whether to draw crop marks on multi-page prints. The default is true.
      Parameters:
      aCropMarks - true to draw crop marks on multi-page prints.
    • getCropMarks

      public boolean getCropMarks()
      Returns whether crop marks are drawn on multi-page prints.
      Returns:
      whether crop marks are drawn on multi-page prints.
    • setPositioningMarks

      public void setPositioningMarks(boolean aPositioningMarks)
      Specifies whether to draw positioning marks on multi-page prints. The default is true.
      Parameters:
      aPositioningMarks - true to draw positioning marks on multi-page prints.
    • getPositioningMarks

      public boolean getPositioningMarks()
      Returns whether positioning marks are drawn on multi-page prints.
      Returns:
      whether positioning marks are drawn on multi-page prints.
    • setRasterizedRendering

      public void setRasterizedRendering(boolean aRasterizedRendering)
      Specifies whether to use rasterized rendering, when necessary. This technique improves memory usage of prints that contain transparent and translucent elements. Rasterized rendering is enabled by default.
      Parameters:
      aRasterizedRendering - true to use rasterized rendering.
    • getRasterizedRendering

      public boolean getRasterizedRendering()
      Returns whether rasterized rendering is enabled.
      Returns:
      whether rasterized rendering is enabled.
      See Also:
    • setLayeredRendering

      public void setLayeredRendering(boolean aLayeredRendering)
      Specifies whether to use layered rendering, when necessary. This technique improves memory usage and quality of prints that contain transparent and translucent elements. Layered rendering is enabled by default.
      Parameters:
      aLayeredRendering - true to use layered rendering.
    • getLayeredRendering

      public boolean getLayeredRendering()
      Returns whether layered rendering is enabled.
      Returns:
      whether layered rendering is enabled.
      See Also:
    • setForceLayeredRendering

      public void setForceLayeredRendering(boolean aForceLayeredRendering)
      Specifies whether to force layered rendering, rather than only using it when necessary. While producing files that may be larger than strictly necessary, forcing layered rendering can be useful to avoid the possible small discrepancies between filled graphics as they are painted on the screen and as they are painted by the printer driver. More specifically, filled polygons or parts of polygons with zero thickness may look different on the screen and in print. Layered rendering is not forced by default.
      Parameters:
      aForceLayeredRendering - true to force layered rendering.
    • getForceLayeredRendering

      public boolean getForceLayeredRendering()
      Returns whether layered rendering is forced.
      Returns:
      whether layered rendering is forced.
      See Also:
    • setRasterizedLayerQualityFactor

      public void setRasterizedLayerQualityFactor(double aRasterizedLayerQualityFactor)
      Sets the quality factor for the rasterized layer. By default (with a factor of 1.0), when rasterization is required in the layered rendering technique, an image buffer the size of the component is created. Larger factors increase the width and height of the image buffer proportionally, increasing the quality of the rasterized layer. Of course, larger factors also increase the printing time and the size of the printer output file.
      Parameters:
      aRasterizedLayerQualityFactor - the quality factor for the rasterized layer.
    • getRasterizedLayerQualityFactor

      public double getRasterizedLayerQualityFactor()
      Returns the quality factor for the rasterized layer.
      Returns:
      the quality factor for the rasterized layer.
      See Also:
    • setRasterizedLayerMaximumStripSize

      public void setRasterizedLayerMaximumStripSize(int aRasterizedLayerMaximumStripSize)
      Sets the maximum number of pixels in a strip of the rasterized layer. If the layered rendering technique performs rasterization, an image buffer with a size proportional to the size of the component is created. In order to reduce memory usage of the printing system, the full buffer can be replaced by small strips that are processed subsequently. A value of 0 indicates not to use strips. The default maximum number of pixels is 106.
      Parameters:
      aRasterizedLayerMaximumStripSize - the maximum number of pixels in a strip of the rasterized layer.
    • getRasterizedLayerMaximumStripSize

      public int getRasterizedLayerMaximumStripSize()
      Returns the maximum number of pixels in a strip of the rasterized layer.
      Returns:
      the maximum number of pixels in a strip of the rasterized layer.
      See Also:
    • setPageDecorator

      public void setPageDecorator(Printable aPageDecorator)

      Sets a Printable that can be used to decorate each page. It is for example possible to add a watermark to each page using this method.

      The default is null, meaning that no decorations are added.

      Parameters:
      aPageDecorator - the page decorator.
    • getPageDecorator

      public Printable getPageDecorator()
      Returns the Printable that is used as page decorator.
      Returns:
      the Printable that is used as page decorator.
    • pageCount

      public Point pageCount(PageFormat aPageFormat)
      Returns the number of pages in the x direction and y direction, if the component is printed with the current settings on the given page format.
      Parameters:
      aPageFormat - the page format for which the page count is calculated
      Returns:
      the number of pages in the x direction and y direction
    • createPreview

      public TLcdPrintPreview createPreview(PageFormat aPageFormat)
      Creates a preview panel for the given page format.
      Parameters:
      aPageFormat - the page format to use
      Returns:
      a panel visualizing the component
    • print

      public int print(Graphics aGraphics, PageFormat aPageFormat, int aPageIndex)
      Specified by:
      print in interface Printable