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 // check if dialog exceed window bounds at left or bottom 835 // Then position the dialog by moving it by the amount it exceeds 836 // the window bounds 837 // If it results in dialog moving beyond the window bounds at top/left 838 // then position it at window top/left 839 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) { 840 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) { 841 x = (gcBounds.x + gcBounds.width) - dlgBounds.width; 842 } else { 843 x = gcBounds.x; 844 } 845 } 846 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) { 847 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) { 848 y = (gcBounds.y + gcBounds.height) - dlgBounds.height; 849 } else { 850 y = gcBounds.y; 851 } 852 } 853 pageDialog.setBounds(x, y, dlgBounds.width, dlgBounds.height); 854 } 855 pageDialog.show(); 856 857 if (pageDialog.getStatus() == ServiceDialog.APPROVE) { 858 PrintRequestAttributeSet newas = 859 pageDialog.getAttributes(); 860 Class<?> amCategory = SunAlternateMedia.class; 861 862 if (attributes.containsKey(amCategory) && 863 !newas.containsKey(amCategory)) { 864 attributes.remove(amCategory); 865 } 866 attributes.addAll(newas); 867 return attributeToPageFormat(service, attributes); 868 } else { 869 return null; 870 } 871 } 872 873 protected PageFormat getPageFormatFromAttributes() { 874 if (attributes == null || attributes.isEmpty()) { 911 912 } catch (PrinterException e) { 913 914 } 915 916 boolean ret = printDialog(); 917 this.attributes = attributes; 918 return ret; 919 920 } 921 922 /* A security check has already been performed in the 923 * java.awt.print.printerJob.getPrinterJob method. 924 * So by the time we get here, it is OK for the current thread 925 * to print either to a file (from a Dialog we control!) or 926 * to a chosen printer. 927 * 928 * We raise privilege when we put up the dialog, to avoid 929 * the "warning applet window" banner. 930 */ 931 GraphicsConfiguration grCfg = null; 932 Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); 933 if (w != null) { 934 grCfg = w.getGraphicsConfiguration(); 935 } else { 936 grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment(). 937 getDefaultScreenDevice().getDefaultConfiguration(); 938 } 939 final GraphicsConfiguration gc = grCfg; 940 941 PrintService service = java.security.AccessController.doPrivileged( 942 new java.security.PrivilegedAction<PrintService>() { 943 public PrintService run() { 944 PrintService service = getPrintService(); 945 if (service == null) { 946 ServiceDialog.showNoPrintService(gc); 947 return null; 948 } 949 return service; 950 } 951 }); 952 953 if (service == null) { 954 return false; 955 } 956 957 PrintService[] services; 958 StreamPrintServiceFactory[] spsFactories = null; 959 if (service instanceof StreamPrintService) { 964 } 965 } else { 966 services = java.security.AccessController.doPrivileged( 967 new java.security.PrivilegedAction<PrintService[]>() { 968 public PrintService[] run() { 969 PrintService[] services = PrinterJob.lookupPrintServices(); 970 return services; 971 } 972 }); 973 974 if ((services == null) || (services.length == 0)) { 975 /* 976 * No services but default PrintService exists? 977 * Create services using defaultService. 978 */ 979 services = new PrintService[1]; 980 services[0] = service; 981 } 982 } 983 984 // we position the dialog a little beyond the upper-left corner of the window 985 // which is consistent with the NATIVE print dialog 986 int x = 50; 987 int y = 50; 988 PrintService newService; 989 // temporarily add an attribute pointing back to this job. 990 PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this); 991 attributes.add(jobWrapper); 992 try { 993 newService = 994 ServiceUI.printDialog(gc, x, y, 995 services, service, 996 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 997 attributes); 998 } catch (IllegalArgumentException iae) { 999 newService = ServiceUI.printDialog(gc, x, y, 1000 services, services[0], 1001 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 1002 attributes); 1003 } 1004 attributes.remove(PrinterJobWrapper.class); 1005 1006 if (newService == null) { 1007 return false; |