本文整理汇总了Java中java.awt.print.PageFormat.getPaper方法的典型用法代码示例。如果您正苦于以下问题:Java PageFormat.getPaper方法的具体用法?Java PageFormat.getPaper怎么用?Java PageFormat.getPaper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.print.PageFormat
的用法示例。
在下文中一共展示了PageFormat.getPaper方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Get an instance of {@link java.awt.print.PageFormat}.
* @param pj {@link java.awt.print.PrinterJob} which is
* associated with the default printer.
* @return an instance of <code>PageFormat</code> that describes the size and
* orientation of a page to be printed.
*/
public static PageFormat getPageFormat(PrinterJob pj) {
PageFormat pageFormat = null;
pageFormat = pj.defaultPage();
Paper p = pageFormat.getPaper();
int pageOrientation = getPreferences().getInt(PROP_PAGE_ORIENTATION, pageFormat.getOrientation());
double paperWidth = getPreferences().getDouble(PROP_PAGE_WIDTH, p.getWidth());
double paperHeight = getPreferences().getDouble(PROP_PAGE_HEIGHT, p.getHeight());
double iaWidth = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_WIDTH, p.getImageableWidth());
double iaHeight = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_HEIGHT, p.getImageableHeight());
double iaX = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_X, p.getImageableX());
double iaY = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_Y, p.getImageableY());
pageFormat.setOrientation(pageOrientation);
p.setSize(paperWidth, paperHeight);
p.setImageableArea(iaX, iaY, iaWidth, iaHeight);
pageFormat.setPaper(p);
return pageFormat;
}
示例2: testGetPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public void testGetPageFormat() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat expResult = PrintPreferences.getPageFormat(pj);
PrintPreferences.setPageFormat(expResult);
PageFormat result = PrintPreferences.getPageFormat(pj);
assertEquals(expResult.getHeight(), result.getHeight());
assertEquals(expResult.getWidth(), result.getWidth());
assertEquals(expResult.getOrientation(), result.getOrientation());
assertEquals(expResult.getPaper().getHeight(), result.getPaper().getHeight());
assertEquals(expResult.getPaper().getWidth(), result.getPaper().getWidth());
assertEquals(expResult.getPaper().getImageableHeight(), result.getPaper().getImageableHeight());
assertEquals(expResult.getPaper().getImageableWidth(), result.getPaper().getImageableWidth());
assertEquals(expResult.getPaper().getImageableX(), result.getPaper().getImageableX());
assertEquals(expResult.getPaper().getImageableY(), result.getPaper().getImageableY());
double w = expResult.getPaper().getWidth() + 10;
double h = expResult.getPaper().getHeight() + 10;
Paper p = expResult.getPaper();
double ix = p.getImageableX() + 10;
double iy = p.getImageableY() + 10;
double iw = p.getImageableWidth() + 10;
double ih = p.getImageableHeight() + 10;
p.setImageableArea(ix, iy, iw, ih);
p.setSize(w, h);
expResult.setPaper(p);
PrintPreferences.setPageFormat(expResult);
assertEquals(h, PrintPreferences.getPageFormat(pj).getHeight());
assertEquals(w, PrintPreferences.getPageFormat(pj).getWidth());
assertEquals(ix, PrintPreferences.getPageFormat(pj).getPaper().getImageableX());
assertEquals(iy, PrintPreferences.getPageFormat(pj).getPaper().getImageableY());
assertEquals(iw, PrintPreferences.getPageFormat(pj).getPaper().getImageableWidth());
assertEquals(ih, PrintPreferences.getPageFormat(pj).getPaper().getImageableHeight());
expResult.setOrientation(PageFormat.REVERSE_LANDSCAPE);
PrintPreferences.setPageFormat(expResult);
assertEquals(PageFormat.REVERSE_LANDSCAPE, PrintPreferences.getPageFormat(pj).getOrientation());
}
示例3: setPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public static void setPageFormat(String name, PageFormat pageFormat) {
Properties properties = getProperties(name);
switch (pageFormat.getOrientation()) {
case PageFormat.LANDSCAPE:
properties.setProperty(ORIENTATION, LANDSCAPE);
break;
case PageFormat.PORTRAIT:
properties.setProperty(ORIENTATION, PORTRAIT);
break;
case PageFormat.REVERSE_LANDSCAPE:
properties.setProperty(ORIENTATION, REVERSE_LANDSCAPE);
break;
default:
properties.setProperty(ORIENTATION, "EMPTY");
}
;
final Paper paper = pageFormat.getPaper();
properties.setProperty(PAPER_IMAGEABLE_HEIGHT, Double.toString(paper
.getImageableHeight()));
properties.setProperty(PAPER_IMAGEABLE_WIDTH, Double.toString(paper
.getImageableWidth()));
properties.setProperty(PAPER_IMAGEABLE_X, Double.toString(paper
.getImageableX()));
properties.setProperty(PAPER_IMAGEABLE_Y, Double.toString(paper
.getImageableY()));
properties
.setProperty(PAPER_HEIGHT, Double.toString(paper.getHeight()));
properties.setProperty(PAPER_WIDTH, Double.toString(paper.getWidth()));
}
示例4: PolylinePrintingTest
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public PolylinePrintingTest() throws PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
p.setImageableArea(0,0,p.getWidth(), p.getHeight());
pf.setPaper(p);
job.setPrintable(this, pf);
if (job.printDialog()) {
job.print();
}
}
示例5: getPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public static PageFormat getPageFormat(String name, PageFormat pageFormat) {
Properties properties = getProperties(name);
if (properties == null)
return pageFormat;
final String orientation = properties.getProperty(ORIENTATION);
if (LANDSCAPE.equals(orientation))
pageFormat.setOrientation(PageFormat.LANDSCAPE);
else if (PORTRAIT.equals(orientation))
pageFormat.setOrientation(PageFormat.PORTRAIT);
else if (REVERSE_LANDSCAPE.equals(orientation))
pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
String s = properties.getProperty(PAPER_IMAGEABLE_HEIGHT);
if (s == null)
return pageFormat;
double iHeight = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_WIDTH);
if (s == null)
return pageFormat;
double iWidth = Double.parseDouble(s);
s = properties.getProperty(PAPER_HEIGHT);
if (s == null)
return pageFormat;
double height = Double.parseDouble(s);
s = properties.getProperty(PAPER_WIDTH);
if (s == null)
return pageFormat;
double width = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_X);
if (s == null)
return pageFormat;
final double x = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_Y);
if (s == null)
return pageFormat;
final double y = Double.parseDouble(s);
final Paper paper = pageFormat.getPaper();
paper.setImageableArea(x, y, iWidth, iHeight);
paper.setSize(width, height);
pageFormat.setPaper(paper);
return pageFormat;
}
示例6: patchMedia
import java.awt.print.PageFormat; //导入方法依赖的package包/类
private Pageable patchMedia( Pageable pageable ){
/* OpenBook is used internally only when app uses Printable.
* This is the case when we use the values from the attribute set.
*/
Media media = (Media)reqAttrSet.get(Media.class);
OrientationRequested orientReq = (OrientationRequested)reqAttrSet.get(OrientationRequested.class);
MediaPrintableArea mpa = (MediaPrintableArea)reqAttrSet.get(MediaPrintableArea.class);
if ((orientReq != null || media != null || mpa != null) && pageable instanceof OpenBook) {
/* We could almost(!) use PrinterJob.getPageFormat() except
* here we need to start with the PageFormat from the OpenBook :
*/
Printable printable = pageable.getPrintable(0);
PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
Paper paper = pf.getPaper();
/* If there's a media but no media printable area, we can try
* to retrieve the default value for mpa and use that.
*/
if (mpa == null && media != null && service.isAttributeCategorySupported(MediaPrintableArea.class)) {
Object mpaVals = service. getSupportedAttributeValues(MediaPrintableArea.class, null, reqAttrSet);
if (mpaVals instanceof MediaPrintableArea[] && ((MediaPrintableArea[])mpaVals).length > 0) {
mpa = ((MediaPrintableArea[])mpaVals)[0];
}
}
if (isSupportedValue(orientReq, reqAttrSet) || (!fidelity && orientReq != null)) {
int orient;
if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
orient = PageFormat.REVERSE_LANDSCAPE;
} else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
orient = PageFormat.LANDSCAPE;
} else {
orient = PageFormat.PORTRAIT;
}
pf.setOrientation(orient);
}
if (isSupportedValue(media, reqAttrSet) || (!fidelity && media != null)) {
if (media instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName)media;
MediaSize msz = MediaSize.getMediaSizeForName(msn);
if (msz != null) {
float paperWid = msz.getX(MediaSize.INCH) * 72.0f;
float paperHgt = msz.getY(MediaSize.INCH) * 72.0f;
paper.setSize(paperWid, paperHgt);
if (mpa == null) {
paper.setImageableArea(72.0, 72.0, paperWid-144.0, paperHgt-144.0);
}
}
}
}
if (isSupportedValue(mpa, reqAttrSet) || (!fidelity && mpa != null)) {
float [] printableArea = mpa.getPrintableArea(MediaPrintableArea.INCH);
for (int i=0; i < printableArea.length; i++) {
printableArea[i] = printableArea[i]*72.0f;
}
paper.setImageableArea(printableArea[0], printableArea[1], printableArea[2], printableArea[3]);
}
pf.setPaper(paper);
pf = validatePage(pf);
return new OpenBook(pf, printable);
}
return pageable;
}
示例7: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
int ix = (int)pf.getImageableX();
int iy = (int)pf.getImageableY();
int iw = (int)pf.getImageableWidth();
int ih = (int)pf.getImageableHeight();
System.out.println("ix="+ix+" iy="+iy+" iw="+iw+" ih="+ih);
if ((ix < 0) || (iy < 0)) {
throw new RuntimeException("Imageable x or y is a negative value.");
}
Paper paper = pf.getPaper();
int wid = (int)paper.getWidth();
int hgt = (int)paper.getHeight();
System.out.println("wid="+wid+" hgt="+hgt);
/*
* If imageable width/height is -ve, then print was done with 1" margin
* e.g. ix=72 iy=72 iw=451 ih=697 and paper wid=595
* but with fix, we get print with hardware margin e.g.
* ix=12, iy=12, iw=571, ih=817
*/
if ((wid - iw > 72) || (hgt - ih > 72)) {
throw new RuntimeException("Imageable width or height is negative value");
}
if ((ix+iw > wid) || (iy+ih > hgt)) {
throw new RuntimeException("Printable width or height "
+ "exceeds paper width or height.");
}
// runtime checking to see if the margins/printable area
// correspond to the entire size of the paper, for now, make it pass
// as for linux, the hwmargin is not taken into account - bug6574279
if (ix == 0 && iy == 0 && (ix+iw == wid) && (iy+ih == hgt)) {
return PAGE_EXISTS;
}
Graphics2D g2d = (Graphics2D)g;
g2d.translate(ix, iy);
g2d.setColor(Color.black);
g2d.drawRect(1, 1, iw-2, ih-2);
return PAGE_EXISTS;
}