/******************************************************************************* * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.printing; import org.eclipse.swt.*; import org.eclipse.swt.printing.PrinterData; import org.eclipse.swt.widgets.*; /** * Instances of this class allow the user to select * a printer and various print-related parameters * prior to starting a print job. *

* IMPORTANT: This class is intended to be subclassed only * within the SWT implementation. *

* * @see Printing snippets * @see SWT Example: ControlExample, Dialog tab * @see Sample code and further information */ public class PrintDialog extends Dialog { PrinterData printerData; int scope = PrinterData.ALL_PAGES; int startPage = -1, endPage = -1; boolean printToFile = false; /** * Constructs a new instance of this class given only its parent. * * @param parent a composite control which will be the parent of the new instance (cannot be null) * * @exception IllegalArgumentException * @exception SWTException * * @see SWT * @see Widget#checkSubclass * @see Widget#getStyle */ public PrintDialog (Shell parent) { this (parent, SWT.PRIMARY_MODAL); } /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. *

* The style value is either one of the style constants defined in * class SWT which is applicable to instances of this * class, or must be built by bitwise OR'ing together * (that is, using the int "|" operator) two or more * of those SWT style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. *

* * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException * @exception SWTException * * @see SWT * @see Widget#checkSubclass * @see Widget#getStyle */ public PrintDialog (Shell parent, int style) { super (parent, style); checkSubclass (); } /** * Sets the printer data that will be used when the dialog * is opened. * * @param data the data that will be used when the dialog is opened * * @since 3.4 */ public void setPrinterData(PrinterData data) { this.printerData = data; } /** * Returns the printer data that will be used when the dialog * is opened. * * @return the data that will be used when the dialog is opened * * @since 3.4 */ public PrinterData getPrinterData() { return printerData; } /** * Makes the receiver visible and brings it to the front * of the display. * * @return a printer data object describing the desired print job parameters * * @exception SWTException */ public PrinterData open() { /* Return the first printer in the list */ PrinterData[] printers = Printer.getPrinterList(); if (printers.length > 0) return printers[0]; return null; } /** * Returns the print job scope that the user selected * before pressing OK in the dialog. This will be one * of the following values: *
*
PrinterData.ALL_PAGES
*
Print all pages in the current document
*
PrinterData.PAGE_RANGE
*
Print the range of pages specified by startPage and endPage
*
PrinterData.SELECTION
*
Print the current selection
*
* * @return the scope setting that the user selected */ public int getScope() { return scope; } /** * Sets the scope of the print job. The user will see this * setting when the dialog is opened. This can have one of * the following values: *
*
PrinterData.ALL_PAGES
*
Print all pages in the current document
*
PrinterData.PAGE_RANGE
*
Print the range of pages specified by startPage and endPage
*
PrinterData.SELECTION
*
Print the current selection
*
* * @param scope the scope setting when the dialog is opened */ public void setScope(int scope) { this.scope = scope; } /** * Returns the start page setting that the user selected * before pressing OK in the dialog. *

* This value can be from 1 to the maximum number of pages for the platform. * Note that it is only valid if the scope is PrinterData.PAGE_RANGE. *

* * @return the start page setting that the user selected */ public int getStartPage() { return startPage; } /** * Sets the start page that the user will see when the dialog * is opened. *

* This value can be from 1 to the maximum number of pages for the platform. * Note that it is only valid if the scope is PrinterData.PAGE_RANGE. *

* * @param startPage the startPage setting when the dialog is opened */ public void setStartPage(int startPage) { this.startPage = startPage; } /** * Returns the end page setting that the user selected * before pressing OK in the dialog. *

* This value can be from 1 to the maximum number of pages for the platform. * Note that it is only valid if the scope is PrinterData.PAGE_RANGE. *

* * @return the end page setting that the user selected */ public int getEndPage() { return endPage; } /** * Sets the end page that the user will see when the dialog * is opened. *

* This value can be from 1 to the maximum number of pages for the platform. * Note that it is only valid if the scope is PrinterData.PAGE_RANGE. *

* * @param endPage the end page setting when the dialog is opened */ public void setEndPage(int endPage) { this.endPage = endPage; } /** * Returns the 'Print to file' setting that the user selected * before pressing OK in the dialog. * * @return the 'Print to file' setting that the user selected */ public boolean getPrintToFile() { return printToFile; } /** * Sets the 'Print to file' setting that the user will see * when the dialog is opened. * * @param printToFile the 'Print to file' setting when the dialog is opened */ public void setPrintToFile(boolean printToFile) { this.printToFile = printToFile; } protected void checkSubclass() { } }