提交 8c79a55e 编写于 作者: J jgodinez

8025988: [macosx] Attribute settings don't work for JobAttributes range

8025990: [macosx] Attribute settings don't work for JobAttributes setOrientationRequested, setMedia
Reviewed-by: prr, jchen
上级 2c74eeb4
...@@ -359,7 +359,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj ...@@ -359,7 +359,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable"); static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I"); static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z"); static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;");
NSMutableDictionary* printingDictionary = [dst dictionary]; NSMutableDictionary* printingDictionary = [dst dictionary];
...@@ -368,19 +372,35 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj ...@@ -368,19 +372,35 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object) jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object)
[printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate]; [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate];
jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit) jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit)
if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES) if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES)
{ {
[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; jint selectID = JNFCallIntMethod(env, srcPrinterJob, jm_getSelectAttrib);
if (selectID ==0) {
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
} else if (selectID == 2) {
// In Mac 10.7, Print ALL is deselected if PrintSelection is YES whether
// NSPrintAllPages is YES or NO
[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];
} else {
[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
}
[printingDictionary setObject:[NSNumber numberWithInteger:1] forKey:NSPrintFirstPage]; jint fromPage = JNFCallIntMethod(env, srcPrinterJob, jm_getFromPage);
[printingDictionary setObject:[NSNumber numberWithInteger:jNumPages] forKey:NSPrintLastPage]; jint toPage = JNFCallIntMethod(env, srcPrinterJob, jm_getToPage);
// setting fromPage and toPage will not be shown in the dialog if printing All pages
[printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
[printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
} }
else else
{ {
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages]; [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
} }
jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat);
if (page != NULL) {
javaPageFormatToNSPrintInfo(env, NULL, page, dst);
}
} }
/* /*
......
...@@ -117,6 +117,16 @@ public abstract class RasterPrinterJob extends PrinterJob { ...@@ -117,6 +117,16 @@ public abstract class RasterPrinterJob extends PrinterJob {
/* Stream destination type. */ /* Stream destination type. */
protected static final int STREAM = 2; protected static final int STREAM = 2;
/**
* Pageable MAX pages
*/
private static final int MAX_UNKNOWN_PAGES = 9999;
private static final int PD_ALLPAGES = 0x00000000;
private static final int PD_SELECTION = 0x00000001;
private static final int PD_PAGENUMS = 0x00000002;
private static final int PD_NOSELECTION = 0x00000004;
/** /**
* Maximum amount of memory in bytes to use for the * Maximum amount of memory in bytes to use for the
* buffered image "band". 4Mb is a compromise between * buffered image "band". 4Mb is a compromise between
...@@ -800,6 +810,14 @@ public abstract class RasterPrinterJob extends PrinterJob { ...@@ -800,6 +810,14 @@ public abstract class RasterPrinterJob extends PrinterJob {
} }
} }
protected PageFormat getPageFormatFromAttributes() {
if (attributes == null) {
return null;
}
return attributeToPageFormat(getPrintService(), this.attributes);
}
/** /**
* Presents the user a dialog for changing properties of the * Presents the user a dialog for changing properties of the
* print job interactively. * print job interactively.
...@@ -1762,6 +1780,78 @@ public abstract class RasterPrinterJob extends PrinterJob { ...@@ -1762,6 +1780,78 @@ public abstract class RasterPrinterJob extends PrinterJob {
return mCollate; return mCollate;
} }
private final int getSelectAttrib() {
if (attributes != null) {
SunPageSelection pages =
(SunPageSelection)attributes.get(SunPageSelection.class);
if (pages == SunPageSelection.RANGE) {
return PD_PAGENUMS;
} else if (pages == SunPageSelection.SELECTION) {
return PD_SELECTION;
} else if (pages == SunPageSelection.ALL) {
return PD_ALLPAGES;
}
}
return PD_NOSELECTION;
}
//returns 1-based index for "From" page
private final int getFromPageAttrib() {
if (attributes != null) {
PageRanges pageRangesAttr =
(PageRanges)attributes.get(PageRanges.class);
if (pageRangesAttr != null) {
int[][] range = pageRangesAttr.getMembers();
return range[0][0];
}
}
return getMinPageAttrib();
}
//returns 1-based index for "To" page
private final int getToPageAttrib() {
if (attributes != null) {
PageRanges pageRangesAttr =
(PageRanges)attributes.get(PageRanges.class);
if (pageRangesAttr != null) {
int[][] range = pageRangesAttr.getMembers();
return range[range.length-1][1];
}
}
return getMaxPageAttrib();
}
private final int getMinPageAttrib() {
if (attributes != null) {
SunMinMaxPage s =
(SunMinMaxPage)attributes.get(SunMinMaxPage.class);
if (s != null) {
return s.getMin();
}
}
return 1;
}
private final int getMaxPageAttrib() {
if (attributes != null) {
SunMinMaxPage s =
(SunMinMaxPage)attributes.get(SunMinMaxPage.class);
if (s != null) {
return s.getMax();
}
}
Pageable pageable = getPageable();
if (pageable != null) {
int numPages = pageable.getNumberOfPages();
if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) {
numPages = MAX_UNKNOWN_PAGES;
}
return ((numPages == 0) ? 1 : numPages);
}
return Integer.MAX_VALUE;
}
/** /**
* Called by the print() method at the start of * Called by the print() method at the start of
* a print job. * a print job.
......
...@@ -183,10 +183,6 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -183,10 +183,6 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
/** /**
* Values must match those defined in wingdi.h & commdlg.h * Values must match those defined in wingdi.h & commdlg.h
*/ */
private static final int PD_ALLPAGES = 0x00000000;
private static final int PD_SELECTION = 0x00000001;
private static final int PD_PAGENUMS = 0x00000002;
private static final int PD_NOSELECTION = 0x00000004;
private static final int PD_COLLATE = 0x00000010; private static final int PD_COLLATE = 0x00000010;
private static final int PD_PRINTTOFILE = 0x00000020; private static final int PD_PRINTTOFILE = 0x00000020;
private static final int DM_ORIENTATION = 0x00000001; private static final int DM_ORIENTATION = 0x00000001;
...@@ -1639,63 +1635,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1639,63 +1635,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
} }
} }
//returns 1-based index for "From" page
private final int getFromPageAttrib() {
if (attributes != null) {
PageRanges pageRangesAttr =
(PageRanges)attributes.get(PageRanges.class);
if (pageRangesAttr != null) {
int[][] range = pageRangesAttr.getMembers();
return range[0][0];
}
}
return getMinPageAttrib();
}
//returns 1-based index for "To" page
private final int getToPageAttrib() {
if (attributes != null) {
PageRanges pageRangesAttr =
(PageRanges)attributes.get(PageRanges.class);
if (pageRangesAttr != null) {
int[][] range = pageRangesAttr.getMembers();
return range[range.length-1][1];
}
}
return getMaxPageAttrib();
}
private final int getMinPageAttrib() {
if (attributes != null) {
SunMinMaxPage s =
(SunMinMaxPage)attributes.get(SunMinMaxPage.class);
if (s != null) {
return s.getMin();
}
}
return 1;
}
private final int getMaxPageAttrib() {
if (attributes != null) {
SunMinMaxPage s =
(SunMinMaxPage)attributes.get(SunMinMaxPage.class);
if (s != null) {
return s.getMax();
}
}
Pageable pageable = getPageable();
if (pageable != null) {
int numPages = pageable.getNumberOfPages();
if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) {
numPages = MAX_UNKNOWN_PAGES;
}
return ((numPages == 0) ? 1 : numPages);
}
return Integer.MAX_VALUE;
}
private final boolean getDestAttrib() { private final boolean getDestAttrib() {
return (mDestination != null); return (mDestination != null);
...@@ -1847,20 +1787,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1847,20 +1787,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
return mAttMediaTray; return mAttMediaTray;
} }
private final int getSelectAttrib() {
if (attributes != null) {
SunPageSelection pages =
(SunPageSelection)attributes.get(SunPageSelection.class);
if (pages == SunPageSelection.RANGE) {
return PD_PAGENUMS;
} else if (pages == SunPageSelection.SELECTION) {
return PD_SELECTION;
} else if (pages == SunPageSelection.ALL) {
return PD_ALLPAGES;
}
}
return PD_NOSELECTION;
}
private final boolean getPrintToFileEnabled() { private final boolean getPrintToFileEnabled() {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
/* /*
* @test * @test
* @bug 4851363 * @bug 4851363 8025988 8025990
* @summary Tests the save to file dialog has a title * @summary Tests the save to file dialog has a title.
* @run main/manual=yesno/othervm SaveDialogTitleTest * @run main/manual=yesno/othervm SaveDialogTitleTest
*/ */
...@@ -37,12 +37,21 @@ public class SaveDialogTitleTest { ...@@ -37,12 +37,21 @@ public class SaveDialogTitleTest {
System.out.print("Once the dialog appears, press OK and the "); System.out.print("Once the dialog appears, press OK and the ");
System.out.print("Save to File dialog should appear and it "); System.out.print("Save to File dialog should appear and it ");
System.out.println("must have a window title else the test fails."); System.out.println("must have a window title else the test fails.");
System.out.println("To test 8025988: Range should be selected with pages 3 to 8.");
System.out.println("To test 8025990: Paper should be Legal and in Landscape.");
Toolkit tk = Toolkit.getDefaultToolkit(); Toolkit tk = Toolkit.getDefaultToolkit();
JobAttributes jobAttributes = new JobAttributes(); JobAttributes jobAttributes = new JobAttributes();
jobAttributes.setDestination(JobAttributes.DestinationType.FILE); jobAttributes.setDestination(JobAttributes.DestinationType.FILE);
jobAttributes.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE);
jobAttributes.setPageRanges(new int[][]{new int[]{3,8}});
PageAttributes page = new PageAttributes();
page.setMedia(PageAttributes.MediaType.LEGAL);
page.setOrientationRequested(PageAttributes.
OrientationRequestedType.LANDSCAPE);
PrintJob printJob = PrintJob printJob =
tk.getPrintJob(new Frame(), "Save Title Test", tk.getPrintJob(new Frame(), "Save Title Test",
jobAttributes, null); jobAttributes, page);
if (printJob != null) { // in case user cancels. if (printJob != null) { // in case user cancels.
printJob.end(); printJob.end();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册