當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。