13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.print;
27
28 import java.io.FilePermission;
29
30 import java.awt.Color;
31 import java.awt.Dialog;
32 import java.awt.Frame;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.GraphicsConfiguration;
36 import java.awt.GraphicsEnvironment;
37 import java.awt.HeadlessException;
38 import java.awt.KeyboardFocusManager;
39 import java.awt.Rectangle;
40 import java.awt.Shape;
41 import java.awt.geom.AffineTransform;
42 import java.awt.geom.Area;
43 import java.awt.geom.Point2D;
44 import java.awt.geom.Rectangle2D;
45 import java.awt.image.BufferedImage;
46 import java.awt.print.Book;
47 import java.awt.print.Pageable;
48 import java.awt.print.PageFormat;
49 import java.awt.print.Paper;
50 import java.awt.print.Printable;
51 import java.awt.print.PrinterAbortException;
52 import java.awt.print.PrinterException;
53 import java.awt.print.PrinterJob;
54 import java.awt.Window;
55 import java.io.File;
56 import java.io.IOException;
57 import java.util.ArrayList;
58 import java.util.Enumeration;
59 import java.util.Locale;
60 import sun.awt.image.ByteInterleavedRaster;
61
62 import javax.print.Doc;
63 import javax.print.DocFlavor;
64 import javax.print.DocPrintJob;
65 import javax.print.PrintException;
66 import javax.print.PrintService;
67 import javax.print.PrintServiceLookup;
68 import javax.print.ServiceUI;
69 import javax.print.StreamPrintService;
70 import javax.print.StreamPrintServiceFactory;
71 import javax.print.attribute.Attribute;
72 import javax.print.attribute.AttributeSet;
73 import javax.print.attribute.HashPrintRequestAttributeSet;
74 import javax.print.attribute.PrintRequestAttributeSet;
75 import javax.print.attribute.ResolutionSyntax;
76 import javax.print.attribute.Size2DSyntax;
77 import javax.print.attribute.standard.Chromaticity;
78 import javax.print.attribute.standard.Copies;
79 import javax.print.attribute.standard.Destination;
80 import javax.print.attribute.standard.DialogTypeSelection;
81 import javax.print.attribute.standard.Fidelity;
82 import javax.print.attribute.standard.JobName;
83 import javax.print.attribute.standard.JobSheets;
84 import javax.print.attribute.standard.Media;
85 import javax.print.attribute.standard.MediaPrintableArea;
86 import javax.print.attribute.standard.MediaSize;
87 import javax.print.attribute.standard.MediaSizeName;
88 import javax.print.attribute.standard.OrientationRequested;
89 import javax.print.attribute.standard.PageRanges;
90 import javax.print.attribute.standard.PrinterResolution;
91 import javax.print.attribute.standard.PrinterState;
92 import javax.print.attribute.standard.PrinterStateReason;
93 import javax.print.attribute.standard.PrinterStateReasons;
94 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
95 import javax.print.attribute.standard.RequestingUserName;
96 import javax.print.attribute.standard.SheetCollate;
97 import javax.print.attribute.standard.Sides;
98
99 import sun.print.PageableDoc;
100 import sun.print.ServiceDialog;
101 import sun.print.SunPrinterJobService;
102 import sun.print.SunPageSelection;
103
104 /**
105 * A class which rasterizes a printer job.
106 *
107 * @author Richard Blanchard
108 */
109 public abstract class RasterPrinterJob extends PrinterJob {
110
111 /* Class Constants */
112
113 /* Printer destination type. */
114 protected static final int PRINTER = 0;
115
116 /* File destination type. */
117 protected static final int FILE = 1;
118
119 /* Stream destination type. */
120 protected static final int STREAM = 2;
121
122 /**
123 * Pageable MAX pages
819 new java.security.PrivilegedAction<PrintService>() {
820 public PrintService run() {
821 PrintService service = getPrintService();
822 if (service == null) {
823 ServiceDialog.showNoPrintService(gc);
824 return null;
825 }
826 return service;
827 }
828 });
829
830 if (service == null) {
831 return null;
832 }
833
834 // we position the dialog a little beyond the upper-left corner of the window
835 // which is consistent with the NATIVE page dialog
836 Rectangle gcBounds = gc.getBounds();
837 int x = gcBounds.x+50;
838 int y = gcBounds.y+50;
839 ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service,
840 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
841 attributes, (Frame)null);
842 Rectangle dlgBounds = pageDialog.getBounds();
843
844 // if portion of dialog is not within the gc boundary
845 if (!gcBounds.contains(dlgBounds)) {
846 // check if dialog exceed window bounds at left or bottom
847 // Then position the dialog by moving it by the amount it exceeds
848 // the window bounds
849 // If it results in dialog moving beyond the window bounds at top/left
850 // then position it at window top/left
851 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) {
852 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) {
853 x = (gcBounds.x + gcBounds.width) - dlgBounds.width;
854 } else {
855 x = gcBounds.x;
856 }
857 }
858 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) {
859 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) {
860 y = (gcBounds.y + gcBounds.height) - dlgBounds.height;
861 } else {
927
928 boolean ret = printDialog();
929 this.attributes = attributes;
930 return ret;
931
932 }
933
934 /* A security check has already been performed in the
935 * java.awt.print.printerJob.getPrinterJob method.
936 * So by the time we get here, it is OK for the current thread
937 * to print either to a file (from a Dialog we control!) or
938 * to a chosen printer.
939 *
940 * We raise privilege when we put up the dialog, to avoid
941 * the "warning applet window" banner.
942 */
943 GraphicsConfiguration grCfg = null;
944 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
945 if (w != null) {
946 grCfg = w.getGraphicsConfiguration();
947 } else {
948 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
949 getDefaultScreenDevice().getDefaultConfiguration();
950 }
951 final GraphicsConfiguration gc = grCfg;
952
953 PrintService service = java.security.AccessController.doPrivileged(
954 new java.security.PrivilegedAction<PrintService>() {
955 public PrintService run() {
956 PrintService service = getPrintService();
957 if (service == null) {
958 ServiceDialog.showNoPrintService(gc);
959 return null;
960 }
961 return service;
962 }
963 });
964
965 if (service == null) {
966 return false;
997 // which is consistent with the NATIVE print dialog
998 int x = 50;
999 int y = 50;
1000 PrintService newService;
1001 // temporarily add an attribute pointing back to this job.
1002 PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this);
1003 attributes.add(jobWrapper);
1004 try {
1005 newService =
1006 ServiceUI.printDialog(gc, x, y,
1007 services, service,
1008 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
1009 attributes);
1010 } catch (IllegalArgumentException iae) {
1011 newService = ServiceUI.printDialog(gc, x, y,
1012 services, services[0],
1013 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
1014 attributes);
1015 }
1016 attributes.remove(PrinterJobWrapper.class);
1017
1018 if (newService == null) {
1019 return false;
1020 }
1021
1022 if (!service.equals(newService)) {
1023 try {
1024 setPrintService(newService);
1025 } catch (PrinterException e) {
1026 /*
1027 * The only time it would throw an exception is when
1028 * newService is no longer available but we should still
1029 * select this printer.
1030 */
1031 myService = newService;
1032 }
1033 }
1034 return true;
1035 }
1036
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.print;
27
28 import java.io.FilePermission;
29
30 import java.awt.Color;
31 import java.awt.Dialog;
32 import java.awt.Frame;
33 import java.awt.Graphics2D;
34 import java.awt.GraphicsConfiguration;
35 import java.awt.GraphicsEnvironment;
36 import java.awt.HeadlessException;
37 import java.awt.KeyboardFocusManager;
38 import java.awt.Rectangle;
39 import java.awt.Shape;
40 import java.awt.geom.AffineTransform;
41 import java.awt.geom.Point2D;
42 import java.awt.geom.Rectangle2D;
43 import java.awt.image.BufferedImage;
44 import java.awt.print.Book;
45 import java.awt.print.Pageable;
46 import java.awt.print.PageFormat;
47 import java.awt.print.Paper;
48 import java.awt.print.Printable;
49 import java.awt.print.PrinterAbortException;
50 import java.awt.print.PrinterException;
51 import java.awt.print.PrinterJob;
52 import java.awt.Window;
53 import java.io.File;
54 import java.io.IOException;
55 import java.util.ArrayList;
56 import java.util.Locale;
57 import sun.awt.image.ByteInterleavedRaster;
58
59 import javax.print.Doc;
60 import javax.print.DocFlavor;
61 import javax.print.DocPrintJob;
62 import javax.print.PrintException;
63 import javax.print.PrintService;
64 import javax.print.PrintServiceLookup;
65 import javax.print.ServiceUI;
66 import javax.print.StreamPrintService;
67 import javax.print.StreamPrintServiceFactory;
68 import javax.print.attribute.Attribute;
69 import javax.print.attribute.AttributeSet;
70 import javax.print.attribute.HashPrintRequestAttributeSet;
71 import javax.print.attribute.PrintRequestAttributeSet;
72 import javax.print.attribute.ResolutionSyntax;
73 import javax.print.attribute.Size2DSyntax;
74 import javax.print.attribute.standard.Copies;
75 import javax.print.attribute.standard.Destination;
76 import javax.print.attribute.standard.DialogTypeSelection;
77 import javax.print.attribute.standard.Fidelity;
78 import javax.print.attribute.standard.JobName;
79 import javax.print.attribute.standard.JobSheets;
80 import javax.print.attribute.standard.Media;
81 import javax.print.attribute.standard.MediaPrintableArea;
82 import javax.print.attribute.standard.MediaSize;
83 import javax.print.attribute.standard.MediaSizeName;
84 import javax.print.attribute.standard.OrientationRequested;
85 import javax.print.attribute.standard.PageRanges;
86 import javax.print.attribute.standard.PrinterResolution;
87 import javax.print.attribute.standard.PrinterState;
88 import javax.print.attribute.standard.PrinterStateReason;
89 import javax.print.attribute.standard.PrinterStateReasons;
90 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
91 import javax.print.attribute.standard.RequestingUserName;
92 import javax.print.attribute.standard.SheetCollate;
93 import javax.print.attribute.standard.Sides;
94
95 /**
96 * A class which rasterizes a printer job.
97 *
98 * @author Richard Blanchard
99 */
100 public abstract class RasterPrinterJob extends PrinterJob {
101
102 /* Class Constants */
103
104 /* Printer destination type. */
105 protected static final int PRINTER = 0;
106
107 /* File destination type. */
108 protected static final int FILE = 1;
109
110 /* Stream destination type. */
111 protected static final int STREAM = 2;
112
113 /**
114 * Pageable MAX pages
810 new java.security.PrivilegedAction<PrintService>() {
811 public PrintService run() {
812 PrintService service = getPrintService();
813 if (service == null) {
814 ServiceDialog.showNoPrintService(gc);
815 return null;
816 }
817 return service;
818 }
819 });
820
821 if (service == null) {
822 return null;
823 }
824
825 // we position the dialog a little beyond the upper-left corner of the window
826 // which is consistent with the NATIVE page dialog
827 Rectangle gcBounds = gc.getBounds();
828 int x = gcBounds.x+50;
829 int y = gcBounds.y+50;
830 ServiceDialog pageDialog;
831 if (w instanceof Frame) {
832 pageDialog = new ServiceDialog(gc, x, y, service,
833 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
834 attributes,(Frame)w);
835 } else {
836 pageDialog = new ServiceDialog(gc, x, y, service,
837 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
838 attributes, (Dialog)w);
839 }
840 Rectangle dlgBounds = pageDialog.getBounds();
841
842 // if portion of dialog is not within the gc boundary
843 if (!gcBounds.contains(dlgBounds)) {
844 // check if dialog exceed window bounds at left or bottom
845 // Then position the dialog by moving it by the amount it exceeds
846 // the window bounds
847 // If it results in dialog moving beyond the window bounds at top/left
848 // then position it at window top/left
849 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) {
850 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) {
851 x = (gcBounds.x + gcBounds.width) - dlgBounds.width;
852 } else {
853 x = gcBounds.x;
854 }
855 }
856 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) {
857 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) {
858 y = (gcBounds.y + gcBounds.height) - dlgBounds.height;
859 } else {
925
926 boolean ret = printDialog();
927 this.attributes = attributes;
928 return ret;
929
930 }
931
932 /* A security check has already been performed in the
933 * java.awt.print.printerJob.getPrinterJob method.
934 * So by the time we get here, it is OK for the current thread
935 * to print either to a file (from a Dialog we control!) or
936 * to a chosen printer.
937 *
938 * We raise privilege when we put up the dialog, to avoid
939 * the "warning applet window" banner.
940 */
941 GraphicsConfiguration grCfg = null;
942 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
943 if (w != null) {
944 grCfg = w.getGraphicsConfiguration();
945 /* Add DialogOwner attribute to set the owner of this print dialog
946 * only if it is not set already
947 * (it might be set in java.awt.PrintJob.printDialog)
948 */
949 if (attributes.get(DialogOwner.class) == null) {
950 attributes.add(w instanceof Frame ? new DialogOwner((Frame)w) :
951 new DialogOwner((Dialog)w));
952 }
953 } else {
954 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
955 getDefaultScreenDevice().getDefaultConfiguration();
956 }
957 final GraphicsConfiguration gc = grCfg;
958
959 PrintService service = java.security.AccessController.doPrivileged(
960 new java.security.PrivilegedAction<PrintService>() {
961 public PrintService run() {
962 PrintService service = getPrintService();
963 if (service == null) {
964 ServiceDialog.showNoPrintService(gc);
965 return null;
966 }
967 return service;
968 }
969 });
970
971 if (service == null) {
972 return false;
1003 // which is consistent with the NATIVE print dialog
1004 int x = 50;
1005 int y = 50;
1006 PrintService newService;
1007 // temporarily add an attribute pointing back to this job.
1008 PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this);
1009 attributes.add(jobWrapper);
1010 try {
1011 newService =
1012 ServiceUI.printDialog(gc, x, y,
1013 services, service,
1014 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
1015 attributes);
1016 } catch (IllegalArgumentException iae) {
1017 newService = ServiceUI.printDialog(gc, x, y,
1018 services, services[0],
1019 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
1020 attributes);
1021 }
1022 attributes.remove(PrinterJobWrapper.class);
1023 attributes.remove(DialogOwner.class);
1024
1025 if (newService == null) {
1026 return false;
1027 }
1028
1029 if (!service.equals(newService)) {
1030 try {
1031 setPrintService(newService);
1032 } catch (PrinterException e) {
1033 /*
1034 * The only time it would throw an exception is when
1035 * newService is no longer available but we should still
1036 * select this printer.
1037 */
1038 myService = newService;
1039 }
1040 }
1041 return true;
1042 }
1043
|