use of javax.print.PrintService in project JMRI by JMRI.
the class TrainPrintUtilities method getPrinterJComboBox.
public static JComboBox<String> getPrinterJComboBox() {
JComboBox<String> box = new JComboBox<>();
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService printService : services) {
box.addItem(printService.getName());
}
// Set to default printer
box.setSelectedItem(getDefaultPrinterName());
return box;
}
use of javax.print.PrintService 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.PrintService in project jdk8u_jdk by JetBrains.
the class PSPrinterJob method startPage.
/**
* The RasterPrintJob super class calls this method
* at the start of each page.
*/
protected void startPage(PageFormat pageFormat, Printable painter, int index, boolean paperChanged) throws PrinterException {
double paperHeight = pageFormat.getPaper().getHeight();
double paperWidth = pageFormat.getPaper().getWidth();
int pageNumber = index + 1;
/* Place an initial gstate on to our gstate stack.
* It will have the default PostScript gstate
* attributes.
*/
mGStateStack = new ArrayList();
mGStateStack.add(new GState());
mPSStream.println(PAGE_COMMENT + pageNumber + " " + pageNumber);
/* Check current page's pageFormat against the previous pageFormat,
*/
if (index > 0 && paperChanged) {
mPSStream.print("<< /PageSize [" + paperWidth + " " + paperHeight + "]");
final PrintService pservice = getPrintService();
Boolean isPS = (Boolean) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
try {
Class psClass = Class.forName("sun.print.IPPPrintService");
if (psClass.isInstance(pservice)) {
Method isPSMethod = psClass.getMethod("isPostscript", (Class[]) null);
return (Boolean) isPSMethod.invoke(pservice, (Object[]) null);
}
} catch (Throwable t) {
}
return Boolean.TRUE;
}
});
if (isPS) {
mPSStream.print(" /DeferredMediaSelection true");
}
mPSStream.println(" >> setpagedevice");
}
mPSStream.println(PAGE_SAVE);
mPSStream.println(paperHeight + COORD_PREP);
}
use of javax.print.PrintService in project jdk8u_jdk by JetBrains.
the class PrintJob2D method updateAttributes.
private void updateAttributes() {
Copies c = (Copies) attributes.get(Copies.class);
jobAttributes.setCopies(c.getValue());
SunPageSelection sel = (SunPageSelection) attributes.get(SunPageSelection.class);
if (sel == SunPageSelection.RANGE) {
jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
} else if (sel == SunPageSelection.SELECTION) {
jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
} else {
jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
}
Destination dest = (Destination) attributes.get(Destination.class);
if (dest != null) {
jobAttributes.setDestination(DestinationType.FILE);
jobAttributes.setFileName(dest.getURI().getPath());
} else {
jobAttributes.setDestination(DestinationType.PRINTER);
}
PrintService serv = printerJob.getPrintService();
if (serv != null) {
jobAttributes.setPrinter(serv.getName());
}
PageRanges range = (PageRanges) attributes.get(PageRanges.class);
int[][] members = range.getMembers();
jobAttributes.setPageRanges(members);
SheetCollate collation = (SheetCollate) attributes.get(SheetCollate.class);
if (collation == SheetCollate.COLLATED) {
jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
} else {
jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
}
Sides sides = (Sides) attributes.get(Sides.class);
if (sides == Sides.TWO_SIDED_LONG_EDGE) {
jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
} else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
} else {
jobAttributes.setSides(SidesType.ONE_SIDED);
}
// PageAttributes
Chromaticity color = (Chromaticity) attributes.get(Chromaticity.class);
if (color == Chromaticity.COLOR) {
pageAttributes.setColor(ColorType.COLOR);
} else {
pageAttributes.setColor(ColorType.MONOCHROME);
}
OrientationRequested orient = (OrientationRequested) attributes.get(OrientationRequested.class);
if (orient == OrientationRequested.LANDSCAPE) {
pageAttributes.setOrientationRequested(OrientationRequestedType.LANDSCAPE);
} else {
pageAttributes.setOrientationRequested(OrientationRequestedType.PORTRAIT);
}
PrintQuality qual = (PrintQuality) attributes.get(PrintQuality.class);
if (qual == PrintQuality.DRAFT) {
pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
} else if (qual == PrintQuality.HIGH) {
pageAttributes.setPrintQuality(PrintQualityType.HIGH);
} else {
// NORMAL
pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
}
Media msn = (Media) attributes.get(Media.class);
if (msn != null && msn instanceof MediaSizeName) {
MediaType mType = unMapMedia((MediaSizeName) msn);
if (mType != null) {
pageAttributes.setMedia(mType);
}
}
debugPrintAttributes(false, false);
}
use of javax.print.PrintService in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method getPrintService.
/**
* Returns the service (printer) for this printer job.
* Implementations of this class which do not support print services
* may return null;
* @return the service for this printer job.
*
*/
public PrintService getPrintService() {
if (myService == null) {
PrintService svc = PrintServiceLookup.lookupDefaultPrintService();
if (svc != null && svc.isDocFlavorSupported(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
try {
setPrintService(svc);
myService = svc;
} catch (PrinterException e) {
}
}
if (myService == null) {
PrintService[] svcs = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
if (svcs.length > 0) {
try {
setPrintService(svcs[0]);
myService = svcs[0];
} catch (PrinterException e) {
}
}
}
}
return myService;
}
Aggregations