Class AWTRenderer

  • All Implemented Interfaces:
    java.awt.print.Pageable, java.awt.print.Printable, Constants, Renderer

    public class AWTRenderer
    extends Java2DRenderer
    implements java.awt.print.Pageable
    The AWTRender outputs the pages generated by the layout engine to a Swing window. This Swing window serves as default viewer for the -awt switch and as an example of how to embed the AWTRenderer into an AWT/Swing application.
    • Field Detail

      • MIME_TYPE

        public static final java.lang.String MIME_TYPE
        The MIME type for AWT-Rendering
        See Also:
        Constant Field Values
      • debug

        public boolean debug
        flag for debugging
      • statusListener

        protected StatusListener statusListener
        Will be notified when rendering progresses
    • Constructor Detail

      • AWTRenderer

        public AWTRenderer​(FOUserAgent userAgent)
        Creates a new AWTRenderer instance.
        Parameters:
        userAgent - the user agent that contains configuration data
      • AWTRenderer

        public AWTRenderer​(FOUserAgent userAgent,
                           Renderable renderable,
                           boolean previewAsMainWindow,
                           boolean show)
        Creates a new AWTRenderer instance.
        Parameters:
        userAgent - the user agent that contains configuration data
        renderable - a Renderable instance can be set so the Preview Dialog can enable the "Reload" button which causes the current document to be reprocessed and redisplayed.
        previewAsMainWindow - true if the preview dialog created by the renderer should be the main window of the application.
        show - sets whether the preview dialog should be created and displayed when the rendering has finished.
    • Method Detail

      • renderPage

        public void renderPage​(PageViewport pageViewport)
                        throws java.io.IOException,
                               FOPException
        This method override only stores the PageViewport in a List. No actual rendering is performed here. A renderer override renderPage() to get the freshly produced PageViewport, and render them on the fly (producing the desired BufferedImages by calling getPageImage(), which lazily starts the rendering process).
        Specified by:
        renderPage in interface Renderer
        Overrides:
        renderPage in class Java2DRenderer
        Parameters:
        pageViewport - the PageViewport object supplied by the Area Tree
        Throws:
        FOPException - thrown by java2DRenderer
        java.io.IOException - In case of an I/O error
        See Also:
        Renderer
      • stopRenderer

        public void stopRenderer()
                          throws java.io.IOException
        Signals the end of the rendering phase. The renderer should reset to an initial state and dispose of any resources for the completed rendering.
        Specified by:
        stopRenderer in interface Renderer
        Overrides:
        stopRenderer in class Java2DRenderer
        Throws:
        java.io.IOException - If an I/O error occurs
      • getPageImageSize

        public java.awt.Dimension getPageImageSize​(int pageNum)
                                            throws FOPException
        Parameters:
        pageNum - the page number
        Returns:
        the dimensions of the specified page
        Throws:
        FOPException - If the page is out of range or has not been rendered.
      • getPageFormat

        public java.awt.print.PageFormat getPageFormat​(int pageIndex)
                                                throws java.lang.IndexOutOfBoundsException
        Specified by:
        getPageFormat in interface java.awt.print.Pageable
        Throws:
        java.lang.IndexOutOfBoundsException
      • getPrintable

        public java.awt.print.Printable getPrintable​(int pageIndex)
                                              throws java.lang.IndexOutOfBoundsException
        Specified by:
        getPrintable in interface java.awt.print.Pageable
        Throws:
        java.lang.IndexOutOfBoundsException
      • supportsOutOfOrder

        public boolean supportsOutOfOrder()
        Check if this renderer supports out of order rendering. If this renderer supports out of order rendering then it means that the pages that are not ready will be prepared and a future page will be rendered.
        Specified by:
        supportsOutOfOrder in interface Renderer
        Overrides:
        supportsOutOfOrder in class AbstractRenderer
        Returns:
        True if the renderer supports out of order rendering
      • getMimeType

        public java.lang.String getMimeType()
        Get the MIME type of the renderer.
        Specified by:
        getMimeType in interface Renderer
        Returns:
        The MIME type of the renderer, may return null if not applicable.
      • drawBackAndBorders

        protected void drawBackAndBorders​(Area area,
                                          float startx,
                                          float starty,
                                          float width,
                                          float height)
        Draws the background and borders and adds a basic debug view // TODO implement visual-debugging as standalone Draw the background and borders. This draws the background and border traits for an area given the position. float, float, float, float)
        Overrides:
        drawBackAndBorders in class AbstractPathOrientedRenderer
        Parameters:
        area - the area to get the traits from
        startx - the start x position
        starty - the start y position
        width - the width of the area
        height - the height of the area
      • debugBackAndBorders

        private void debugBackAndBorders​(Area area,
                                         float startx,
                                         float starty,
                                         float width,
                                         float height)
        Draws a thin border around every area to help debugging
      • getStatusListener

        public StatusListener getStatusListener()
        Returns:
        the StatusListener.
      • setStatusListener

        public void setStatusListener​(StatusListener statusListener)
        Sets a StatusListener this renderer uses to notify about events.
        Parameters:
        statusListener - The StatusListener to set.