diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 17ab015b11e3d..2a68571ee1311 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ import javax.print.attribute.standard.MediaSize; import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.PageRanges; +import javax.print.attribute.Attribute; import sun.java2d.*; import sun.print.*; @@ -64,6 +65,8 @@ public final class CPrinterJob extends RasterPrinterJob { private static Font defaultFont; + private String tray = null; + // This is the NSPrintInfo for this PrinterJob. Protect multi thread // access to it. It is used by the pageDialog, jobDialog, and printLoop. // This way the state of these items is shared across these calls. @@ -179,6 +182,11 @@ protected void setAttributes(PrintRequestAttributeSet attributes) throws Printer if (attributes == null) { return; } + Attribute attr = attributes.get(Media.class); + if (attr instanceof CustomMediaTray) { + CustomMediaTray customTray = (CustomMediaTray) attr; + tray = customTray.getChoiceName(); + } PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class); if (isSupportedValue(pageRangesAttr, attributes)) { @@ -631,6 +639,10 @@ private String getPrinterName(){ return service.getName(); } + private String getPrinterTray() { + return tray; + } + private void setPrinterServiceFromNative(String printerName) { // This is called from the native side. PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m index e995da67dcbd5..a09f0e552c6ef 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -546,6 +546,7 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob, static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;"); static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;"); static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;"); + static JNF_MEMBER_CACHE(jm_getPrinterTray, sjc_CPrinterJob, "getPrinterTray", "()Ljava/lang/String;"); jboolean retVal = JNI_FALSE; @@ -560,6 +561,13 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob, [printerView setFirstPage:firstPage lastPage:lastPage]; NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + jobject printerTrayObj = JNFCallObjectMethod(env, jthis, jm_getPrinterTray); + if (printerTrayObj != NULL) { + NSString *printerTray = JNFJavaToNSString(env, printerTrayObj); + if (printerTray != nil) { + [[printInfo printSettings] setObject:printerTray forKey:@"InputSlot"]; + } + } // passing jthis CPrinterJob as well, so we can extract the printer name from the current job javaPageFormatToNSPrintInfo(env, jthis, page, printInfo); diff --git a/src/java.desktop/share/classes/sun/print/CustomMediaTray.java b/src/java.desktop/share/classes/sun/print/CustomMediaTray.java index 394aba988c179..7410dfd978622 100644 --- a/src/java.desktop/share/classes/sun/print/CustomMediaTray.java +++ b/src/java.desktop/share/classes/sun/print/CustomMediaTray.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ import javax.print.attribute.standard.Media; import java.util.ArrayList; -class CustomMediaTray extends MediaTray { +public class CustomMediaTray extends MediaTray { private static ArrayList customStringTable = new ArrayList<>(); private static ArrayList customEnumTable = new ArrayList<>(); private String choiceName; diff --git a/test/jdk/java/awt/print/PrinterJob/TestMediaTraySelection.java b/test/jdk/java/awt/print/PrinterJob/TestMediaTraySelection.java index 26b4637f431bf..f75336c2c0deb 100644 --- a/test/jdk/java/awt/print/PrinterJob/TestMediaTraySelection.java +++ b/test/jdk/java/awt/print/PrinterJob/TestMediaTraySelection.java @@ -21,9 +21,9 @@ * questions. */ /* - * @bug 6357887 8165146 + * @bug 6357887 8165146 8234393 * @summary Verifies if selected printertray is used - * @requires os.family == "linux" + * @requires (os.family == "linux" | os.family == "mac") * @run main/manual TestMediaTraySelection */