256 */
257 private String mDocName = "Java Printing";
258
259
260 /**
261 * Printing cancellation flags
262 */
263 // MacOSX - made protected so subclasses can reference it.
264 protected boolean performingPrinting = false;
265 // MacOSX - made protected so subclasses can reference it.
266 protected boolean userCancelled = false;
267
268 /**
269 * Print to file permission variables.
270 */
271 private FilePermission printToFilePermission;
272
273 /**
274 * List of areas & the graphics state for redrawing
275 */
276 private ArrayList redrawList = new ArrayList();
277
278
279 /* variables representing values extracted from an attribute set.
280 * These take precedence over values set on a printer job
281 */
282 private int copiesAttr;
283 private String jobNameAttr;
284 private String userNameAttr;
285 private PageRanges pageRangesAttr;
286 protected Sides sidesAttr;
287 protected String destinationAttr;
288 protected boolean noJobSheet = false;
289 protected int mDestType = RasterPrinterJob.FILE;
290 protected String mDestination = "";
291 protected boolean collateAttReq = false;
292
293 /**
294 * Device rotation flag, if it support 270, this is set to true;
295 */
296 protected boolean landscapeRotates270 = false;
695 * for modification
696 * @return the original <code>page</code> object if the dialog
697 * is cancelled, or a new PageFormat object containing
698 * the format indicated by the user if the dialog is
699 * acknowledged
700 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
701 * returns true.
702 * @see java.awt.GraphicsEnvironment#isHeadless
703 * @since 1.2
704 */
705 public PageFormat pageDialog(PageFormat page)
706 throws HeadlessException {
707 if (GraphicsEnvironment.isHeadless()) {
708 throw new HeadlessException();
709 }
710
711 final GraphicsConfiguration gc =
712 GraphicsEnvironment.getLocalGraphicsEnvironment().
713 getDefaultScreenDevice().getDefaultConfiguration();
714
715 PrintService service =
716 (PrintService)java.security.AccessController.doPrivileged(
717 new java.security.PrivilegedAction() {
718 public Object run() {
719 PrintService service = getPrintService();
720 if (service == null) {
721 ServiceDialog.showNoPrintService(gc);
722 return null;
723 }
724 return service;
725 }
726 });
727
728 if (service == null) {
729 return page;
730 }
731 updatePageAttributes(service, page);
732
733 PageFormat newPage = pageDialog(attributes);
734
735 if (newPage == null) {
736 return page;
737 } else {
738 return newPage;
751
752 DialogTypeSelection dlg =
753 (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
754
755 // Check for native, note that default dialog is COMMON.
756 if (dlg == DialogTypeSelection.NATIVE) {
757 PrintService pservice = getPrintService();
758 PageFormat page = pageDialog(attributeToPageFormat(pservice,
759 attributes));
760 updateAttributesWithPageFormat(pservice, page, attributes);
761 return page;
762 }
763
764 final GraphicsConfiguration gc =
765 GraphicsEnvironment.getLocalGraphicsEnvironment().
766 getDefaultScreenDevice().getDefaultConfiguration();
767 Rectangle bounds = gc.getBounds();
768 int x = bounds.x+bounds.width/3;
769 int y = bounds.y+bounds.height/3;
770
771 PrintService service =
772 (PrintService)java.security.AccessController.doPrivileged(
773 new java.security.PrivilegedAction() {
774 public Object run() {
775 PrintService service = getPrintService();
776 if (service == null) {
777 ServiceDialog.showNoPrintService(gc);
778 return null;
779 }
780 return service;
781 }
782 });
783
784 if (service == null) {
785 return null;
786 }
787
788 ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service,
789 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
790 attributes, (Frame)null);
791 pageDialog.show();
792
793 if (pageDialog.getStatus() == ServiceDialog.APPROVE) {
794 PrintRequestAttributeSet newas =
795 pageDialog.getAttributes();
796 Class amCategory = SunAlternateMedia.class;
797
798 if (attributes.containsKey(amCategory) &&
799 !newas.containsKey(amCategory)) {
800 attributes.remove(amCategory);
801 }
802 attributes.addAll(newas);
803 return attributeToPageFormat(service, attributes);
804 } else {
805 return null;
806 }
807 }
808
809 protected PageFormat getPageFormatFromAttributes() {
810 if (attributes == null) {
811 return null;
812 }
813 return attributeToPageFormat(getPrintService(), this.attributes);
814 }
815
816
851
852 boolean ret = printDialog();
853 this.attributes = attributes;
854 return ret;
855
856 }
857
858 /* A security check has already been performed in the
859 * java.awt.print.printerJob.getPrinterJob method.
860 * So by the time we get here, it is OK for the current thread
861 * to print either to a file (from a Dialog we control!) or
862 * to a chosen printer.
863 *
864 * We raise privilege when we put up the dialog, to avoid
865 * the "warning applet window" banner.
866 */
867 final GraphicsConfiguration gc =
868 GraphicsEnvironment.getLocalGraphicsEnvironment().
869 getDefaultScreenDevice().getDefaultConfiguration();
870
871 PrintService service =
872 (PrintService)java.security.AccessController.doPrivileged(
873 new java.security.PrivilegedAction() {
874 public Object run() {
875 PrintService service = getPrintService();
876 if (service == null) {
877 ServiceDialog.showNoPrintService(gc);
878 return null;
879 }
880 return service;
881 }
882 });
883
884 if (service == null) {
885 return false;
886 }
887
888 PrintService[] services;
889 StreamPrintServiceFactory[] spsFactories = null;
890 if (service instanceof StreamPrintService) {
891 spsFactories = lookupStreamPrintServices(null);
892 services = new StreamPrintService[spsFactories.length];
893 for (int i=0; i<spsFactories.length; i++) {
894 services[i] = spsFactories[i].getPrintService(null);
895 }
896 } else {
897 services =
898 (PrintService[])java.security.AccessController.doPrivileged(
899 new java.security.PrivilegedAction() {
900 public Object run() {
901 PrintService[] services = PrinterJob.lookupPrintServices();
902 return services;
903 }
904 });
905
906 if ((services == null) || (services.length == 0)) {
907 /*
908 * No services but default PrintService exists?
909 * Create services using defaultService.
910 */
911 services = new PrintService[1];
912 services[0] = service;
913 }
914 }
915
916 Rectangle bounds = gc.getBounds();
917 int x = bounds.x+bounds.width/3;
918 int y = bounds.y+bounds.height/3;
919 PrintService newService;
920 // temporarily add an attribute pointing back to this job.
2114 * underlying graphics system then we do not
2115 * need to rasterize. We also may not need to
2116 * create the 'band' if all the pages can take
2117 * this path.
2118 */
2119 if (pathGraphics != null) {
2120 pathGraphics.transform(scaleTransform);
2121 // user (0,0) should be origin of page, not imageable area
2122 pathGraphics.translate(-getPhysicalPrintableX(paper) / xScale,
2123 -getPhysicalPrintableY(paper) / yScale);
2124 pathGraphics.transform(new AffineTransform(page.getMatrix()));
2125 initPrinterGraphics(pathGraphics, pageFormatArea);
2126
2127 redrawList.clear();
2128
2129 AffineTransform initialTx = pathGraphics.getTransform();
2130
2131 painter.print(pathGraphics, origPage, pageIndex);
2132
2133 for (int i=0;i<redrawList.size();i++) {
2134 GraphicsState gstate = (GraphicsState)redrawList.get(i);
2135 pathGraphics.setTransform(initialTx);
2136 ((PathGraphics)pathGraphics).redrawRegion(
2137 gstate.region,
2138 gstate.sx,
2139 gstate.sy,
2140 gstate.theClip,
2141 gstate.theTransform);
2142 }
2143
2144 /* This is the banded-raster printing loop.
2145 * It should be moved into its own method.
2146 */
2147 } else {
2148 BufferedImage band = cachedBand;
2149 if (cachedBand == null ||
2150 bandWidth != cachedBandWidth ||
2151 bandHeight != cachedBandHeight) {
2152 band = new BufferedImage(bandWidth, bandHeight,
2153 BufferedImage.TYPE_3BYTE_BGR);
2154 cachedBand = band;
|
256 */
257 private String mDocName = "Java Printing";
258
259
260 /**
261 * Printing cancellation flags
262 */
263 // MacOSX - made protected so subclasses can reference it.
264 protected boolean performingPrinting = false;
265 // MacOSX - made protected so subclasses can reference it.
266 protected boolean userCancelled = false;
267
268 /**
269 * Print to file permission variables.
270 */
271 private FilePermission printToFilePermission;
272
273 /**
274 * List of areas & the graphics state for redrawing
275 */
276 private ArrayList<GraphicsState> redrawList = new ArrayList<>();
277
278
279 /* variables representing values extracted from an attribute set.
280 * These take precedence over values set on a printer job
281 */
282 private int copiesAttr;
283 private String jobNameAttr;
284 private String userNameAttr;
285 private PageRanges pageRangesAttr;
286 protected Sides sidesAttr;
287 protected String destinationAttr;
288 protected boolean noJobSheet = false;
289 protected int mDestType = RasterPrinterJob.FILE;
290 protected String mDestination = "";
291 protected boolean collateAttReq = false;
292
293 /**
294 * Device rotation flag, if it support 270, this is set to true;
295 */
296 protected boolean landscapeRotates270 = false;
695 * for modification
696 * @return the original <code>page</code> object if the dialog
697 * is cancelled, or a new PageFormat object containing
698 * the format indicated by the user if the dialog is
699 * acknowledged
700 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
701 * returns true.
702 * @see java.awt.GraphicsEnvironment#isHeadless
703 * @since 1.2
704 */
705 public PageFormat pageDialog(PageFormat page)
706 throws HeadlessException {
707 if (GraphicsEnvironment.isHeadless()) {
708 throw new HeadlessException();
709 }
710
711 final GraphicsConfiguration gc =
712 GraphicsEnvironment.getLocalGraphicsEnvironment().
713 getDefaultScreenDevice().getDefaultConfiguration();
714
715 PrintService service = java.security.AccessController.doPrivileged(
716 new java.security.PrivilegedAction<PrintService>() {
717 public PrintService run() {
718 PrintService service = getPrintService();
719 if (service == null) {
720 ServiceDialog.showNoPrintService(gc);
721 return null;
722 }
723 return service;
724 }
725 });
726
727 if (service == null) {
728 return page;
729 }
730 updatePageAttributes(service, page);
731
732 PageFormat newPage = pageDialog(attributes);
733
734 if (newPage == null) {
735 return page;
736 } else {
737 return newPage;
750
751 DialogTypeSelection dlg =
752 (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
753
754 // Check for native, note that default dialog is COMMON.
755 if (dlg == DialogTypeSelection.NATIVE) {
756 PrintService pservice = getPrintService();
757 PageFormat page = pageDialog(attributeToPageFormat(pservice,
758 attributes));
759 updateAttributesWithPageFormat(pservice, page, attributes);
760 return page;
761 }
762
763 final GraphicsConfiguration gc =
764 GraphicsEnvironment.getLocalGraphicsEnvironment().
765 getDefaultScreenDevice().getDefaultConfiguration();
766 Rectangle bounds = gc.getBounds();
767 int x = bounds.x+bounds.width/3;
768 int y = bounds.y+bounds.height/3;
769
770 PrintService service = java.security.AccessController.doPrivileged(
771 new java.security.PrivilegedAction<PrintService>() {
772 public PrintService run() {
773 PrintService service = getPrintService();
774 if (service == null) {
775 ServiceDialog.showNoPrintService(gc);
776 return null;
777 }
778 return service;
779 }
780 });
781
782 if (service == null) {
783 return null;
784 }
785
786 ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service,
787 DocFlavor.SERVICE_FORMATTED.PAGEABLE,
788 attributes, (Frame)null);
789 pageDialog.show();
790
791 if (pageDialog.getStatus() == ServiceDialog.APPROVE) {
792 PrintRequestAttributeSet newas =
793 pageDialog.getAttributes();
794 Class<?> amCategory = SunAlternateMedia.class;
795
796 if (attributes.containsKey(amCategory) &&
797 !newas.containsKey(amCategory)) {
798 attributes.remove(amCategory);
799 }
800 attributes.addAll(newas);
801 return attributeToPageFormat(service, attributes);
802 } else {
803 return null;
804 }
805 }
806
807 protected PageFormat getPageFormatFromAttributes() {
808 if (attributes == null) {
809 return null;
810 }
811 return attributeToPageFormat(getPrintService(), this.attributes);
812 }
813
814
849
850 boolean ret = printDialog();
851 this.attributes = attributes;
852 return ret;
853
854 }
855
856 /* A security check has already been performed in the
857 * java.awt.print.printerJob.getPrinterJob method.
858 * So by the time we get here, it is OK for the current thread
859 * to print either to a file (from a Dialog we control!) or
860 * to a chosen printer.
861 *
862 * We raise privilege when we put up the dialog, to avoid
863 * the "warning applet window" banner.
864 */
865 final GraphicsConfiguration gc =
866 GraphicsEnvironment.getLocalGraphicsEnvironment().
867 getDefaultScreenDevice().getDefaultConfiguration();
868
869 PrintService service = java.security.AccessController.doPrivileged(
870 new java.security.PrivilegedAction<PrintService>() {
871 public PrintService run() {
872 PrintService service = getPrintService();
873 if (service == null) {
874 ServiceDialog.showNoPrintService(gc);
875 return null;
876 }
877 return service;
878 }
879 });
880
881 if (service == null) {
882 return false;
883 }
884
885 PrintService[] services;
886 StreamPrintServiceFactory[] spsFactories = null;
887 if (service instanceof StreamPrintService) {
888 spsFactories = lookupStreamPrintServices(null);
889 services = new StreamPrintService[spsFactories.length];
890 for (int i=0; i<spsFactories.length; i++) {
891 services[i] = spsFactories[i].getPrintService(null);
892 }
893 } else {
894 services = java.security.AccessController.doPrivileged(
895 new java.security.PrivilegedAction<PrintService[]>() {
896 public PrintService[] run() {
897 PrintService[] services = PrinterJob.lookupPrintServices();
898 return services;
899 }
900 });
901
902 if ((services == null) || (services.length == 0)) {
903 /*
904 * No services but default PrintService exists?
905 * Create services using defaultService.
906 */
907 services = new PrintService[1];
908 services[0] = service;
909 }
910 }
911
912 Rectangle bounds = gc.getBounds();
913 int x = bounds.x+bounds.width/3;
914 int y = bounds.y+bounds.height/3;
915 PrintService newService;
916 // temporarily add an attribute pointing back to this job.
2110 * underlying graphics system then we do not
2111 * need to rasterize. We also may not need to
2112 * create the 'band' if all the pages can take
2113 * this path.
2114 */
2115 if (pathGraphics != null) {
2116 pathGraphics.transform(scaleTransform);
2117 // user (0,0) should be origin of page, not imageable area
2118 pathGraphics.translate(-getPhysicalPrintableX(paper) / xScale,
2119 -getPhysicalPrintableY(paper) / yScale);
2120 pathGraphics.transform(new AffineTransform(page.getMatrix()));
2121 initPrinterGraphics(pathGraphics, pageFormatArea);
2122
2123 redrawList.clear();
2124
2125 AffineTransform initialTx = pathGraphics.getTransform();
2126
2127 painter.print(pathGraphics, origPage, pageIndex);
2128
2129 for (int i=0;i<redrawList.size();i++) {
2130 GraphicsState gstate = redrawList.get(i);
2131 pathGraphics.setTransform(initialTx);
2132 ((PathGraphics)pathGraphics).redrawRegion(
2133 gstate.region,
2134 gstate.sx,
2135 gstate.sy,
2136 gstate.theClip,
2137 gstate.theTransform);
2138 }
2139
2140 /* This is the banded-raster printing loop.
2141 * It should be moved into its own method.
2142 */
2143 } else {
2144 BufferedImage band = cachedBand;
2145 if (cachedBand == null ||
2146 bandWidth != cachedBandWidth ||
2147 bandHeight != cachedBandHeight) {
2148 band = new BufferedImage(bandWidth, bandHeight,
2149 BufferedImage.TYPE_3BYTE_BGR);
2150 cachedBand = band;
|