< prev index next >

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

Print this page




 768 
 769     /**
 770      * return a PageFormat corresponding to the updated attributes,
 771      * or null if the user cancelled the dialog.
 772      */
 773     @SuppressWarnings("deprecation")
 774     public PageFormat pageDialog(final PrintRequestAttributeSet attributes)
 775         throws HeadlessException {
 776         if (GraphicsEnvironment.isHeadless()) {
 777             throw new HeadlessException();
 778         }
 779 
 780         DialogTypeSelection dlg =
 781             (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
 782 
 783         // Check for native, note that default dialog is COMMON.
 784         if (dlg == DialogTypeSelection.NATIVE) {
 785             PrintService pservice = getPrintService();
 786             PageFormat pageFrmAttrib = attributeToPageFormat(pservice,
 787                                                              attributes);

 788             PageFormat page = pageDialog(pageFrmAttrib);

 789 
 790             // If user cancels the dialog, pageDialog() will return the original
 791             // page object and as per spec, we should return null in that case.
 792             if (page == pageFrmAttrib) {
 793                 return null;
 794             }
 795             updateAttributesWithPageFormat(pservice, page, attributes);
 796             return page;
 797         }
 798 
 799         GraphicsConfiguration grCfg = null;
 800         Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
 801         if (w != null) {
 802             grCfg = w.getGraphicsConfiguration();
 803         } else {
 804             grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
 805                         getDefaultScreenDevice().getDefaultConfiguration();
 806         }
 807         final GraphicsConfiguration gc = grCfg;
 808 


 906     public boolean printDialog(final PrintRequestAttributeSet attributes)
 907         throws HeadlessException {
 908         if (GraphicsEnvironment.isHeadless()) {
 909             throw new HeadlessException();
 910         }
 911 
 912         DialogTypeSelection dlg =
 913             (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
 914 
 915         // Check for native, note that default dialog is COMMON.
 916         if (dlg == DialogTypeSelection.NATIVE) {
 917             this.attributes = attributes;
 918             try {
 919                 debug_println("calling setAttributes in printDialog");
 920                 setAttributes(attributes);
 921 
 922             } catch (PrinterException e) {
 923 
 924             }
 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


2521      * This is a utility method used by subclasses to remove them so we
2522      * don't have to worry about platform or font specific handling of them.
2523      */
2524     protected String removeControlChars(String s) {
2525         char[] in_chars = s.toCharArray();
2526         int len = in_chars.length;
2527         char[] out_chars = new char[len];
2528         int pos = 0;
2529 
2530         for (int i = 0; i < len; i++) {
2531             char c = in_chars[i];
2532             if (c > '\r' || c < '\t' || c == '\u000b' || c == '\u000c')  {
2533                out_chars[pos++] = c;
2534             }
2535         }
2536         if (pos == len) {
2537             return s; // no need to make a new String.
2538         } else {
2539             return new String(out_chars, 0, pos);
2540         }



















2541     }
2542 }


 768 
 769     /**
 770      * return a PageFormat corresponding to the updated attributes,
 771      * or null if the user cancelled the dialog.
 772      */
 773     @SuppressWarnings("deprecation")
 774     public PageFormat pageDialog(final PrintRequestAttributeSet attributes)
 775         throws HeadlessException {
 776         if (GraphicsEnvironment.isHeadless()) {
 777             throw new HeadlessException();
 778         }
 779 
 780         DialogTypeSelection dlg =
 781             (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
 782 
 783         // Check for native, note that default dialog is COMMON.
 784         if (dlg == DialogTypeSelection.NATIVE) {
 785             PrintService pservice = getPrintService();
 786             PageFormat pageFrmAttrib = attributeToPageFormat(pservice,
 787                                                              attributes);
 788             setParentWindowID(attributes);
 789             PageFormat page = pageDialog(pageFrmAttrib);
 790             clearParentWindowID();
 791 
 792             // If user cancels the dialog, pageDialog() will return the original
 793             // page object and as per spec, we should return null in that case.
 794             if (page == pageFrmAttrib) {
 795                 return null;
 796             }
 797             updateAttributesWithPageFormat(pservice, page, attributes);
 798             return page;
 799         }
 800 
 801         GraphicsConfiguration grCfg = null;
 802         Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
 803         if (w != null) {
 804             grCfg = w.getGraphicsConfiguration();
 805         } else {
 806             grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
 807                         getDefaultScreenDevice().getDefaultConfiguration();
 808         }
 809         final GraphicsConfiguration gc = grCfg;
 810 


 908     public boolean printDialog(final PrintRequestAttributeSet attributes)
 909         throws HeadlessException {
 910         if (GraphicsEnvironment.isHeadless()) {
 911             throw new HeadlessException();
 912         }
 913 
 914         DialogTypeSelection dlg =
 915             (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
 916 
 917         // Check for native, note that default dialog is COMMON.
 918         if (dlg == DialogTypeSelection.NATIVE) {
 919             this.attributes = attributes;
 920             try {
 921                 debug_println("calling setAttributes in printDialog");
 922                 setAttributes(attributes);
 923 
 924             } catch (PrinterException e) {
 925 
 926             }
 927 
 928             setParentWindowID(attributes);
 929             boolean ret = printDialog();
 930             clearParentWindowID();
 931             this.attributes = attributes;
 932             return ret;
 933 
 934         }
 935 
 936         /* A security check has already been performed in the
 937          * java.awt.print.printerJob.getPrinterJob method.
 938          * So by the time we get here, it is OK for the current thread
 939          * to print either to a file (from a Dialog we control!) or
 940          * to a chosen printer.
 941          *
 942          * We raise privilege when we put up the dialog, to avoid
 943          * the "warning applet window" banner.
 944          */
 945         GraphicsConfiguration grCfg = null;
 946         Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
 947         if (w != null) {
 948             grCfg = w.getGraphicsConfiguration();
 949              /* Add DialogOwner attribute to set the owner of this print dialog
 950               * only if it is not set already


2525      * This is a utility method used by subclasses to remove them so we
2526      * don't have to worry about platform or font specific handling of them.
2527      */
2528     protected String removeControlChars(String s) {
2529         char[] in_chars = s.toCharArray();
2530         int len = in_chars.length;
2531         char[] out_chars = new char[len];
2532         int pos = 0;
2533 
2534         for (int i = 0; i < len; i++) {
2535             char c = in_chars[i];
2536             if (c > '\r' || c < '\t' || c == '\u000b' || c == '\u000c')  {
2537                out_chars[pos++] = c;
2538             }
2539         }
2540         if (pos == len) {
2541             return s; // no need to make a new String.
2542         } else {
2543             return new String(out_chars, 0, pos);
2544         }
2545     }
2546 
2547     private long parentWindowID = 0L; 
2548 
2549     /* Called from native code */
2550     private long getParentWindowID() {
2551         return parentWindowID;
2552     }
2553 
2554     private void clearParentWindowID() {
2555         parentWindowID = 0L;
2556     }
2557 
2558     private void setParentWindowID(PrintRequestAttributeSet attrs) {
2559         parentWindowID = 0L;
2560         DialogOnTop onTop = (DialogOnTop)attrs.get(DialogOnTop.class);
2561         if (onTop != null) {
2562             parentWindowID = onTop.getID();
2563         }            
2564     }
2565 }
< prev index next >