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


Java PageFormat类代码示例

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


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

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

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Set the print size to fit a page in the verticle direction.
 * The horizontal is scaled equally but no garuntees are made on the page fit.
 */
private void scaleToFitY() {
    PageFormat format = getPageFormat();
    Rectangle componentBounds = scene.getBounds();

    if (componentBounds.height == 0) {
        return;
    }

    double scaleY = format.getImageableHeight() / componentBounds.height;
    double scaleX = scaleY;
    if (scaleY < 1) {
        setSize((float) (componentBounds.width * scaleX), (float) format.getImageableHeight());
        setScaledSize(scaleX, scaleY);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:PageableScene.java

示例4: getPageFormat

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

示例5: PrintPreviewPanel

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Creates a preview panel for the specified {@link PrintableComponent}.
 *
 * @param comp
 *            the {@link PrintableComponent} the preview panel should be created for.
 */
public PrintPreviewPanel(PrintableComponent comp, PageFormat pageFormat) {
	this.printer = new ComponentPrinter(comp);
	this.cardLayout = new CardLayout();
	this.pageFormat = pageFormat;
	setLayout(cardLayout);

	GridBagConstraints gbc = new GridBagConstraints();
	gbc.weightx = 1;
	gbc.weighty = 1;
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.CENTER;

	landscapePanel = new JPanel(new GridBagLayout());
	landscapePreview = new ComponentPreviewPanel(Orientation.LANDSCAPE);
	landscapePanel.add(landscapePreview, gbc);
	add(landscapePanel, Orientation.LANDSCAPE.toString());

	portraitPanel = new JPanel(new GridBagLayout());
	portraitPreview = new ComponentPreviewPanel(Orientation.PORTRAIT);
	portraitPanel.add(portraitPreview, gbc);
	add(portraitPanel, Orientation.PORTRAIT.toString());

	// set page format
	setPageFormat(pageFormat);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:32,代码来源:PrintPreviewPanel.java

示例6: setPageFormat

import java.awt.print.PageFormat; //导入依赖的package包/类
public void setPageFormat(PageFormat pageFormat) {
	this.pageFormat = pageFormat;
	remove(landscapePanel);
	remove(portraitPanel);
	add(landscapePanel, Orientation.LANDSCAPE.toString());
	add(portraitPanel, Orientation.PORTRAIT.toString());
	if (pageFormat.getOrientation() == PageFormat.LANDSCAPE) {
		cardLayout.show(this, Orientation.LANDSCAPE.toString());
	} else {
		cardLayout.show(this, Orientation.PORTRAIT.toString());
	}
	repaint();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:PrintPreviewPanel.java

示例7: print

import java.awt.print.PageFormat; //导入依赖的package包/类
public int print(final Graphics graphics,
                 final PageFormat pageFormat, final int pageIndex)
        throws PrinterException {

    final int retVal =
        printDelegatee.print(graphics, pageFormat, pageIndex);
    if (retVal != NO_SUCH_PAGE && !isAborted()) {
        if (SwingUtilities.isEventDispatchThread()) {
            updateStatusOnEDT(pageIndex);
        } else {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    updateStatusOnEDT(pageIndex);
                }
            });
        }
    }
    return retVal;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:PrintingStatus.java

示例8: print

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Print the plot to a printer, represented by the specified graphics
 * object.
 *
 * @param graphics The context into which the page is drawn.
 * @param format The size and orientation of the page being drawn.
 * @param index The zero based index of the page to be drawn.
 * @return PAGE_EXISTS if the page is rendered successfully, or
 * NO_SUCH_PAGE if pageIndex specifies a non-existent page.
 * @exception PrinterException If the print job is terminated.
 */

public synchronized int print(Graphics graphics, PageFormat format,
        int index) throws PrinterException {
    if (graphics == null) return Printable.NO_SUCH_PAGE;
    // We only print on one page.
    if (index >= 1) {
        return Printable.NO_SUCH_PAGE;
    }
    Graphics2D graphics2D = (Graphics2D) graphics;
    // Scale the printout to fit the pages.
    // Contributed by Laurent ETUR, Schlumberger Riboud Product Center
    double scalex = format.getImageableWidth() / (double) getWidth();
    double scaley = format.getImageableHeight() / (double) getHeight();
    double scale = Math.min(scalex, scaley);
    graphics2D.translate((int)format.getImageableX(),
            (int)format.getImageableY());
    graphics2D.scale(scale, scale);
    _drawPlot(graphics, true);
    return Printable.PAGE_EXISTS;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:32,代码来源:PlotBox.java

示例9: print

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Prints the chart on a single page.
 *
 * @param g  the graphics context.
 * @param pf  the page format to use.
 * @param pageIndex  the index of the page. If not <code>0</code>, nothing 
 *                   gets print.
 *
 * @return The result of printing.
 */
public int print(Graphics g, PageFormat pf, int pageIndex) {

    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    Graphics2D g2 = (Graphics2D) g;
    double x = pf.getImageableX();
    double y = pf.getImageableY();
    double w = pf.getImageableWidth();
    double h = pf.getImageableHeight();
    this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, 
            null);
    return PAGE_EXISTS;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:ChartPanel.java

示例10: getDefaultPrintableArea

import java.awt.print.PageFormat; //导入依赖的package包/类
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
    if (w >= 72.0 * 6.0) {
        ix = 72.0;
        iw = w - 2 * 72.0;
    } else {
        ix = w / 6.0;
        iw = w * 0.75;
    }
    if (h >= 72.0 * 6.0) {
        iy = 72.0;
        ih = h - 2 * 72.0;
    } else {
        iy = h / 6.0;
        ih = h * 0.75;
    }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:RasterPrinterJob.java

示例11: actionPerformed

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

		if (format != null)
		{
			graphComponent.setPageFormat(format);
			graphComponent.zoomAndCenter();
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:21,代码来源:EditorActions.java

示例12: getDefaultPrintableArea

import java.awt.print.PageFormat; //导入依赖的package包/类
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:RasterPrinterJob.java

示例13: printTest

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

示例14: scaleToFit

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Adjusts the scaling factors in both the horizontal and vertical directions
 * to garuntee that the Scene prints onto a single page.
 * @param useSymmetricScaling if true, the horizontal and vertical scaling
 * factors will be the same whereby preserving the current aspect ration. The
 * smallest of the two (horizontal and vertical) scaling factors is used for 
 * both.
 */
private void scaleToFit(boolean useSymmetricScaling) {
    PageFormat format = getPageFormat();

    Rectangle componentBounds = scene.getView().getBounds();

    if (componentBounds.width * componentBounds.height == 0) {
        return;
    }
    double scaleX = format.getImageableWidth() / componentBounds.width;
    double scaleY = format.getImageableHeight() / componentBounds.height;

    if (scaleX < 1 || scaleY < 1) {

        if (useSymmetricScaling) {
            if (scaleX < scaleY) {
                scaleY = scaleX;
            } else {
                scaleX = scaleY;
            }
        }

        setSize((float) (componentBounds.width * scaleX), (float) (componentBounds.height * scaleY));
        setScaledSize(scaleX, scaleY);

    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:PageableScene.java

示例15: print

import java.awt.print.PageFormat; //导入依赖的package包/类
/**
 * Prints the chart on a single page.
 *
 * @param g  the graphics context.
 * @param pf  the page format to use.
 * @param pageIndex  the index of the page. If not <code>0</code>, nothing gets print.
 *
 * @return the result of printing.
 */
public int print(Graphics g, PageFormat pf, int pageIndex) {

    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    Graphics2D g2 = (Graphics2D) g;
    double x = pf.getImageableX();
    double y = pf.getImageableY();
    double w = pf.getImageableWidth();
    double h = pf.getImageableHeight();
    this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null);
    return PAGE_EXISTS;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:ChartPanel.java


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