774 775 DialogTypeSelection dlg = 776 (DialogTypeSelection)attributes.get(DialogTypeSelection.class); 777 778 // Check for native, note that default dialog is COMMON. 779 if (dlg == DialogTypeSelection.NATIVE) { 780 PrintService pservice = getPrintService(); 781 PageFormat pageFrmAttrib = attributeToPageFormat(pservice, 782 attributes); 783 PageFormat page = pageDialog(pageFrmAttrib); 784 785 // If user cancels the dialog, pageDialog() will return the original 786 // page object and as per spec, we should return null in that case. 787 if (page == pageFrmAttrib) { 788 return null; 789 } 790 updateAttributesWithPageFormat(pservice, page, attributes); 791 return page; 792 } 793 794 final GraphicsConfiguration gc = 795 GraphicsEnvironment.getLocalGraphicsEnvironment(). 796 getDefaultScreenDevice().getDefaultConfiguration(); 797 Rectangle bounds = gc.getBounds(); 798 int x = bounds.x+bounds.width/3; 799 int y = bounds.y+bounds.height/3; 800 801 PrintService service = java.security.AccessController.doPrivileged( 802 new java.security.PrivilegedAction<PrintService>() { 803 public PrintService run() { 804 PrintService service = getPrintService(); 805 if (service == null) { 806 ServiceDialog.showNoPrintService(gc); 807 return null; 808 } 809 return service; 810 } 811 }); 812 813 if (service == null) { 814 return null; 815 } 816 817 ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service, 818 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 819 attributes, (Frame)null); 820 pageDialog.show(); 821 822 if (pageDialog.getStatus() == ServiceDialog.APPROVE) { 823 PrintRequestAttributeSet newas = 824 pageDialog.getAttributes(); 825 Class<?> amCategory = SunAlternateMedia.class; 826 827 if (attributes.containsKey(amCategory) && 828 !newas.containsKey(amCategory)) { 829 attributes.remove(amCategory); 830 } 831 attributes.addAll(newas); 832 return attributeToPageFormat(service, attributes); 833 } else { 834 return null; 835 } 836 } 837 838 protected PageFormat getPageFormatFromAttributes() { 839 if (attributes == null || attributes.isEmpty()) { 876 877 } catch (PrinterException e) { 878 879 } 880 881 boolean ret = printDialog(); 882 this.attributes = attributes; 883 return ret; 884 885 } 886 887 /* A security check has already been performed in the 888 * java.awt.print.printerJob.getPrinterJob method. 889 * So by the time we get here, it is OK for the current thread 890 * to print either to a file (from a Dialog we control!) or 891 * to a chosen printer. 892 * 893 * We raise privilege when we put up the dialog, to avoid 894 * the "warning applet window" banner. 895 */ 896 final GraphicsConfiguration gc = 897 GraphicsEnvironment.getLocalGraphicsEnvironment(). 898 getDefaultScreenDevice().getDefaultConfiguration(); 899 900 PrintService service = java.security.AccessController.doPrivileged( 901 new java.security.PrivilegedAction<PrintService>() { 902 public PrintService run() { 903 PrintService service = getPrintService(); 904 if (service == null) { 905 ServiceDialog.showNoPrintService(gc); 906 return null; 907 } 908 return service; 909 } 910 }); 911 912 if (service == null) { 913 return false; 914 } 915 916 PrintService[] services; 917 StreamPrintServiceFactory[] spsFactories = null; 918 if (service instanceof StreamPrintService) { 923 } 924 } else { 925 services = java.security.AccessController.doPrivileged( 926 new java.security.PrivilegedAction<PrintService[]>() { 927 public PrintService[] run() { 928 PrintService[] services = PrinterJob.lookupPrintServices(); 929 return services; 930 } 931 }); 932 933 if ((services == null) || (services.length == 0)) { 934 /* 935 * No services but default PrintService exists? 936 * Create services using defaultService. 937 */ 938 services = new PrintService[1]; 939 services[0] = service; 940 } 941 } 942 943 Rectangle bounds = gc.getBounds(); 944 int x = bounds.x+bounds.width/3; 945 int y = bounds.y+bounds.height/3; 946 PrintService newService; 947 // temporarily add an attribute pointing back to this job. 948 PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this); 949 attributes.add(jobWrapper); 950 try { 951 newService = 952 ServiceUI.printDialog(gc, x, y, 953 services, service, 954 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 955 attributes); 956 } catch (IllegalArgumentException iae) { 957 newService = ServiceUI.printDialog(gc, x, y, 958 services, services[0], 959 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 960 attributes); 961 } 962 attributes.remove(PrinterJobWrapper.class); 963 964 if (newService == null) { 965 return false; | 774 775 DialogTypeSelection dlg = 776 (DialogTypeSelection)attributes.get(DialogTypeSelection.class); 777 778 // Check for native, note that default dialog is COMMON. 779 if (dlg == DialogTypeSelection.NATIVE) { 780 PrintService pservice = getPrintService(); 781 PageFormat pageFrmAttrib = attributeToPageFormat(pservice, 782 attributes); 783 PageFormat page = pageDialog(pageFrmAttrib); 784 785 // If user cancels the dialog, pageDialog() will return the original 786 // page object and as per spec, we should return null in that case. 787 if (page == pageFrmAttrib) { 788 return null; 789 } 790 updateAttributesWithPageFormat(pservice, page, attributes); 791 return page; 792 } 793 794 GraphicsConfiguration grCfg = null; 795 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); 796 if (w != null) { 797 grCfg = w.getGraphicsConfiguration(); 798 } else { 799 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment(). 800 getDefaultScreenDevice().getDefaultConfiguration(); 801 } 802 final GraphicsConfiguration gc = grCfg; 803 804 PrintService service = java.security.AccessController.doPrivileged( 805 new java.security.PrivilegedAction<PrintService>() { 806 public PrintService run() { 807 PrintService service = getPrintService(); 808 if (service == null) { 809 ServiceDialog.showNoPrintService(gc); 810 return null; 811 } 812 return service; 813 } 814 }); 815 816 if (service == null) { 817 return null; 818 } 819 820 // we position the dialog a little beyond the upper-left corner of the window 821 // which is consistent with the NATIVE page dialog 822 Rectangle gcBounds = gc.getBounds(); 823 int x = gcBounds.x+50; 824 int y = gcBounds.y+50; 825 ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service, 826 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 827 attributes, (Frame)null); 828 829 Rectangle dlgBounds = pageDialog.getBounds(); 830 831 // if portion of dialog is not within the gc boundary 832 if (!gcBounds.contains(dlgBounds)) { 833 834 // if dialog bounds exceed window bounds, positioning the dialog 835 // by moving it (bounds.x + bounds.width) - dlgBound.width 836 // If it results in dialog moving beyond the window bounds at top-left, 837 // then position it at window top-left 838 839 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) { 840 x = (gcBounds.x + gcBounds.width) - dlgBounds.width; 841 } else { 842 x = gcBounds.x; 843 } 844 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) { 845 y = (gcBounds.y + gcBounds.height) - dlgBounds.height; 846 } else { 847 y = gcBounds.y; 848 } 849 pageDialog.setBounds(x, y, dlgBounds.width, dlgBounds.height); 850 } 851 pageDialog.show(); 852 853 if (pageDialog.getStatus() == ServiceDialog.APPROVE) { 854 PrintRequestAttributeSet newas = 855 pageDialog.getAttributes(); 856 Class<?> amCategory = SunAlternateMedia.class; 857 858 if (attributes.containsKey(amCategory) && 859 !newas.containsKey(amCategory)) { 860 attributes.remove(amCategory); 861 } 862 attributes.addAll(newas); 863 return attributeToPageFormat(service, attributes); 864 } else { 865 return null; 866 } 867 } 868 869 protected PageFormat getPageFormatFromAttributes() { 870 if (attributes == null || attributes.isEmpty()) { 907 908 } catch (PrinterException e) { 909 910 } 911 912 boolean ret = printDialog(); 913 this.attributes = attributes; 914 return ret; 915 916 } 917 918 /* A security check has already been performed in the 919 * java.awt.print.printerJob.getPrinterJob method. 920 * So by the time we get here, it is OK for the current thread 921 * to print either to a file (from a Dialog we control!) or 922 * to a chosen printer. 923 * 924 * We raise privilege when we put up the dialog, to avoid 925 * the "warning applet window" banner. 926 */ 927 GraphicsConfiguration grCfg = null; 928 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); 929 if (w != null) { 930 grCfg = w.getGraphicsConfiguration(); 931 } else { 932 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment(). 933 getDefaultScreenDevice().getDefaultConfiguration(); 934 } 935 final GraphicsConfiguration gc = grCfg; 936 937 PrintService service = java.security.AccessController.doPrivileged( 938 new java.security.PrivilegedAction<PrintService>() { 939 public PrintService run() { 940 PrintService service = getPrintService(); 941 if (service == null) { 942 ServiceDialog.showNoPrintService(gc); 943 return null; 944 } 945 return service; 946 } 947 }); 948 949 if (service == null) { 950 return false; 951 } 952 953 PrintService[] services; 954 StreamPrintServiceFactory[] spsFactories = null; 955 if (service instanceof StreamPrintService) { 960 } 961 } else { 962 services = java.security.AccessController.doPrivileged( 963 new java.security.PrivilegedAction<PrintService[]>() { 964 public PrintService[] run() { 965 PrintService[] services = PrinterJob.lookupPrintServices(); 966 return services; 967 } 968 }); 969 970 if ((services == null) || (services.length == 0)) { 971 /* 972 * No services but default PrintService exists? 973 * Create services using defaultService. 974 */ 975 services = new PrintService[1]; 976 services[0] = service; 977 } 978 } 979 980 // we position the dialog a little beyond the upper-left corner of the window 981 // which is consistent with the NATIVE print dialog 982 int x = 50; 983 int y = 50; 984 PrintService newService; 985 // temporarily add an attribute pointing back to this job. 986 PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this); 987 attributes.add(jobWrapper); 988 try { 989 newService = 990 ServiceUI.printDialog(gc, x, y, 991 services, service, 992 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 993 attributes); 994 } catch (IllegalArgumentException iae) { 995 newService = ServiceUI.printDialog(gc, x, y, 996 services, services[0], 997 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 998 attributes); 999 } 1000 attributes.remove(PrinterJobWrapper.class); 1001 1002 if (newService == null) { 1003 return false; |