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; 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; | 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; 815 new java.security.PrivilegedAction<PrintService>() { 816 public PrintService run() { 817 PrintService service = getPrintService(); 818 if (service == null) { 819 ServiceDialog.showNoPrintService(gc); 820 return null; 821 } 822 return service; 823 } 824 }); 825 826 if (service == null) { 827 return null; 828 } 829 830 // we position the dialog a little beyond the upper-left corner of the window 831 // which is consistent with the NATIVE page dialog 832 Rectangle gcBounds = gc.getBounds(); 833 int x = gcBounds.x+50; 834 int y = gcBounds.y+50; 835 ServiceDialog pageDialog; 836 if (w instanceof Frame) { 837 pageDialog = new ServiceDialog(gc, x, y, service, 838 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 839 attributes, (Frame)w); 840 } else { 841 pageDialog = new ServiceDialog(gc, x, y, service, 842 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 843 attributes, (Dialog)w); 844 } 845 Rectangle dlgBounds = pageDialog.getBounds(); 846 847 // if portion of dialog is not within the gc boundary 848 if (!gcBounds.contains(dlgBounds)) { 849 // check if dialog exceed window bounds at left or bottom 850 // Then position the dialog by moving it by the amount it exceeds 851 // the window bounds 852 // If it results in dialog moving beyond the window bounds at top/left 853 // then position it at window top/left 854 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) { 855 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) { 856 x = (gcBounds.x + gcBounds.width) - dlgBounds.width; 857 } else { 858 x = gcBounds.x; 859 } 860 } 861 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) { 862 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) { 863 y = (gcBounds.y + gcBounds.height) - dlgBounds.height; 864 } else { 930 931 boolean ret = printDialog(); 932 this.attributes = attributes; 933 return ret; 934 935 } 936 937 /* A security check has already been performed in the 938 * java.awt.print.printerJob.getPrinterJob method. 939 * So by the time we get here, it is OK for the current thread 940 * to print either to a file (from a Dialog we control!) or 941 * to a chosen printer. 942 * 943 * We raise privilege when we put up the dialog, to avoid 944 * the "warning applet window" banner. 945 */ 946 GraphicsConfiguration grCfg = null; 947 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); 948 if (w != null) { 949 grCfg = w.getGraphicsConfiguration(); 950 /* Add DialogOwner attribute to set the owner of this print dialog 951 * only if it is not set already 952 * (it might be set in java.awt.PrintJob.printDialog) 953 */ 954 if (attributes.get(DialogOwner.class) == null) { 955 if (w instanceof Frame) { 956 attributes.add(new DialogOwner((Frame)w)); 957 } else if (w instanceof Dialog) { 958 attributes.add(new DialogOwner((Dialog)w)); 959 } 960 } 961 } else { 962 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment(). 963 getDefaultScreenDevice().getDefaultConfiguration(); 964 } 965 final GraphicsConfiguration gc = grCfg; 966 967 PrintService service = java.security.AccessController.doPrivileged( 968 new java.security.PrivilegedAction<PrintService>() { 969 public PrintService run() { 970 PrintService service = getPrintService(); 971 if (service == null) { 972 ServiceDialog.showNoPrintService(gc); 973 return null; 974 } 975 return service; 976 } 977 }); 978 979 if (service == null) { 980 return false; |