下面列出了怎么用java.awt.print.Pageable的API类实例代码及写法,或者点击链接到github查看源代码。
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
public void pageableJob(Pageable pageable) throws PrintException {
try {
synchronized(this) {
if (job != null) { // shouldn't happen
throw new PrintException("already printing");
} else {
job = new PSPrinterJob();
}
}
job.setPrintService(getPrintService());
job.setCopies(copies);
job.setJobName(jobName);
job.setPageable(pageable);
job.print(reqAttrSet);
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
}
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected 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;
}
protected PageFormat getPageFormatFromAttributes() {
Pageable pageable = null;
if (attributes == null || attributes.isEmpty() ||
!((pageable = getPageable()) instanceof OpenBook)) {
return null;
}
PageFormat newPf = attributeToPageFormat(
getPrintService(), attributes);
PageFormat oldPf = null;
if ((oldPf = pageable.getPageFormat(0)) != null) {
// If orientation, media, imageable area attributes are not in
// "attributes" set, then use respective values of the existing
// page format "oldPf".
if (attributes.get(OrientationRequested.class) == null) {
newPf.setOrientation(oldPf.getOrientation());
}
Paper newPaper = newPf.getPaper();
Paper oldPaper = oldPf.getPaper();
boolean oldPaperValWasSet = false;
if (attributes.get(MediaSizeName.class) == null) {
newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight());
oldPaperValWasSet = true;
}
if (attributes.get(MediaPrintableArea.class) == null) {
newPaper.setImageableArea(
oldPaper.getImageableX(), oldPaper.getImageableY(),
oldPaper.getImageableWidth(),
oldPaper.getImageableHeight());
oldPaperValWasSet = true;
}
if (oldPaperValWasSet) {
newPf.setPaper(newPaper);
}
}
return newPf;
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
protected PageFormat getPageFormatFromAttributes() {
if (attributes == null || attributes.isEmpty()) {
return null;
}
PageFormat newPf = attributeToPageFormat(
getPrintService(), attributes);
PageFormat oldPf = null;
Pageable pageable = getPageable();
if ((pageable != null) &&
(pageable instanceof OpenBook) &&
((oldPf = pageable.getPageFormat(0)) != null)) {
// If orientation, media, imageable area attributes are not in
// "attributes" set, then use respective values of the existing
// page format "oldPf".
if (attributes.get(OrientationRequested.class) == null) {
newPf.setOrientation(oldPf.getOrientation());
}
Paper newPaper = newPf.getPaper();
Paper oldPaper = oldPf.getPaper();
boolean oldPaperValWasSet = false;
if (attributes.get(MediaSizeName.class) == null) {
newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight());
oldPaperValWasSet = true;
}
if (attributes.get(MediaPrintableArea.class) == null) {
newPaper.setImageableArea(
oldPaper.getImageableX(), oldPaper.getImageableY(),
oldPaper.getImageableWidth(),
oldPaper.getImageableHeight());
oldPaperValWasSet = true;
}
if (oldPaperValWasSet) {
newPf.setPaper(newPaper);
}
}
return newPf;
}
@Override
public void setPageable(Pageable document) throws NullPointerException {
if (document == null) {
throw new NullPointerException("Pageable cannot be null.");
}
this.pageable = document;
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
protected PageFormat getPageFormatFromAttributes() {
Pageable pageable = null;
if (attributes == null || attributes.isEmpty() ||
!((pageable = getPageable()) instanceof OpenBook)) {
return null;
}
PageFormat newPf = attributeToPageFormat(
getPrintService(), attributes);
PageFormat oldPf = null;
if ((oldPf = pageable.getPageFormat(0)) != null) {
// If orientation, media, imageable area attributes are not in
// "attributes" set, then use respective values of the existing
// page format "oldPf".
if (attributes.get(OrientationRequested.class) == null) {
newPf.setOrientation(oldPf.getOrientation());
}
Paper newPaper = newPf.getPaper();
Paper oldPaper = oldPf.getPaper();
boolean oldPaperValWasSet = false;
if (attributes.get(MediaSizeName.class) == null) {
newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight());
oldPaperValWasSet = true;
}
if (attributes.get(MediaPrintableArea.class) == null) {
newPaper.setImageableArea(
oldPaper.getImageableX(), oldPaper.getImageableY(),
oldPaper.getImageableWidth(),
oldPaper.getImageableHeight());
oldPaperValWasSet = true;
}
if (oldPaperValWasSet) {
newPf.setPaper(newPaper);
}
}
return newPf;
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}
/**
* Set the range of pages from a Book to be printed.
* Both 'firstPage' and 'lastPage' are zero based
* page indices. If either parameter is less than
* zero then the page range is set to be from the
* first page to the last.
*/
protected void setPageRange(int firstPage, int lastPage) {
if(firstPage >= 0 && lastPage >= 0) {
mFirstPage = firstPage;
mLastPage = lastPage;
if(mLastPage < mFirstPage) mLastPage = mFirstPage;
} else {
mFirstPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
mLastPage = Pageable.UNKNOWN_NUMBER_OF_PAGES;
}
}