net.sf.paperclips.ui
Class PrintPreview

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.eclipse.swt.widgets.Canvas
                      extended by net.sf.paperclips.ui.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)

Author:
Matthew Hall

Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
PrintPreview(org.eclipse.swt.widgets.Composite parent, int style)
          Constructs a PrintPreview control.
 
Method Summary
 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)
           
 float getAbsoluteScale()
          Calculates the absolute scale that the print preview is displaying at.
 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.
 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.
 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.
 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.
 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.
 
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, scroll, setCaret, setFont
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

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.

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.

computeSize

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

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.