use of javax.print.attribute.standard.DialogTypeSelection in project jdk8u_jdk by JetBrains.
the class PSPrinterJob method printDialog.
/* Instance Methods */
/**
* Presents the user a dialog for changing properties of the
* print job interactively.
* @returns false if the user cancels the dialog and
* true otherwise.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public boolean printDialog() throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
if (attributes == null) {
attributes = new HashPrintRequestAttributeSet();
}
attributes.add(new Copies(getCopies()));
attributes.add(new JobName(getJobName(), null));
boolean doPrint = false;
DialogTypeSelection dts = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
if (dts == DialogTypeSelection.NATIVE) {
// Remove DialogTypeSelection.NATIVE to prevent infinite loop in
// RasterPrinterJob.
attributes.remove(DialogTypeSelection.class);
doPrint = printDialog(attributes);
// restore attribute
attributes.add(DialogTypeSelection.NATIVE);
} else {
doPrint = printDialog(attributes);
}
if (doPrint) {
JobName jobName = (JobName) attributes.get(JobName.class);
if (jobName != null) {
setJobName(jobName.getValue());
}
Copies copies = (Copies) attributes.get(Copies.class);
if (copies != null) {
setCopies(copies.getValue());
}
Destination dest = (Destination) attributes.get(Destination.class);
if (dest != null) {
try {
mDestType = RasterPrinterJob.FILE;
mDestination = (new File(dest.getURI())).getPath();
} catch (Exception e) {
mDestination = "out.ps";
}
} else {
mDestType = RasterPrinterJob.PRINTER;
PrintService pServ = getPrintService();
if (pServ != null) {
mDestination = pServ.getName();
if (isMac) {
PrintServiceAttributeSet psaSet = pServ.getAttributes();
if (psaSet != null) {
mDestination = psaSet.get(PrinterName.class).toString();
}
}
}
}
}
return doPrint;
}
use of javax.print.attribute.standard.DialogTypeSelection in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method pageDialog.
/**
* Display a dialog to the user allowing the modification of a
* PageFormat instance.
* The <code>page</code> argument is used to initialize controls
* in the page setup dialog.
* If the user cancels the dialog, then the method returns the
* original <code>page</code> object unmodified.
* If the user okays the dialog then the method returns a new
* PageFormat object with the indicated changes.
* In either case the original <code>page</code> object will
* not be modified.
* @param page the default PageFormat presented to the user
* for modification
* @return the original <code>page</code> object if the dialog
* is cancelled, or a new PageFormat object containing
* the format indicated by the user if the dialog is
* acknowledged
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.2
*/
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
PrintService service = getPrintService();
if (service == null) {
ServiceDialog.showNoPrintService(gc);
return null;
}
return service;
}
});
if (service == null) {
return page;
}
updatePageAttributes(service, page);
PageFormat newPage = null;
DialogTypeSelection dts = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
if (dts == DialogTypeSelection.NATIVE) {
// Remove DialogTypeSelection.NATIVE to prevent infinite loop in
// RasterPrinterJob.
attributes.remove(DialogTypeSelection.class);
newPage = pageDialog(attributes);
// restore attribute
attributes.add(DialogTypeSelection.NATIVE);
} else {
newPage = pageDialog(attributes);
}
if (newPage == null) {
return page;
} else {
return newPage;
}
}
use of javax.print.attribute.standard.DialogTypeSelection in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method printDialog.
/**
* Presents the user a dialog for changing properties of the
* print job interactively.
* The services browsable here are determined by the type of
* service currently installed.
* If the application installed a StreamPrintService on this
* PrinterJob, only the available StreamPrintService (factories) are
* browsable.
*
* @param attributes to store changed properties.
* @return false if the user cancels the dialog and true otherwise.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public boolean printDialog(final PrintRequestAttributeSet attributes) throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
DialogTypeSelection dlg = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
// Check for native, note that default dialog is COMMON.
if (dlg == DialogTypeSelection.NATIVE) {
this.attributes = attributes;
try {
debug_println("calling setAttributes in printDialog");
setAttributes(attributes);
} catch (PrinterException e) {
}
setParentWindowID(attributes);
boolean ret = printDialog();
clearParentWindowID();
this.attributes = attributes;
return ret;
}
/* A security check has already been performed in the
* java.awt.print.printerJob.getPrinterJob method.
* So by the time we get here, it is OK for the current thread
* to print either to a file (from a Dialog we control!) or
* to a chosen printer.
*
* We raise privilege when we put up the dialog, to avoid
* the "warning applet window" banner.
*/
final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
PrintService service = getPrintService();
if (service == null) {
ServiceDialog.showNoPrintService(gc);
return null;
}
return service;
}
});
if (service == null) {
return false;
}
PrintService[] services;
StreamPrintServiceFactory[] spsFactories = null;
if (service instanceof StreamPrintService) {
spsFactories = lookupStreamPrintServices(null);
services = new StreamPrintService[spsFactories.length];
for (int i = 0; i < spsFactories.length; i++) {
services[i] = spsFactories[i].getPrintService(null);
}
} else {
services = (PrintService[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
PrintService[] services = PrinterJob.lookupPrintServices();
return services;
}
});
if ((services == null) || (services.length == 0)) {
/*
* No services but default PrintService exists?
* Create services using defaultService.
*/
services = new PrintService[1];
services[0] = service;
}
}
Rectangle bounds = gc.getBounds();
int x = bounds.x + bounds.width / 3;
int y = bounds.y + bounds.height / 3;
PrintService newService;
// temporarily add an attribute pointing back to this job.
PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this);
attributes.add(jobWrapper);
try {
newService = ServiceUI.printDialog(gc, x, y, services, service, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes);
} catch (IllegalArgumentException iae) {
newService = ServiceUI.printDialog(gc, x, y, services, services[0], DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes);
}
attributes.remove(PrinterJobWrapper.class);
if (newService == null) {
return false;
}
if (!service.equals(newService)) {
try {
setPrintService(newService);
} catch (PrinterException e) {
/*
* The only time it would throw an exception is when
* newService is no longer available but we should still
* select this printer.
*/
myService = newService;
}
}
return true;
}
use of javax.print.attribute.standard.DialogTypeSelection in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method pageDialog.
/**
* return a PageFormat corresponding to the updated attributes,
* or null if the user cancelled the dialog.
*/
public PageFormat pageDialog(final PrintRequestAttributeSet attributes) throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
DialogTypeSelection dlg = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
// Check for native, note that default dialog is COMMON.
if (dlg == DialogTypeSelection.NATIVE) {
PrintService pservice = getPrintService();
PageFormat pageFrmAttrib = attributeToPageFormat(pservice, attributes);
setParentWindowID(attributes);
PageFormat page = pageDialog(pageFrmAttrib);
clearParentWindowID();
// page object and as per spec, we should return null in that case.
if (page == pageFrmAttrib) {
return null;
}
updateAttributesWithPageFormat(pservice, page, attributes);
return page;
}
final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
int x = bounds.x + bounds.width / 3;
int y = bounds.y + bounds.height / 3;
PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
PrintService service = getPrintService();
if (service == null) {
ServiceDialog.showNoPrintService(gc);
return null;
}
return service;
}
});
if (service == null) {
return null;
}
if (onTop != null) {
attributes.add(onTop);
}
ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes, (Frame) null);
pageDialog.show();
if (pageDialog.getStatus() == ServiceDialog.APPROVE) {
PrintRequestAttributeSet newas = pageDialog.getAttributes();
Class amCategory = SunAlternateMedia.class;
if (attributes.containsKey(amCategory) && !newas.containsKey(amCategory)) {
attributes.remove(amCategory);
}
attributes.addAll(newas);
return attributeToPageFormat(service, attributes);
} else {
return null;
}
}
Aggregations