use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.
the class ImageableAreaTest method printWithCustomImageareaSize.
private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(JTable.PrintMode.NORMAL, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}
use of javax.print.attribute.standard.MediaPrintableArea in project adempiere by adempiere.
the class CPaper method setPrintRequestAttributeSet.
// getPrintRequestAttributes
/**
* Set Print Request Attributes
* @param prats PrintRequestAttributeSet
*/
public void setPrintRequestAttributeSet(PrintRequestAttributeSet prats) {
boolean landscape = m_landscape;
MediaSize ms = m_mediaSize;
MediaPrintableArea area = getMediaPrintableArea();
Attribute[] atts = prats.toArray();
for (int i = 0; i < atts.length; i++) {
if (atts[i] instanceof OrientationRequested) {
OrientationRequested or = (OrientationRequested) atts[i];
if (or.equals(OrientationRequested.PORTRAIT))
landscape = false;
else
landscape = true;
} else if (atts[i] instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName) atts[i];
ms = MediaSize.getMediaSizeForName(msn);
} else if (atts[i] instanceof MediaPrintableArea) {
area = (MediaPrintableArea) atts[i];
} else
// unhandeled
System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
}
//
setMediaSize(ms, landscape);
setMediaPrintableArea(area);
}
use of javax.print.attribute.standard.MediaPrintableArea in project jgnash by ccavanaugh.
the class PrintableCheckLayout method getPageFormat.
public PageFormat getPageFormat() {
PrintRequestAttributeSet printAttributes = checkLayout.getPrintAttributes();
if (pageFormat == null) {
// create a default pageFormat
PageFormat format = getPrinterJob().defaultPage();
Paper paper = format.getPaper();
MediaSizeName media = (MediaSizeName) printAttributes.get(Media.class);
MediaSize ms = MediaSize.getMediaSizeForName(media);
MediaPrintableArea ma = (MediaPrintableArea) printAttributes.get(MediaPrintableArea.class);
if (ma != null) {
int INCH = MediaPrintableArea.INCH;
paper.setImageableArea((ma.getX(INCH) * 72), (ma.getY(INCH) * 72), (ma.getWidth(INCH) * 72), (ma.getHeight(INCH) * 72));
}
if (ms != null) {
paper.setSize((ms.getX(Size2DSyntax.INCH) * 72), (ms.getY(Size2DSyntax.INCH) * 72));
}
format.setPaper(paper);
OrientationRequested or = (OrientationRequested) printAttributes.get(OrientationRequested.class);
if (or != null) {
if (or == OrientationRequested.LANDSCAPE) {
format.setOrientation(PageFormat.LANDSCAPE);
} else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
} else if (or == OrientationRequested.PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
} else if (or == OrientationRequested.REVERSE_PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
}
}
pageFormat = format;
}
return pageFormat;
}
use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.
the class CUPSPrinter method initMedia.
/**
* Initialize media by translating PPD info to PrintService attributes.
*/
private synchronized void initMedia() {
if (initialized) {
return;
} else {
initialized = true;
}
if (pageSizes == null) {
return;
}
cupsMediaPrintables = new MediaPrintableArea[nPageSizes];
cupsMediaSNames = new MediaSizeName[nPageSizes];
cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes];
CustomMediaSizeName msn;
MediaPrintableArea mpa;
float length, width, x, y, w, h;
// initialize names and printables
for (int i = 0; i < nPageSizes; i++) {
// media width and length
width = (float) (pageSizes[i * 6] / PRINTER_DPI);
length = (float) (pageSizes[i * 6 + 1] / PRINTER_DPI);
// media printable area
x = (float) (pageSizes[i * 6 + 2] / PRINTER_DPI);
h = (float) (pageSizes[i * 6 + 3] / PRINTER_DPI);
w = (float) (pageSizes[i * 6 + 4] / PRINTER_DPI);
y = (float) (pageSizes[i * 6 + 5] / PRINTER_DPI);
msn = new CustomMediaSizeName(media[i * 2], media[i * 2 + 1], width, length);
// add to list of standard MediaSizeNames
if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) {
// add custom if no matching standard media
cupsMediaSNames[i] = msn;
// add this new custom msn to MediaSize array
if ((width > 0.0) && (length > 0.0)) {
try {
new MediaSize(width, length, Size2DSyntax.INCH, msn);
} catch (IllegalArgumentException e) {
/* PDF printer in Linux for Ledger paper causes
"IllegalArgumentException: X dimension > Y dimension".
We rotate based on IPP spec. */
new MediaSize(length, width, Size2DSyntax.INCH, msn);
}
}
}
// add to list of custom MediaSizeName
// for internal use of IPPPrintService
cupsCustomMediaSNames[i] = msn;
mpa = null;
try {
mpa = new MediaPrintableArea(x, y, w, h, MediaPrintableArea.INCH);
} catch (IllegalArgumentException e) {
if (width > 0 && length > 0) {
mpa = new MediaPrintableArea(0, 0, width, length, MediaPrintableArea.INCH);
}
}
cupsMediaPrintables[i] = mpa;
}
// initialize trays
cupsMediaTrays = new MediaTray[nTrays];
MediaTray mt;
for (int i = 0; i < nTrays; i++) {
mt = new CustomMediaTray(media[(nPageSizes + i) * 2], media[(nPageSizes + i) * 2 + 1]);
cupsMediaTrays[i] = mt;
}
}
use of javax.print.attribute.standard.MediaPrintableArea in project jdk8u_jdk by JetBrains.
the class UnixPrintService method getAllPrintableAreas.
private MediaPrintableArea[] getAllPrintableAreas() {
if (mpas == null) {
Media[] media = (Media[]) getSupportedAttributeValues(Media.class, null, null);
mpas = new MediaPrintableArea[media.length];
for (int i = 0; i < mpas.length; i++) {
if (media[i] instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName) media[i];
MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
if (mediaSize == null) {
mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class);
} else {
mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH) - 0.5f, mediaSize.getY(MediaSize.INCH) - 0.5f, MediaSize.INCH);
}
}
}
}
MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
return mpasCopy;
}
Aggregations