本文整理汇总了Java中java.awt.JobAttributes.getFileName方法的典型用法代码示例。如果您正苦于以下问题:Java JobAttributes.getFileName方法的具体用法?Java JobAttributes.getFileName怎么用?Java JobAttributes.getFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.JobAttributes
的用法示例。
在下文中一共展示了JobAttributes.getFileName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPrintJob2D
import java.awt.JobAttributes; //导入方法依赖的package包/类
private void initPrintJob2D(Frame frame, String doctitle,
JobAttributes jobAttributes,
PageAttributes pageAttributes) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPrintJobAccess();
}
if (frame == null &&
(jobAttributes == null ||
jobAttributes.getDialog() == DialogType.NATIVE)) {
throw new NullPointerException("Frame must not be null");
}
this.frame = frame;
this.docTitle = (doctitle == null) ? "" : doctitle;
this.jobAttributes = (jobAttributes != null)
? jobAttributes : new JobAttributes();
this.pageAttributes = (pageAttributes != null)
? pageAttributes : new PageAttributes();
// Currently, we always reduce page ranges to xxx or xxx-xxx
int[][] pageRanges = this.jobAttributes.getPageRanges();
int first = pageRanges[0][0];
int last = pageRanges[pageRanges.length - 1][1];
this.jobAttributes.setPageRanges(new int[][] {
new int[] { first, last }
});
this.jobAttributes.setToPage(last);
this.jobAttributes.setFromPage(first);
// Verify that the cross feed and feed resolutions are the same
int[] res = this.pageAttributes.getPrinterResolution();
if (res[0] != res[1]) {
throw new IllegalArgumentException("Differing cross feed and feed"+
" resolutions not supported.");
}
// Verify that the app has access to the file system
DestinationType dest= this.jobAttributes.getDestination();
if (dest == DestinationType.FILE) {
throwPrintToFile();
// check if given filename is valid
String destStr = jobAttributes.getFileName();
if ((destStr != null) &&
(jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {
File f = new File(destStr);
try {
// check if this is a new file and if filename chars are valid
// createNewFile returns false if file exists
if (f.createNewFile()) {
f.delete();
}
} catch (IOException ioe) {
throw new IllegalArgumentException("Cannot write to file:"+
destStr);
} catch (SecurityException se) {
//There is already file read/write access so at this point
// only delete access is denied. Just ignore it because in
// most cases the file created in createNewFile gets overwritten
// anyway.
}
File pFile = f.getParentFile();
if ((f.exists() &&
(!f.isFile() || !f.canWrite())) ||
((pFile != null) &&
(!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
throw new IllegalArgumentException("Cannot write to file:"+
destStr);
}
}
}
}