
org.eclipse.swt.printing.Printer Maven / Gradle / Ivy
Show all versions of draw2d-rwt Show documentation
/*******************************************************************************
* 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.draw2d.rap.swt.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.*;
/**
* Instances of this class are used to print to a printer.
* Applications create a GC on a printer using new GC(printer)
* and then draw on the printer GC using the usual graphics calls.
*
* A Printer
object may be constructed by providing
* a PrinterData
object which identifies the printer.
* A PrintDialog
presents a print dialog to the user
* and returns an initialized instance of PrinterData
.
* Alternatively, calling new Printer()
will construct a
* printer object for the user's default printer.
*
* Application code must explicitly invoke the Printer.dispose()
* method to release the operating system resources managed by each instance
* when those instances are no longer required.
*
*
* @see PrinterData
* @see PrintDialog
* @see Printing snippets
* @see Sample code and further information
*/
public final class Printer extends Device {
PrinterData data;
/**
* Returns an array of PrinterData
objects
* representing all available printers.
*
* @return the list of available printers
*/
public static PrinterData[] getPrinterList() {
PrinterData printerList[] = new PrinterData[0];
return printerList;
}
/**
* Returns a PrinterData
object representing
* the default printer or null
if there is no
* printer available on the System.
*
* @return the default printer data or null
*
* @since 2.1
*/
public static PrinterData getDefaultPrinterData() {
return null;
}
static DeviceData checkNull (PrinterData data) {
if (data == null) data = new PrinterData();
if (data.driver == null || data.name == null) {
PrinterData defaultPrinter = getDefaultPrinterData();
if (defaultPrinter == null) SWT.error(SWT.ERROR_NO_HANDLES);
data.driver = defaultPrinter.driver;
data.name = defaultPrinter.name;
}
return data;
}
/**
* Constructs a new printer representing the default printer.
*
* You must dispose the printer when it is no longer required.
*
*
* @exception SWTError
* - ERROR_NO_HANDLES - if there are no valid printers
*
*
* @see Device#dispose
*/
public Printer() {
this(null);
}
/**
* Constructs a new printer given a PrinterData
* object representing the desired printer.
*
* You must dispose the printer when it is no longer required.
*
*
* @param data the printer data for the specified printer
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the specified printer data does not represent a valid printer
*
* @exception SWTError
* - ERROR_NO_HANDLES - if there are no valid printers
*
*
* @see Device#dispose
*/
public Printer(PrinterData data) {
// super(checkNull(data));
SWT.error(SWT.ERROR_NO_HANDLES);
}
///**
// * Invokes platform specific functionality to allocate a new GC handle.
// *
// * IMPORTANT: This method is not part of the public
// * API for Printer
. It is marked public only so that it
// * can be shared within the packages provided by SWT. It is not
// * available on all platforms, and should never be called from
// * application code.
// *
// *
// * @param data the platform specific GC data
// * @return the platform specific GC handle
// */
//public int internal_new_GC(GCData data) {
// return 0;
//}
///**
// * Invokes platform specific functionality to dispose a GC handle.
// *
// * IMPORTANT: This method is not part of the public
// * API for Printer
. It is marked public only so that it
// * can be shared within the packages provided by SWT. It is not
// * available on all platforms, and should never be called from
// * application code.
// *
// *
// * @param hDC the platform specific GC handle
// * @param data the platform specific GC data
// */
//public void internal_dispose_GC(int xGC, GCData data) {
//}
/**
* Starts a print job and returns true if the job started successfully
* and false otherwise.
*
* This must be the first method called to initiate a print job,
* followed by any number of startPage/endPage calls, followed by
* endJob. Calling startPage, endPage, or endJob before startJob
* will result in undefined behavior.
*
*
* @param jobName the name of the print job to start
* @return true if the job started successfully and false otherwise.
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #startPage
* @see #endPage
* @see #endJob
*/
public boolean startJob(String jobName) {
checkDevice();
return true;
}
/**
* Ends the current print job.
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #startJob
* @see #startPage
* @see #endPage
*/
public void endJob() {
checkDevice();
}
/**
* Cancels a print job in progress.
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*/
public void cancelJob() {
checkDevice();
}
/**
* Starts a page and returns true if the page started successfully
* and false otherwise.
*
* After calling startJob, this method may be called any number of times
* along with a matching endPage.
*
*
* @return true if the page started successfully and false otherwise.
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #endPage
* @see #startJob
* @see #endJob
*/
public boolean startPage() {
checkDevice();
return true;
}
/**
* Ends the current page.
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #startPage
* @see #startJob
* @see #endJob
*/
public void endPage() {
checkDevice();
}
/**
* Returns a point whose x coordinate is the horizontal
* dots per inch of the printer, and whose y coordinate
* is the vertical dots per inch of the printer.
*
* @return the horizontal and vertical DPI
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*/
public Point getDPI() {
checkDevice();
return new Point(0, 0);
}
/**
* Returns a rectangle describing the receiver's size and location.
*
* For a printer, this is the size of the physical page, in pixels.
*
*
* @return the bounding rectangle
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #getClientArea
* @see #computeTrim
*/
public Rectangle getBounds() {
checkDevice();
return new Rectangle(0, 0, 0, 0);
}
/**
* Returns a rectangle which describes the area of the
* receiver which is capable of displaying data.
*
* For a printer, this is the size of the printable area
* of the page, in pixels.
*
*
* @return the client area
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #getBounds
* @see #computeTrim
*/
public Rectangle getClientArea() {
checkDevice();
return new Rectangle(0, 0, 0, 0);
}
/**
* Given a client area (as described by the arguments),
* returns a rectangle, relative to the client area's coordinates,
* that is the client area expanded by the printer's trim (or minimum margins).
*
* Most printers have a minimum margin on each edge of the paper where the
* printer device is unable to print. This margin is known as the "trim."
* This method can be used to calculate the printer's minimum margins
* by passing in a client area of 0, 0, 0, 0 and then using the resulting
* x and y coordinates (which will be <= 0) to determine the minimum margins
* for the top and left edges of the paper, and the resulting width and height
* (offset by the resulting x and y) to determine the minimum margins for the
* bottom and right edges of the paper, as follows:
*
*
* - The left trim width is -x pixels
* - The top trim height is -y pixels
* - The right trim width is (x + width) pixels
* - The bottom trim height is (y + height) pixels
*
*
* @param x the x coordinate of the client area
* @param y the y coordinate of the client area
* @param width the width of the client area
* @param height the height of the client area
* @return a rectangle, relative to the client area's coordinates, that is
* the client area expanded by the printer's trim (or minimum margins)
*
* @exception SWTException
* - ERROR_DEVICE_DISPOSED - if the receiver has been disposed
*
*
* @see #getBounds
* @see #getClientArea
*/
public Rectangle computeTrim(int x, int y, int width, int height) {
return new Rectangle(0,0,0,0);
}
/**
* Returns a PrinterData
object representing the
* target printer for this print job.
*
* @return a PrinterData object describing the receiver
*/
public PrinterData getPrinterData() {
return data;
}
}