use of javax.print.attribute.standard.MediaSizeName 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.MediaSizeName 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.MediaSizeName in project camel by apache.
the class PrinterConfiguration method assignMediaSize.
private MediaSizeName assignMediaSize(String size) {
MediaSizeAssigner mediaSizeAssigner = new MediaSizeAssigner();
MediaSizeName answer;
if (size == null) {
// default to NA letter if no size configured
answer = MediaSizeName.NA_LETTER;
} else if (size.toLowerCase().startsWith("iso")) {
answer = mediaSizeAssigner.selectMediaSizeNameISO(size);
} else if (size.startsWith("jis")) {
answer = mediaSizeAssigner.selectMediaSizeNameJIS(size);
} else if (size.startsWith("na")) {
answer = mediaSizeAssigner.selectMediaSizeNameNA(size);
} else {
answer = mediaSizeAssigner.selectMediaSizeNameOther(size);
}
return answer;
}
use of javax.print.attribute.standard.MediaSizeName 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.MediaSizeName 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