当前位置: 首页>>代码示例>>Java>>正文


Java PageFormat.setOrientation方法代码示例

本文整理汇总了Java中java.awt.print.PageFormat.setOrientation方法的典型用法代码示例。如果您正苦于以下问题:Java PageFormat.setOrientation方法的具体用法?Java PageFormat.setOrientation怎么用?Java PageFormat.setOrientation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.print.PageFormat的用法示例。


在下文中一共展示了PageFormat.setOrientation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:PrintPreferences.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:PrintPreferencesTest.java

示例3: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override public int print(Graphics default_graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
	if(pageIndex!=0)
		return NO_SUCH_PAGE;
	pageFormat.setOrientation(PageFormat.LANDSCAPE);

	Color foreground = this.foreground, background = this.background, grid = this.grid;
	this.foreground = Color.BLACK; this.background = Color.WHITE; this.grid = Color.LIGHT_GRAY;

	Graphics2D graphics = (Graphics2D) default_graphics;
	graphics.translate(pageFormat.getImageableX(),
			pageFormat.getImageableY());
	this.paint(graphics);
	Thread.yield(); //yield shortly that the graphics are printed properly

	this.foreground = foreground; this.background = background; this.grid = grid;
	return PAGE_EXISTS;
}
 
开发者ID:kristian,项目名称:JDigitalSimulator,代码行数:18,代码来源:SimulationOscilloscope.java

示例4: printableJob

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:UnixPrintJob.java

示例5: initialize

import java.awt.print.PageFormat; //导入方法依赖的package包/类
private void initialize(byte[] pdfContent, String jobName,String nomeImpressora) throws IOException, PrinterException {
    ByteBuffer bb = ByteBuffer.wrap(pdfContent);

    PDFFile pdfFile = new PDFFile(bb);
    PDFPrintPage pages = new PDFPrintPage(pdfFile);

    PrintService[] pservices = PrinterJob.lookupPrintServices();

    System.out.println(pservices.length);
    if (pservices.length > 0) {
        for (PrintService ps : pservices) {
            System.out.println("Impressora Encontrada: " + ps.getName());

            if (ps.getName().contains(nomeImpressora)) {
                System.out.println("Impressora Selecionada: " + nomeImpressora);
                impressora = ps;
                break;
            }
        }
    }
    if (impressora != null) {
        pjob = PrinterJob.getPrinterJob();
        pjob.setPrintService(impressora);

        PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

        pjob.setJobName(jobName);
        Book book = new Book();
        book.append(pages, pf, pdfFile.getNumPages());
        pjob.setPageable(book);

      
        Paper paper = new Paper();
        paper.setSize(getWidth, getHeight);
        paper.setImageableArea(margin, (int) margin / 4, getWidth - margin * 2, getHeight - margin * 2);
        //paper.setImageableArea(margin,margin, paper.getWidth()-margin*2,paper.getHeight()-margin*2);
        pf.setOrientation(orientacao);
        pf.setPaper(paper);
    }
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:41,代码来源:PrintPdf.java

示例6: getPageFormat

import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException 
{
	PageFormat p = new PageFormat();
	Dimension current = getMinimumSize();
	if (current.width > current.height)
		p.setOrientation(PageFormat.LANDSCAPE);
	else
		p.setOrientation(PageFormat.PORTRAIT);
	return p;
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:12,代码来源:BracketPane.java

示例7: 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;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:45,代码来源:Options.java

示例8: 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:69,代码来源:Win32PrintJob.java


注:本文中的java.awt.print.PageFormat.setOrientation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。