54 import javax.print.PrintService;
55 import javax.print.attribute.HashPrintRequestAttributeSet;
56 import javax.print.attribute.PrintRequestAttributeSet;
57 import javax.print.attribute.ResolutionSyntax;
58 import javax.print.attribute.Size2DSyntax;
59 import javax.print.attribute.standard.Chromaticity;
60 import javax.print.attribute.standard.Copies;
61 import javax.print.attribute.standard.Destination;
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,
970 */
971 graphicsToBeDrawn.append( (Graphics2D) graphics);
972
973 /* We now wait for the app's thread to finish drawing on
974 * the Graphics. This thread will sleep until the application
975 * release the graphics by placing it in the graphics drawn
976 * message queue. If the application signals that it is
977 * finished drawing the entire document then we'll get null
978 * returned when we try and pop a finished graphic.
979 */
980 if (graphicsDrawn.pop() != null) {
981 result = PAGE_EXISTS;
982 } else {
983 result = NO_SUCH_PAGE;
984 }
985
986 return result;
987 }
988
989 private void startPrinterJobThread() {
990 printerJobThread = new ManagedLocalsThread(this, "printerJobThread");
991 printerJobThread.start();
992 }
993
994
995 public void run() {
996
997 try {
998 attributes.remove(PageRanges.class);
999 printerJob.print(attributes);
1000 } catch (PrinterException e) {
1001 //REMIND: need to store this away and not rethrow it.
1002 }
1003
1004 /* Close the message queues so that nobody is stuck
1005 * waiting for one.
1006 */
1007 graphicsToBeDrawn.closeWhenEmpty();
1008 graphicsDrawn.close();
1009 }
1010
|
54 import javax.print.PrintService;
55 import javax.print.attribute.HashPrintRequestAttributeSet;
56 import javax.print.attribute.PrintRequestAttributeSet;
57 import javax.print.attribute.ResolutionSyntax;
58 import javax.print.attribute.Size2DSyntax;
59 import javax.print.attribute.standard.Chromaticity;
60 import javax.print.attribute.standard.Copies;
61 import javax.print.attribute.standard.Destination;
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.print.SunPageSelection;
75 import sun.print.SunMinMaxPage;
76
77 /**
78 * A class which initiates and executes a print job using
79 * the underlying PrinterJob graphics conversions.
80 *
81 * @see java.awt.Toolkit#getPrintJob
82 *
83 */
84 public class PrintJob2D extends PrintJob implements Printable, Runnable {
85
86 private static final MediaType SIZES[] = {
87 MediaType.ISO_4A0, MediaType.ISO_2A0, MediaType.ISO_A0,
88 MediaType.ISO_A1, MediaType.ISO_A2, MediaType.ISO_A3,
89 MediaType.ISO_A4, MediaType.ISO_A5, MediaType.ISO_A6,
90 MediaType.ISO_A7, MediaType.ISO_A8, MediaType.ISO_A9,
91 MediaType.ISO_A10, MediaType.ISO_B0, MediaType.ISO_B1,
92 MediaType.ISO_B2, MediaType.ISO_B3, MediaType.ISO_B4,
93 MediaType.ISO_B5, MediaType.ISO_B6, MediaType.ISO_B7,
969 */
970 graphicsToBeDrawn.append( (Graphics2D) graphics);
971
972 /* We now wait for the app's thread to finish drawing on
973 * the Graphics. This thread will sleep until the application
974 * release the graphics by placing it in the graphics drawn
975 * message queue. If the application signals that it is
976 * finished drawing the entire document then we'll get null
977 * returned when we try and pop a finished graphic.
978 */
979 if (graphicsDrawn.pop() != null) {
980 result = PAGE_EXISTS;
981 } else {
982 result = NO_SUCH_PAGE;
983 }
984
985 return result;
986 }
987
988 private void startPrinterJobThread() {
989 printerJobThread =
990 new Thread(null, this, "printerJobThread", 0, false);
991 printerJobThread.start();
992 }
993
994
995 public void run() {
996
997 try {
998 attributes.remove(PageRanges.class);
999 printerJob.print(attributes);
1000 } catch (PrinterException e) {
1001 //REMIND: need to store this away and not rethrow it.
1002 }
1003
1004 /* Close the message queues so that nobody is stuck
1005 * waiting for one.
1006 */
1007 graphicsToBeDrawn.closeWhenEmpty();
1008 graphicsDrawn.close();
1009 }
1010
|