62 import javax.print.attribute.standard.DialogTypeSelection;
63 import javax.print.attribute.standard.JobName;
64 import javax.print.attribute.standard.MediaSize;
65 import javax.print.attribute.standard.PrintQuality;
66 import javax.print.attribute.standard.PrinterResolution;
67 import javax.print.attribute.standard.SheetCollate;
68 import javax.print.attribute.standard.Sides;
69 import javax.print.attribute.standard.Media;
70 import javax.print.attribute.standard.OrientationRequested;
71 import javax.print.attribute.standard.MediaSizeName;
72 import javax.print.attribute.standard.PageRanges;
73
74 import sun.misc.ManagedLocalsThread;
75 import sun.print.SunPageSelection;
76 import sun.print.SunMinMaxPage;
77
78 /**
79 * A class which initiates and executes a print job using
80 * the underlying PrinterJob graphics conversions.
81 *
82 * @see Toolkit#getPrintJob
83 *
84 */
85 public class PrintJob2D extends PrintJob implements Printable, Runnable {
86
87 private static final MediaType SIZES[] = {
88 MediaType.ISO_4A0, MediaType.ISO_2A0, MediaType.ISO_A0,
89 MediaType.ISO_A1, MediaType.ISO_A2, MediaType.ISO_A3,
90 MediaType.ISO_A4, MediaType.ISO_A5, MediaType.ISO_A6,
91 MediaType.ISO_A7, MediaType.ISO_A8, MediaType.ISO_A9,
92 MediaType.ISO_A10, MediaType.ISO_B0, MediaType.ISO_B1,
93 MediaType.ISO_B2, MediaType.ISO_B3, MediaType.ISO_B4,
94 MediaType.ISO_B5, MediaType.ISO_B6, MediaType.ISO_B7,
95 MediaType.ISO_B8, MediaType.ISO_B9, MediaType.ISO_B10,
96 MediaType.JIS_B0, MediaType.JIS_B1, MediaType.JIS_B2,
97 MediaType.JIS_B3, MediaType.JIS_B4, MediaType.JIS_B5,
98 MediaType.JIS_B6, MediaType.JIS_B7, MediaType.JIS_B8,
99 MediaType.JIS_B9, MediaType.JIS_B10, MediaType.ISO_C0,
100 MediaType.ISO_C1, MediaType.ISO_C2, MediaType.ISO_C3,
101 MediaType.ISO_C4, MediaType.ISO_C5, MediaType.ISO_C6,
102 MediaType.ISO_C7, MediaType.ISO_C8, MediaType.ISO_C9,
733 if (msn != null) {
734 attributes.add(msn);
735 }
736
737 PrintQualityType qType =
738 pageAttributes.getPrintQuality();
739 if (qType == PrintQualityType.DRAFT) {
740 attributes.add(PrintQuality.DRAFT);
741 } else if (qType == PrintQualityType.NORMAL) {
742 attributes.add(PrintQuality.NORMAL);
743 } else if (qType == PrintQualityType.HIGH) {
744 attributes.add(PrintQuality.HIGH);
745 }
746 }
747
748 /**
749 * Gets a Graphics object that will draw to the next page.
750 * The page is sent to the printer when the graphics
751 * object is disposed. This graphics object will also implement
752 * the PrintGraphics interface.
753 * @see PrintGraphics
754 */
755 public Graphics getGraphics() {
756
757 Graphics printGraphics = null;
758
759 synchronized (this) {
760 ++pageIndex;
761
762 // Thread should not be created after end has been called.
763 // One way to detect this is if any of the graphics queue
764 // has been closed.
765 if (pageIndex == 0 && !graphicsToBeDrawn.isClosed()) {
766
767 /* We start a thread on which the PrinterJob will run.
768 * The PrinterJob will ask for pages on that thread
769 * and will use a message queue to fulfill the application's
770 * requests for a Graphics on the application's
771 * thread.
772 */
773
920 /**
921 * Ends this print job once it is no longer referenced.
922 * @see #end
923 */
924 public void finalize() {
925 end();
926 }
927
928 /**
929 * Prints the page at the specified index into the specified
930 * {@link Graphics} context in the specified
931 * format. A <code>PrinterJob</code> calls the
932 * <code>Printable</code> interface to request that a page be
933 * rendered into the context specified by
934 * <code>graphics</code>. The format of the page to be drawn is
935 * specified by <code>pageFormat</code>. The zero based index
936 * of the requested page is specified by <code>pageIndex</code>.
937 * If the requested page does not exist then this method returns
938 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
939 * The <code>Graphics</code> class or subclass implements the
940 * {@link PrinterGraphics} interface to provide additional
941 * information. If the <code>Printable</code> object
942 * aborts the print job then it throws a {@link PrinterException}.
943 * @param graphics the context into which the page is drawn
944 * @param pageFormat the size and orientation of the page being drawn
945 * @param pageIndex the zero based index of the page to be drawn
946 * @return PAGE_EXISTS if the page is rendered successfully
947 * or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
948 * non-existent page.
949 * @exception java.awt.print.PrinterException
950 * thrown when the print job is terminated.
951 */
952 public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
953 throws PrinterException {
954
955 int result;
956
957 /* This method will be called by the PrinterJob on a thread other
958 * that the application's thread. We hold on to the graphics
959 * until we can rendevous with the application's thread and
960 * hand over the graphics. The application then does all the
|
62 import javax.print.attribute.standard.DialogTypeSelection;
63 import javax.print.attribute.standard.JobName;
64 import javax.print.attribute.standard.MediaSize;
65 import javax.print.attribute.standard.PrintQuality;
66 import javax.print.attribute.standard.PrinterResolution;
67 import javax.print.attribute.standard.SheetCollate;
68 import javax.print.attribute.standard.Sides;
69 import javax.print.attribute.standard.Media;
70 import javax.print.attribute.standard.OrientationRequested;
71 import javax.print.attribute.standard.MediaSizeName;
72 import javax.print.attribute.standard.PageRanges;
73
74 import sun.misc.ManagedLocalsThread;
75 import sun.print.SunPageSelection;
76 import sun.print.SunMinMaxPage;
77
78 /**
79 * A class which initiates and executes a print job using
80 * the underlying PrinterJob graphics conversions.
81 *
82 * @see java.awt.Toolkit#getPrintJob
83 *
84 */
85 public class PrintJob2D extends PrintJob implements Printable, Runnable {
86
87 private static final MediaType SIZES[] = {
88 MediaType.ISO_4A0, MediaType.ISO_2A0, MediaType.ISO_A0,
89 MediaType.ISO_A1, MediaType.ISO_A2, MediaType.ISO_A3,
90 MediaType.ISO_A4, MediaType.ISO_A5, MediaType.ISO_A6,
91 MediaType.ISO_A7, MediaType.ISO_A8, MediaType.ISO_A9,
92 MediaType.ISO_A10, MediaType.ISO_B0, MediaType.ISO_B1,
93 MediaType.ISO_B2, MediaType.ISO_B3, MediaType.ISO_B4,
94 MediaType.ISO_B5, MediaType.ISO_B6, MediaType.ISO_B7,
95 MediaType.ISO_B8, MediaType.ISO_B9, MediaType.ISO_B10,
96 MediaType.JIS_B0, MediaType.JIS_B1, MediaType.JIS_B2,
97 MediaType.JIS_B3, MediaType.JIS_B4, MediaType.JIS_B5,
98 MediaType.JIS_B6, MediaType.JIS_B7, MediaType.JIS_B8,
99 MediaType.JIS_B9, MediaType.JIS_B10, MediaType.ISO_C0,
100 MediaType.ISO_C1, MediaType.ISO_C2, MediaType.ISO_C3,
101 MediaType.ISO_C4, MediaType.ISO_C5, MediaType.ISO_C6,
102 MediaType.ISO_C7, MediaType.ISO_C8, MediaType.ISO_C9,
733 if (msn != null) {
734 attributes.add(msn);
735 }
736
737 PrintQualityType qType =
738 pageAttributes.getPrintQuality();
739 if (qType == PrintQualityType.DRAFT) {
740 attributes.add(PrintQuality.DRAFT);
741 } else if (qType == PrintQualityType.NORMAL) {
742 attributes.add(PrintQuality.NORMAL);
743 } else if (qType == PrintQualityType.HIGH) {
744 attributes.add(PrintQuality.HIGH);
745 }
746 }
747
748 /**
749 * Gets a Graphics object that will draw to the next page.
750 * The page is sent to the printer when the graphics
751 * object is disposed. This graphics object will also implement
752 * the PrintGraphics interface.
753 * @see java.awt.PrintGraphics
754 */
755 public Graphics getGraphics() {
756
757 Graphics printGraphics = null;
758
759 synchronized (this) {
760 ++pageIndex;
761
762 // Thread should not be created after end has been called.
763 // One way to detect this is if any of the graphics queue
764 // has been closed.
765 if (pageIndex == 0 && !graphicsToBeDrawn.isClosed()) {
766
767 /* We start a thread on which the PrinterJob will run.
768 * The PrinterJob will ask for pages on that thread
769 * and will use a message queue to fulfill the application's
770 * requests for a Graphics on the application's
771 * thread.
772 */
773
920 /**
921 * Ends this print job once it is no longer referenced.
922 * @see #end
923 */
924 public void finalize() {
925 end();
926 }
927
928 /**
929 * Prints the page at the specified index into the specified
930 * {@link Graphics} context in the specified
931 * format. A <code>PrinterJob</code> calls the
932 * <code>Printable</code> interface to request that a page be
933 * rendered into the context specified by
934 * <code>graphics</code>. The format of the page to be drawn is
935 * specified by <code>pageFormat</code>. The zero based index
936 * of the requested page is specified by <code>pageIndex</code>.
937 * If the requested page does not exist then this method returns
938 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
939 * The <code>Graphics</code> class or subclass implements the
940 * {@link java.awt.PrintGraphics} interface to provide additional
941 * information. If the <code>Printable</code> object
942 * aborts the print job then it throws a {@link PrinterException}.
943 * @param graphics the context into which the page is drawn
944 * @param pageFormat the size and orientation of the page being drawn
945 * @param pageIndex the zero based index of the page to be drawn
946 * @return PAGE_EXISTS if the page is rendered successfully
947 * or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
948 * non-existent page.
949 * @exception java.awt.print.PrinterException
950 * thrown when the print job is terminated.
951 */
952 public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
953 throws PrinterException {
954
955 int result;
956
957 /* This method will be called by the PrinterJob on a thread other
958 * that the application's thread. We hold on to the graphics
959 * until we can rendevous with the application's thread and
960 * hand over the graphics. The application then does all the
|