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


Java Paper类代码示例

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


Paper类属于java.awt.print包,在下文中一共展示了Paper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPageFormat

import java.awt.print.Paper; //导入依赖的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: actionPerformed

import java.awt.print.Paper; //导入依赖的package包/类
/**
 * 
 */
public void actionPerformed(ActionEvent e) {
  if (e.getSource() instanceof mxGraphComponent) {
    mxGraphComponent graphComponent = (mxGraphComponent) e.getSource();
    PrinterJob pj = PrinterJob.getPrinterJob();

    if (pj.printDialog()) {
      PageFormat pf = graphComponent.getPageFormat();
      Paper paper = new Paper();
      double margin = 36;
      paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
          paper.getHeight() - margin * 2);
      pf.setPaper(paper);
      pj.setPrintable(graphComponent, pf);

      try {
        pj.print();
      } catch (PrinterException e2) {
        System.out.println(e2);
      }
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:26,代码来源:EditorActions.java

示例3: getPageFormat

import java.awt.print.Paper; //导入依赖的package包/类
public PageFormat getPageFormat() {
    PrinterJob job = PrinterJob.getPrinterJob();

    if (myPageFormat == null) {
        myPageFormat = job.defaultPage();

        // restore
        myPageFormat.setOrientation(round(get(PAGE_ORIENTATION, PageFormat.PORTRAIT)));
        Paper paper = myPageFormat.getPaper();

        if (get(PAPER_WIDTH, null) != null && get(PAPER_HEIGHT, null) != null) {
            paper.setSize(get(PAPER_WIDTH, INCH), get(PAPER_HEIGHT, INCH));
        }
        if (get(AREA_X, null) != null && get(AREA_Y, null) != null && get(AREA_WIDTH, null) != null && get(AREA_HEIGHT, null) != null) {
            paper.setImageableArea(get(AREA_X, INCH), get(AREA_Y, INCH), get(AREA_WIDTH, INCH), get(AREA_HEIGHT, INCH));
        }
        myPageFormat.setPaper(paper);
    }
    return myPageFormat;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Config.java

示例4: printTest

import java.awt.print.Paper; //导入依赖的package包/类
private static void printTest() {
    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = pj.defaultPage();
    Paper paper = new Paper();
    double margin = 36; // half inch
    paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
            paper.getHeight() - margin * 2);
    pf.setPaper(paper);

    pj.setPrintable(new PrintTestLexmarkIQ(), pf);
    if (pj.printDialog()) {
        try {
            pj.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:PrintTestLexmarkIQ.java

示例5: testGetPageFormat

import java.awt.print.Paper; //导入依赖的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

示例6: showPageSetup

import java.awt.print.Paper; //导入依赖的package包/类
public boolean showPageSetup() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat oldFormat = getPageFormat();
    PageFormat newFormat = job.pageDialog(oldFormat);

    if (oldFormat == newFormat) {
        return false;
    }
    myPageFormat = newFormat;

    // save
    set(PAGE_ORIENTATION, myPageFormat.getOrientation());
    Paper paper = myPageFormat.getPaper();

    set(PAPER_WIDTH, paper.getWidth());
    set(PAPER_HEIGHT, paper.getHeight());

    set(AREA_X, paper.getImageableX());
    set(AREA_Y, paper.getImageableY());

    set(AREA_WIDTH, paper.getImageableWidth());
    set(AREA_HEIGHT, paper.getImageableHeight());

    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:Config.java

示例7: EPSPrinter

import java.awt.print.Paper; //导入依赖的package包/类
public EPSPrinter(Printable printable, String title,
                  PrintStream stream,
                  int x, int y, int wid, int hgt) {

    this.printable = printable;
    this.epsTitle = title;
    this.stream = stream;
    llx = x;
    lly = y;
    urx = llx+wid;
    ury = lly+hgt;
    // construct a PageFormat with zero margins representing the
    // exact bounds of the applet. ie construct a theoretical
    // paper which happens to exactly match applet panel size.
    Paper p = new Paper();
    p.setSize((double)wid, (double)hgt);
    p.setImageableArea(0.0,0.0, (double)wid, (double)hgt);
    pf = new PageFormat();
    pf.setPaper(p);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:PSPrinterJob.java

示例8: actionPerformed

import java.awt.print.Paper; //导入依赖的package包/类
/**
 * 
 */
public void actionPerformed(ActionEvent e)
{
	if (e.getSource() instanceof mxGraphComponent)
	{
		mxGraphComponent graphComponent = (mxGraphComponent) e
				.getSource();
		PrinterJob pj = PrinterJob.getPrinterJob();

		if (pj.printDialog())
		{
			PageFormat pf = graphComponent.getPageFormat();
			Paper paper = new Paper();
			double margin = 36;
			paper.setImageableArea(margin, margin, paper.getWidth()
					- margin * 2, paper.getHeight() - margin * 2);
			pf.setPaper(paper);
			pj.setPrintable(graphComponent, pf);

			try
			{
				pj.print();
			}
			catch (PrinterException e2)
			{
				System.out.println(e2);
			}
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:33,代码来源:EditorActions.java

示例9: doTest

import java.awt.print.Paper; //导入依赖的package包/类
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WrongPaperPrintingTest.java

示例10: main

import java.awt.print.Paper; //导入依赖的package包/类
public static void main(String args[]) {
    PageFormat pf;
    pf = (PageFormat) new PageFormat().clone();
    pf.getWidth();
    pf.getHeight();
    pf.getImageableX();
    pf.getImageableY();
    pf.getImageableWidth();
    pf.getImageableHeight();
    pf.getPaper();
    pf.setPaper(new Paper());
    pf.setOrientation(PageFormat.PORTRAIT);
    if (pf.getOrientation() != PageFormat.PORTRAIT)
        throw new RuntimeException("Changing Orientation did not result in a change: PageFormat.PORTRAIT");

    pf.setOrientation(PageFormat.LANDSCAPE);
    if (pf.getOrientation() != PageFormat.LANDSCAPE)
        throw new RuntimeException("Changing Orientation did not result in a change: PageFormat.LANDSCAPE");

    pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    if (pf.getOrientation() != PageFormat.REVERSE_LANDSCAPE)
        throw new RuntimeException("Changing Orientation did not result in a change: PageFormat.REVERSE_LANDSCAPE");

    pf.getOrientation();
    pf.getMatrix();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:HeadlessPageFormat.java

示例11: setPaperWidth

import java.awt.print.Paper; //导入依赖的package包/类
/**
 * Sets the width for this page. This also validates the imageable bounds of
 * the paper.
 */
public boolean setPaperWidth(double width) {
	if (width == pageFormat.getWidth())
		return false;

	double oldWidth = pageFormat.getWidth();
	Paper paper = pageFormat.getPaper();
	paper.setSize(width, paper.getHeight());
	pageFormat.setPaper(paper);
	firePropertyChange(PROPERTY_WIDTH, new Double(oldWidth), new Double(
			width));

	validateImageableBounds();

	return true;
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:20,代码来源:PrintLayout.java

示例12: setPaperHeight

import java.awt.print.Paper; //导入依赖的package包/类
/**
 * Sets the height for this page. This also validates the imageable bounds
 * of the paper.
 */
public boolean setPaperHeight(double height) {
	if (height == pageFormat.getHeight())
		return false;

	double oldHeight = pageFormat.getHeight();
	Paper paper = pageFormat.getPaper();
	paper.setSize(paper.getWidth(), height);
	pageFormat.setPaper(paper);
	firePropertyChange(PROPERTY_WIDTH, new Double(oldHeight), new Double(
			height));

	validateImageableBounds();

	return true;
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:20,代码来源:PrintLayout.java

示例13: getPageFormat

import java.awt.print.Paper; //导入依赖的package包/类
private PageFormat getPageFormat() {
	final double mmToDots = 72 / 2.54;

	SettingsModel settings = Controller.get().getConfig();
	Paper p = new Paper();
	p.setSize(
		settings.getValue("PageWidht", 21.0 * mmToDots),
		settings.getValue("PageHeight", 29.7 * mmToDots)
	);
	p.setImageableArea(
		settings.getValue("PageImageableX", 2.5 * mmToDots),
		settings.getValue("PageImageableY", 1.0 * mmToDots),
		settings.getValue("PageImageableWidth", 17.5 * mmToDots),
		settings.getValue("PageImageableHeight", 27.7 * mmToDots)
	);
	PageFormat pf = new PageFormat();
	pf.setPaper(p);
	pf.setOrientation(settings.getValue("PageOrientation", PageFormat.PORTRAIT));
	return pf;
}
 
开发者ID:SmallLars,项目名称:esadb,代码行数:21,代码来源:GUI.java

示例14: actionPerformed

import java.awt.print.Paper; //导入依赖的package包/类
public void actionPerformed(ActionEvent e)
{
	PrinterJob pj = PrinterJob.getPrinterJob();

	if (pj.printDialog())
	{
		PageFormat pf = frame.getPageFormat();
		Paper paper = new Paper();
		double margin = 36;
		paper.setImageableArea(margin, margin, paper.getWidth()	- margin * 2, paper.getHeight() - margin * 2);
		pf.setPaper(paper);
		pj.setPrintable(textArea, pf);

		try
		{
			// Don't delete the float cast! If done, deriveFont will change the style instead of the font size.
			textArea.setFont(textArea.getFont().deriveFont((float)(textArea.getFont().getSize() - 5)));
			pj.print();
		} catch (PrinterException e2)
		{
			JOptionPane.showMessageDialog(frame, "Error de impresión", "Error", JOptionPane.ERROR_MESSAGE);
		}
		textArea.setFont(textArea.getFont().deriveFont((float)(textArea.getFont().getSize() + 5)));
	}
}
 
开发者ID:pedromateo,项目名称:tug_qt_unit_testing_fw,代码行数:26,代码来源:EditImplActions.java

示例15: getPageFormat

import java.awt.print.Paper; //导入依赖的package包/类
/**
 * Gets a page format instance that describes this page's geometry in terms
 * of the Java print API.
 * 
 * @return A throwaway PageFormat object that describes this page's current
 *         geometry. Changes to the returned PageFormat object will not
 *         affect this page in any way.
 */
public PageFormat getPageFormat() {
    PageFormat pageFormat = new PageFormat();
    pageFormat.setOrientation(getOrientation().getPrintApiCode());
    Paper paper = new Paper();
    
    if (getOrientation() == PageOrientation.PORTRAIT) {
        paper.setSize(getWidth(), getHeight());
    } else {
        paper.setSize(getHeight(), getWidth());
    }

    // the imageable area on the page format we return determines the clipping
    // region for the print API, so we always want to set it as big as possible
    // regardless of our own margin guides
    paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());

    pageFormat.setPaper(paper);
    
    return pageFormat;
}
 
开发者ID:SQLPower,项目名称:wabit,代码行数:29,代码来源:Page.java


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