< prev index next >

src/java.desktop/share/classes/sun/print/RasterPrinterJob.java

Print this page




 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) {


 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;




 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         GraphicsConfiguration grCfg = null;
 897         Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
 898         if (w != null) {
 899             grCfg = w.getGraphicsConfiguration();
 900         } else {
 901             grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
 902                         getDefaultScreenDevice().getDefaultConfiguration();      
 903         }
 904         final GraphicsConfiguration gc = grCfg;        
 905 
 906         PrintService service = java.security.AccessController.doPrivileged(
 907                                new java.security.PrivilegedAction<PrintService>() {
 908                 public PrintService run() {
 909                     PrintService service = getPrintService();
 910                     if (service == null) {
 911                         ServiceDialog.showNoPrintService(gc);
 912                         return null;
 913                     }
 914                     return service;
 915                 }
 916             });
 917 
 918         if (service == null) {
 919             return false;
 920         }
 921 
 922         PrintService[] services;
 923         StreamPrintServiceFactory[] spsFactories = null;
 924         if (service instanceof StreamPrintService) {


 930         } else {
 931             services = java.security.AccessController.doPrivileged(
 932                        new java.security.PrivilegedAction<PrintService[]>() {
 933                 public PrintService[] run() {
 934                     PrintService[] services = PrinterJob.lookupPrintServices();
 935                     return services;
 936                 }
 937             });
 938 
 939             if ((services == null) || (services.length == 0)) {
 940                 /*
 941                  * No services but default PrintService exists?
 942                  * Create services using defaultService.
 943                  */
 944                 services = new PrintService[1];
 945                 services[0] = service;
 946             }
 947         }
 948 
 949         Rectangle bounds = gc.getBounds();
 950         // we do not add bounds.x,bounds.y as ServiceUI.printDialog adds it
 951         int x = bounds.width/3;
 952         int y = bounds.height/3;
 953         PrintService newService;
 954         // temporarily add an attribute pointing back to this job.
 955         PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this);
 956         attributes.add(jobWrapper);
 957         try {
 958             newService =
 959             ServiceUI.printDialog(gc, x, y,
 960                                   services, service,
 961                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
 962                                   attributes);
 963         } catch (IllegalArgumentException iae) {
 964             newService = ServiceUI.printDialog(gc, x, y,
 965                                   services, services[0],
 966                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
 967                                   attributes);
 968         }
 969         attributes.remove(PrinterJobWrapper.class);
 970 
 971         if (newService == null) {
 972             return false;


< prev index next >