use of javax.print.attribute.standard.MediaSize in project jdk8u_jdk by JetBrains.
the class MediaMappingsTest method main.
public static void main(String[] args) {
MediaSize sizeA = MediaSize.getMediaSizeForName(MediaSizeName.A);
new MediaSize(1.0f, 2.0f, MediaSize.MM, MediaSizeName.A);
if (!sizeA.equals(MediaSize.getMediaSizeForName(MediaSizeName.A))) {
throw new RuntimeException("mapping changed");
}
MediaSize sizeB = MediaSize.getMediaSizeForName(MediaSizeName.B);
new MediaSize(1, 2, MediaSize.MM, MediaSizeName.B);
if (!sizeB.equals(MediaSize.getMediaSizeForName(MediaSizeName.B))) {
throw new RuntimeException("mapping changed");
}
}
use of javax.print.attribute.standard.MediaSize in project adempiere by adempiere.
the class MPrintPaper method getMediaSize.
/**************************************************************************
* Get Media Size.
* The search is hard coded as the javax.print.MediaSize* info is private
* @return MediaSize from Code
*/
public MediaSize getMediaSize() {
if (m_mediaSize != null)
return m_mediaSize;
//
String nameCode = getCode();
if (nameCode != null) {
// Get Name
MediaSizeName nameMedia = null;
CMediaSizeName msn = new CMediaSizeName(4);
String[] names = msn.getStringTable();
for (int i = 0; i < names.length; i++) {
String name = names[i];
if (name.equalsIgnoreCase(nameCode)) {
nameMedia = (MediaSizeName) msn.getEnumValueTable()[i];
log.finer("Name=" + nameMedia);
break;
}
}
if (nameMedia != null) {
m_mediaSize = MediaSize.getMediaSizeForName(nameMedia);
log.fine("Name->Size=" + m_mediaSize);
}
}
// Create New Media Size
if (m_mediaSize == null) {
float x = getSizeX().floatValue();
float y = getSizeY().floatValue();
if (x > 0 && y > 0) {
m_mediaSize = new MediaSize(x, y, getUnitsInt(), MediaSizeName.A);
log.fine("Size=" + m_mediaSize);
}
}
// Fallback
if (m_mediaSize == null)
m_mediaSize = getMediaSizeDefault();
return m_mediaSize;
}
use of javax.print.attribute.standard.MediaSize 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.MediaSize in project jgnash by ccavanaugh.
the class ReportPrintFactory method getDefaultPage.
/**
* Returns the default paper size for a report
*
* @return page format
*/
private static PageFormat getDefaultPage() {
/* A4 is the assumed default */
MediaSize defaultMediaSize = MediaSize.ISO.A4;
/* US and Canada use letter size as the default */
Locale[] letterLocales = new Locale[] { Locale.US, Locale.CANADA, Locale.CANADA_FRENCH };
if (Arrays.asList(letterLocales).contains(Locale.getDefault())) {
defaultMediaSize = MediaSize.NA.LETTER;
}
/* Create the default paper size with a default margin */
Paper paper = new Paper();
int width = (int) (defaultMediaSize.getX(MediaSize.INCH) / (1f / 72f));
int height = (int) (defaultMediaSize.getY(MediaSize.INCH) / (1f / 72f));
paper.setSize(width, height);
paper.setImageableArea(DEFAULT_MARGIN, DEFAULT_MARGIN, width - (2 * DEFAULT_MARGIN), height - (2 * DEFAULT_MARGIN));
PageFormat format = new PageFormat();
format.setPaper(paper);
/* if a default printer is found, validate the page */
PrintService[] services = PrinterJob.lookupPrintServices();
if (services.length != 0) {
// no printers found on the system.
format = PrinterJob.getPrinterJob().validatePage(format);
}
return format;
}
use of javax.print.attribute.standard.MediaSize 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;
}
Aggregations