Class PrintPreview

  • All Implemented Interfaces:
    org.eclipse.swt.graphics.Drawable

    public class PrintPreview
    extends org.eclipse.swt.widgets.Canvas
    A WYSIWYG (what you see is what you get) print preview panel. This control displays a preview of what a PrintJob will look like on paper, depending on the selected printer.
    Styles:
    (none)
    Events:
    (none)
    • Constructor Summary

      Constructors 
      Constructor Description
      PrintPreview​(org.eclipse.swt.widgets.Composite parent, int style)
      Constructs a PrintPreview control.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private org.eclipse.swt.graphics.Point addTrim​(org.eclipse.swt.graphics.Point size)  
      private static float checkScale​(float scale)  
      org.eclipse.swt.graphics.Point computeSize​(double scale)
      Returns the control size needed to display a full page at the given scale.
      org.eclipse.swt.graphics.Point computeSize​(int wHint, int hHint, boolean changed)  
      private void configureAntialiasing​(org.eclipse.swt.graphics.GC printerGC)  
      private void disposeGC()  
      private void disposePages()  
      private void disposePrinter()  
      private void disposeResources()  
      private void disposeResources​(org.eclipse.swt.graphics.Image printerImage, org.eclipse.swt.graphics.GC printerGC, org.eclipse.swt.graphics.Transform printerTransform, org.eclipse.swt.graphics.Image displayImage, PrintPiece page)  
      private void drawBackground​(org.eclipse.swt.widgets.Event event)  
      private void fetchPages​(int endIndex)  
      float getAbsoluteScale()
      Calculates the absolute scale that the print preview is displaying at.
      private float getAbsoluteScale​(org.eclipse.swt.graphics.Point controlSize)  
      private org.eclipse.swt.graphics.Point getBoilerplateSize()  
      private org.eclipse.swt.graphics.GC getGC()  
      int getHorizontalPageCount()
      Returns how many pages will be displayed in the horizontal direction.
      org.eclipse.swt.graphics.Rectangle getMargins()
      Returns a Rectangle whose x, y, width, and height fields respectively indicate the margin at the left, top, right, and bottom edges of the control.
      int getPageCount()
      Returns the known number of pages in the print job.
      private org.eclipse.swt.graphics.Point[] getPageDisplayLocations()  
      private org.eclipse.swt.graphics.Point getPageDisplaySize()  
      int getPageIndex()
      Returns the index of the first visible page.
      org.eclipse.swt.graphics.Point getPageSpacing()
      Returns a Point whose x and y fields respectively indicate the horizontal and vertical spacing between pages on the control.
      private org.eclipse.swt.graphics.Point getPaperSize()  
      private org.eclipse.swt.printing.Printer getPrinter()  
      org.eclipse.swt.printing.PrinterData getPrinterData()
      Returns the PrinterData for the printer to preview on.
      PrintJob getPrintJob()
      Returns the print job.
      float getScale()
      Returns the view scale.
      int getVerticalPageCount()
      Returns how many pages will be displayed in the vertical direction.
      private void invalidatePageDisplayBounds()  
      boolean isFitHorizontal()
      Returns whether the page scales to fit the document horizontally.
      boolean isFitVertical()
      Returns whether the page scales to fit the document vertically.
      boolean isLazyPageLayout()
      Returns whether the preview lays out pages lazily.
      boolean isPageLayoutComplete()
      Returns whether all pages have been laid out.
      private boolean orientationRequiresRotate()  
      private void paint​(org.eclipse.swt.widgets.Event event)  
      private void paintPage​(org.eclipse.swt.widgets.Event event, PrintPiece page, org.eclipse.swt.graphics.Point location)  
      void setFitHorizontal​(boolean fitHorizontal)
      Sets whether the page scales to fit the document horizontally.
      void setFitVertical​(boolean fitVertical)
      Sets whether the page scales to fit the document vertically.
      void setHorizontalPageCount​(int horizontalPages)
      Sets how many pages will be displayed in the horizontal direction.
      void setLazyPageLayout​(boolean lazy)
      Sets whether the preview lays out pages lazily.
      void setMargins​(org.eclipse.swt.graphics.Rectangle margins)
      Sets the margins at each edge of the control to the argument.
      void setPageIndex​(int pageIndex)
      Sets the index of the first visible page to the argument.
      void setPageSpacing​(org.eclipse.swt.graphics.Point pageSpacing)
      Sets the horizontal and vertical spacing between pages to the argument.
      void setPrinterData​(org.eclipse.swt.printing.PrinterData printerData)
      Sets the PrinterData for the printer to preview on.
      void setPrintJob​(PrintJob printJob)
      Sets the print job to preview.
      void setScale​(float scale)
      Sets the view scale.
      void setVerticalPageCount​(int verticalPages)
      Sets how many pages will be displayed in the vertical direction.
      void startBackgroundLayout​(java.lang.Runnable callback)
      Begins lazy loading in the background, invoking the callback runnable periodically as pages are laid out.
      • Methods inherited from class org.eclipse.swt.widgets.Canvas

        drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
      • Methods inherited from class org.eclipse.swt.widgets.Composite

        changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
      • Methods inherited from class org.eclipse.swt.widgets.Scrollable

        computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
      • Methods inherited from class org.eclipse.swt.widgets.Control

        addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
      • Methods inherited from class org.eclipse.swt.widgets.Widget

        addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • printerData

        private org.eclipse.swt.printing.PrinterData printerData
      • pageIndex

        private int pageIndex
      • fitHorizontal

        private boolean fitHorizontal
      • fitVertical

        private boolean fitVertical
      • scale

        private float scale
      • horizontalPageCount

        private int horizontalPageCount
      • verticalPageCount

        private int verticalPageCount
      • lazy

        private boolean lazy
      • paperSize

        private org.eclipse.swt.graphics.Point paperSize
      • printer

        private org.eclipse.swt.printing.Printer printer
      • gc

        private org.eclipse.swt.graphics.GC gc
      • pageDisplaySize

        private org.eclipse.swt.graphics.Point pageDisplaySize
      • pageDisplayLocations

        private org.eclipse.swt.graphics.Point[] pageDisplayLocations
      • margins

        private org.eclipse.swt.graphics.Rectangle margins
      • pageSpacing

        private org.eclipse.swt.graphics.Point pageSpacing
    • Constructor Detail

      • PrintPreview

        public PrintPreview​(org.eclipse.swt.widgets.Composite parent,
                            int style)
        Constructs a PrintPreview control.
        Parameters:
        parent - the parent control.
        style - the control style.
    • Method Detail

      • getPrintJob

        public PrintJob getPrintJob()
        Returns the print job.
        Returns:
        the print job.
      • setPrintJob

        public void setPrintJob​(PrintJob printJob)
        Sets the print job to preview.
        Parameters:
        printJob - the print job to preview.
      • getPrinterData

        public org.eclipse.swt.printing.PrinterData getPrinterData()
        Returns the PrinterData for the printer to preview on.
        Returns:
        the PrinterData for the printer to preview on.
      • setPrinterData

        public void setPrinterData​(org.eclipse.swt.printing.PrinterData printerData)
        Sets the PrinterData for the printer to preview on.
        Parameters:
        printerData - the PrinterData for the printer to preview on.
      • getPageIndex

        public int getPageIndex()
        Returns the index of the first visible page.
        Returns:
        the index of the first visible page.
      • setPageIndex

        public void setPageIndex​(int pageIndex)
        Sets the index of the first visible page to the argument.
        Parameters:
        pageIndex - the page index.
      • getPageCount

        public int getPageCount()
        Returns the known number of pages in the print job. If setLazyPageLayout(boolean) is set to true, this method returns the number of pages laid out so far. This method returns 0 when getPrintJob() is null or getPrinterData() is null.
        Returns:
        the known number of pages in the print job.
      • isPageLayoutComplete

        public boolean isPageLayoutComplete()
        Returns whether all pages have been laid out.
        Returns:
        whether all pages have been laid out.
      • isFitHorizontal

        public boolean isFitHorizontal()
        Returns whether the page scales to fit the document horizontally.
        Returns:
        whether the page scales to fit the document horizontally.
      • setFitHorizontal

        public void setFitHorizontal​(boolean fitHorizontal)
        Sets whether the page scales to fit the document horizontally.
        Parameters:
        fitHorizontal - whether the page scales to fit the document horizontally.
      • isFitVertical

        public boolean isFitVertical()
        Returns whether the page scales to fit the document vertically.
        Returns:
        whether the page scales to fit the document vertically.
      • setFitVertical

        public void setFitVertical​(boolean fitVertical)
        Sets whether the page scales to fit the document vertically.
        Parameters:
        fitVertical - whether the page scales to fit the document vertically.
      • getScale

        public float getScale()
        Returns the view scale. The document displays at this scale when !(isFitHorizontal() || isFitVertical()).
        Returns:
        the view scale.
      • setScale

        public void setScale​(float scale)
        Sets the view scale.
        Parameters:
        scale - the view scale. A scale of 1.0 causes the document to appear at full size on the computer screen.
      • checkScale

        private static float checkScale​(float scale)
      • getHorizontalPageCount

        public int getHorizontalPageCount()
        Returns how many pages will be displayed in the horizontal direction.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Returns:
        how many pages will be displayed in the horizontal direction.
      • setHorizontalPageCount

        public void setHorizontalPageCount​(int horizontalPages)
        Sets how many pages will be displayed in the horizontal direction.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Parameters:
        horizontalPages - how many pages will be displayed in the horizontal direction.
      • getVerticalPageCount

        public int getVerticalPageCount()
        Returns how many pages will be displayed in the vertical direction.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Returns:
        how many pages will be displayed in the vertical direction.
      • setVerticalPageCount

        public void setVerticalPageCount​(int verticalPages)
        Sets how many pages will be displayed in the vertical direction.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Parameters:
        verticalPages - how many pages will be displayed in the vertical direction.
      • isLazyPageLayout

        public boolean isLazyPageLayout()
        Returns whether the preview lays out pages lazily. Note that total page counts in page numbers will not display correctly when this is enabled.
        Returns:
        whether the preview lays out pages lazily.
      • setLazyPageLayout

        public void setLazyPageLayout​(boolean lazy)
        Sets whether the preview lays out pages lazily. Note that total page counts in page numbers will not display correctly when this is enabled.
        Parameters:
        lazy - whether the preview lays out pages lazily.
      • startBackgroundLayout

        public void startBackgroundLayout​(java.lang.Runnable callback)
        Begins lazy loading in the background, invoking the callback runnable periodically as pages are laid out.

        NOTE: This API is experimental and subject to change.

        Parameters:
        callback - runnable that will be invoked periodically as pages are laid out.
      • invalidatePageDisplayBounds

        private void invalidatePageDisplayBounds()
      • paint

        private void paint​(org.eclipse.swt.widgets.Event event)
      • paintPage

        private void paintPage​(org.eclipse.swt.widgets.Event event,
                               PrintPiece page,
                               org.eclipse.swt.graphics.Point location)
      • disposeResources

        private void disposeResources​(org.eclipse.swt.graphics.Image printerImage,
                                      org.eclipse.swt.graphics.GC printerGC,
                                      org.eclipse.swt.graphics.Transform printerTransform,
                                      org.eclipse.swt.graphics.Image displayImage,
                                      PrintPiece page)
      • configureAntialiasing

        private void configureAntialiasing​(org.eclipse.swt.graphics.GC printerGC)
      • getPrinter

        private org.eclipse.swt.printing.Printer getPrinter()
      • getGC

        private org.eclipse.swt.graphics.GC getGC()
      • orientationRequiresRotate

        private boolean orientationRequiresRotate()
      • getPaperSize

        private org.eclipse.swt.graphics.Point getPaperSize()
      • fetchPages

        private void fetchPages​(int endIndex)
      • drawBackground

        private void drawBackground​(org.eclipse.swt.widgets.Event event)
      • getAbsoluteScale

        public float getAbsoluteScale()
        Calculates the absolute scale that the print preview is displaying at. If either of the fitHorizontal or fitVertical properties are true, this is the scale allows the page to fit within this control's current bounds. Otherwise the value of the scale property is returned.
        Returns:
        the absolute scale that the print preview is displaying at.
      • getMargins

        public org.eclipse.swt.graphics.Rectangle getMargins()
        Returns a Rectangle whose x, y, width, and height fields respectively indicate the margin at the left, top, right, and bottom edges of the control.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Returns:
        a Rectangle whose x, y, width, and height fields respectively indicate the margin at the left, top, right, and bottom edges of the control.
      • setMargins

        public void setMargins​(org.eclipse.swt.graphics.Rectangle margins)
        Sets the margins at each edge of the control to the argument.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Parameters:
        margins - a Rectangle whose x, y, width, and height fields respectively indicate the margin at the left, top, right, and bottom edges of the control.
      • getPageSpacing

        public org.eclipse.swt.graphics.Point getPageSpacing()
        Returns a Point whose x and y fields respectively indicate the horizontal and vertical spacing between pages on the control.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Returns:
        a Point whose x and y fields respectively indicate the horizontal and vertical spacing between pages on the control.
      • setPageSpacing

        public void setPageSpacing​(org.eclipse.swt.graphics.Point pageSpacing)
        Sets the horizontal and vertical spacing between pages to the argument.

        THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.

        Parameters:
        pageSpacing - a Point whose x and y fields respectively indicate the horizontal and vertical spacing between pages on the control.
      • getBoilerplateSize

        private org.eclipse.swt.graphics.Point getBoilerplateSize()
      • getAbsoluteScale

        private float getAbsoluteScale​(org.eclipse.swt.graphics.Point controlSize)
      • getPageDisplaySize

        private org.eclipse.swt.graphics.Point getPageDisplaySize()
      • getPageDisplayLocations

        private org.eclipse.swt.graphics.Point[] getPageDisplayLocations()
      • disposePages

        private void disposePages()
      • disposePrinter

        private void disposePrinter()
      • disposeGC

        private void disposeGC()
      • disposeResources

        private void disposeResources()
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(int wHint,
                                                          int hHint,
                                                          boolean changed)
        Overrides:
        computeSize in class org.eclipse.swt.widgets.Control
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(double scale)
        Returns the control size needed to display a full page at the given scale.
        Parameters:
        scale - the absolute scale. A scale of 1, for example, yields a "life size" preview.
        Returns:
        the control size needed to display a full page at the given scale.
      • addTrim

        private org.eclipse.swt.graphics.Point addTrim​(org.eclipse.swt.graphics.Point size)