类java.awt.print.PageFormat源码实例Demo

下面列出了怎么用java.awt.print.PageFormat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openstock   文件: ChartComposite.java
/**
 * Not implemented.
 *
 * @param graphics  the graphics.
 * @param pageFormat  the page format.
 * @param pageIndex  the page index.
 *
 * @return ?.
 *
 * @throws PrinterException if there is a problem.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
    throws PrinterException {
    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    /*
    CairoImage image = new CairoImage(
            this.getBounds().width, this.getBounds().height);
    Graphics2D g2 = image.createGraphics2D();
    double x = pageFormat.getImageableX();
    double y = pageFormat.getImageableY();
    double w = pageFormat.getImageableWidth();
    double h = pageFormat.getImageableHeight();
    this.chart.draw(
        g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null
    );
    */
    return PAGE_EXISTS;
}
 
源代码2 项目: openstock   文件: ChartPanel.java
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            }
            catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}
 
源代码3 项目: pentaho-reporting   文件: ExpressionTestBase.java
protected MasterReport createRelationalReport( final TableModel tableModel, final String... additionalFields ) {
  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( PageSize.A3, PageFormat.LANDSCAPE, new Insets( 0, 0, 0, 0 ) ) );
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final RelationalReportBuilder builder = new RelationalReportBuilder( dataSchemaModel );
  builder.addGroup( ROW_DIMENSION_A );
  builder.addGroup( ROW_DIMENSION_B );
  builder.addGroup( COLUMN_DIMENSION_A );
  builder.addGroup( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, null, Color.lightGray );
  builder.addDetails( "relational", null, Color.yellow );
  for ( int i = 0; i < additionalFields.length; i++ ) {
    String additionalField = additionalFields[i];
    builder.addDetails( additionalField, null, null );
  }

  report.setRootGroup( builder.create() );
  return report;
}
 
源代码4 项目: pentaho-reporting   文件: WeirdLayoutIT.java
public void testLayout() throws ResourceException, ContentProcessingException, ReportProcessingException {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final URL target = WeirdLayoutIT.class.getResource( "weird-layouting.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final Band band = report.getReportHeader();
  band.setName( "ReportHeader1" );

  DebugReportRunner.layoutSingleBand( report, band, false, true );

}
 
源代码5 项目: dragonwell8_jdk   文件: RasterPrinterJob.java
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);
}
 
源代码6 项目: jdk8u-jdk   文件: RasterPrinterJob.java
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);
}
 
源代码7 项目: osp   文件: SnapshotTool.java
public void print() {
  PrinterJob printerJob = PrinterJob.getPrinterJob();
  PageFormat format = new PageFormat();
  java.awt.print.Book book = new java.awt.print.Book();
  book.append(this, format);
  printerJob.setPageable(book);
  if(printerJob.printDialog()) {
    try {
      printerJob.print();
    } catch(PrinterException pe) {
      // JOptionPane.showMessageDialog(c,
      // TrackerRes.getString("TActions.Dialog.PrintError.Message"), //$NON-NLS-1$
      // TrackerRes.getString("TActions.Dialog.PrintError.Title"), //$NON-NLS-1$
      // JOptionPane.ERROR_MESSAGE);
    }
  }
}
 
源代码8 项目: pentaho-reporting   文件: MinChunkWidthIT.java
public void testMinChunkWidth() throws Exception {
  if ( DebugReportRunner.isSafeToTestComplexText() == false ) {
    return;
  }

  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.setCompatibilityLevel( null );
  basereport.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "true" );

  final URL target = LayoutIT.class.getResource( "min-chunkwidth.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, true );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), true, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485 or 400
  // and that only two lines exist for each
  ModelPrinter.INSTANCE.print( logicalPageBox );
  new ValidateRunner( false, true ).startValidation( logicalPageBox );
}
 
源代码9 项目: SIMVA-SoS   文件: ChartPanel.java
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            }
            catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}
 
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);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
源代码11 项目: hottub   文件: bug8023392.java
public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
        throws PrinterException {
    if (pageIndex >= 1) {
        return Printable.NO_SUCH_PAGE;
    }

    this.paint(graphics);
    return Printable.PAGE_EXISTS;
}
 
源代码12 项目: hottub   文件: PrintLatinCJKTest.java
public int print(Graphics g, PageFormat pf, int pageIndex)
                     throws PrinterException {

    if (pageIndex > 0) {
        return Printable.NO_SUCH_PAGE;
    }
    g.translate((int) pf.getImageableX(), (int) pf.getImageableY());
    g.setFont(new Font("Dialog", Font.PLAIN, 36));
    g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100);
    return Printable.PAGE_EXISTS;
}
 
源代码13 项目: jdk8u60   文件: PSPrinterJob.java
public PageFormat getPageFormat(int pgIndex) {
    if (pgIndex > 0) {
        throw new IndexOutOfBoundsException("pgIndex");
    } else {
        return pf;
    }
}
 
源代码14 项目: beast-mcmc   文件: JChartPanel.java
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
	if (pageIndex > 0) {
		return(NO_SUCH_PAGE);
	} else {
		Graphics2D g2d = (Graphics2D)g;

		double x0 = pageFormat.getImageableX();
		double y0 = pageFormat.getImageableY();

		double w0 = pageFormat.getImageableWidth();
		double h0 = pageFormat.getImageableHeight();

		double w1 = getWidth();
		double h1 = getHeight();

		double scale;

		if (w0 / w1 < h0 / h1) {
			scale = w0 / w1;
		} else {
			scale = h0 /h1;
		}

		g2d.translate(x0, y0);
		g2d.scale(scale, scale);

		Color bg = getBackground();
		setBackground(Color.white);

		paint(g2d);

		setBackground(bg);

		return(PAGE_EXISTS);
	}
}
 
源代码15 项目: jdk8u60   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码16 项目: openjdk-jdk8u   文件: WPrinterJob.java
/**
 * End a page.
 */
@Override
protected void endPage(PageFormat format, Printable painter,
                       int index) {

    deviceEndPage(format, painter, index);
}
 
源代码17 项目: ramus   文件: IDEF0Printable.java
public int getPageCount() {
    int res = 0;
    for (int index = 0; index < painters.length; index++) {
        PIDEF0painter painter = getPainter(index);
        res += painter.hPageCount;
    }
    if (getPageFormat().getOrientation() == PageFormat.PORTRAIT)
        res = (int) Math.ceil((double) res / 2.d);
    return res;
}
 
源代码18 项目: jdk8u-jdk   文件: RasterPrinterJob.java
/**
 * The passed in PageFormat is cloned and altered to be usable on
 * the PrinterJob's current printer.
 */
public PageFormat validatePage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    Paper newPaper = new Paper();
    validatePaper(newPage.getPaper(), newPaper);
    newPage.setPaper(newPaper);

    return newPage;
}
 
源代码19 项目: openjdk-jdk8u   文件: PSPrinterJob.java
public PageFormat getPageFormat(int pgIndex) {
    if (pgIndex > 0) {
        throw new IndexOutOfBoundsException("pgIndex");
    } else {
        return pf;
    }
}
 
源代码20 项目: haxademic   文件: PrintPageDirectNew.java
public int print(Graphics g, PageFormat pageFormat, int page) {
	// Create the Graphics2D object, Translate the origin to 0,0 for the top left corner, Set the default drawing color to black
	Graphics2D g2d = (Graphics2D) g;
	g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
	g2d.setPaint(Color.black);
	
	// Print the full-page PImage by converting to native BufferedImage
	P.out("PageFormat size: ", (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight());
	g2d.drawImage((BufferedImage) printBuffer.getNative(), 0, 0, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight(), null);
	
	return (PAGE_EXISTS);
}
 
源代码21 项目: pentaho-reporting   文件: PageFormatPreviewPane.java
public void draw( final Graphics2D graphics, final Rectangle2D bounds ) {
  final PageFormat gpf = getPageFormat();

  final Rectangle2D.Double imageableArea =
      new Rectangle2D.Double( gpf.getImageableX(), gpf.getImageableY(), gpf.getImageableWidth(), gpf
          .getImageableHeight() );
  graphics.setPaint( new Color( 225, 225, 225 ) );
  graphics.fill( imageableArea );
  graphics.setPaint( Color.gray );
  graphics.draw( imageableArea );

  final int pcH = pageDefinition.getPageCountHorizontal();
  final int pcW = pageDefinition.getPageCountVertical();

  final Line2D line = new Line2D.Double();
  for ( int splitH = 1; splitH < pcH; splitH += 1 ) {
    final double xPos = gpf.getImageableX() + ( splitH * gpf.getImageableWidth() );
    line.setLine( xPos, gpf.getImageableY(), xPos, gpf.getImageableY() + gpf.getImageableHeight() );
    graphics.draw( line );
  }

  for ( int splitW = 1; splitW < pcW; splitW += 1 ) {
    final double yPos = gpf.getImageableY() + ( splitW * gpf.getImageableHeight() );
    line.setLine( gpf.getImageableX(), yPos, gpf.getImageableX() + gpf.getImageableWidth(), yPos );
    graphics.draw( line );
  }
}
 
源代码22 项目: netbeans   文件: Printer.java
public int print(Graphics g, PageFormat pageFormat, int index) throws PrinterException {
//out("PAPER IS: " + myPapers.size());
        if (index == myPapers.size()) {
            return NO_SUCH_PAGE;
        }
//out("  print: " + index);
        myPapers.get(index).print(g);

        return PAGE_EXISTS;
    }
 
源代码23 项目: jdk8u-jdk   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码24 项目: Bytecoder   文件: PrintJob2D.java
/**
 * Prints the page at the specified index into the specified
 * {@link Graphics} context in the specified
 * format.  A {@code PrinterJob} calls the
 * {@code Printable} interface to request that a page be
 * rendered into the context specified by
 * {@code graphics}.  The format of the page to be drawn is
 * specified by {@code pageFormat}.  The zero based index
 * of the requested page is specified by {@code pageIndex}.
 * If the requested page does not exist then this method returns
 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
 * The {@code Graphics} class or subclass implements the
 * {@link java.awt.PrintGraphics} interface to provide additional
 * information.  If the {@code Printable} object
 * aborts the print job then it throws a {@link PrinterException}.
 * @param graphics the context into which the page is drawn
 * @param pageFormat the size and orientation of the page being drawn
 * @param pageIndex the zero based index of the page to be drawn
 * @return PAGE_EXISTS if the page is rendered successfully
 *         or NO_SUCH_PAGE if {@code pageIndex} specifies a
 *         non-existent page.
 * @exception java.awt.print.PrinterException
 *         thrown when the print job is terminated.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
             throws PrinterException {

    int result;

    /* This method will be called by the PrinterJob on a thread other
     * that the application's thread. We hold on to the graphics
     * until we can rendevous with the application's thread and
     * hand over the graphics. The application then does all the
     * drawing. When the application is done drawing we rendevous
     * again with the PrinterJob thread and release the Graphics
     * so that it knows we are done.
     */

    /* Add the graphics to the message queue of graphics to
     * be rendered. This is really a one slot queue. The
     * application's thread will come along and remove the
     * graphics from the queue when the app asks for a graphics.
     */
    graphicsToBeDrawn.append( (Graphics2D) graphics);

    /* We now wait for the app's thread to finish drawing on
     * the Graphics. This thread will sleep until the application
     * release the graphics by placing it in the graphics drawn
     * message queue. If the application signals that it is
     * finished drawing the entire document then we'll get null
     * returned when we try and pop a finished graphic.
     */
    if (graphicsDrawn.pop() != null) {
        result = PAGE_EXISTS;
    } else {
        result = NO_SUCH_PAGE;
    }

    return result;
}
 
源代码25 项目: jdk8u-jdk   文件: PathGraphics.java
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
源代码26 项目: openjdk-8-source   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码27 项目: jdk8u_jdk   文件: PrintJob2D.java
/**
 * Prints the page at the specified index into the specified
 * {@link Graphics} context in the specified
 * format.  A <code>PrinterJob</code> calls the
 * <code>Printable</code> interface to request that a page be
 * rendered into the context specified by
 * <code>graphics</code>.  The format of the page to be drawn is
 * specified by <code>pageFormat</code>.  The zero based index
 * of the requested page is specified by <code>pageIndex</code>.
 * If the requested page does not exist then this method returns
 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
 * The <code>Graphics</code> class or subclass implements the
 * {@link PrinterGraphics} interface to provide additional
 * information.  If the <code>Printable</code> object
 * aborts the print job then it throws a {@link PrinterException}.
 * @param graphics the context into which the page is drawn
 * @param pageFormat the size and orientation of the page being drawn
 * @param pageIndex the zero based index of the page to be drawn
 * @return PAGE_EXISTS if the page is rendered successfully
 *         or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
 *         non-existent page.
 * @exception java.awt.print.PrinterException
 *         thrown when the print job is terminated.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
             throws PrinterException {

    int result;

    /* This method will be called by the PrinterJob on a thread other
     * that the application's thread. We hold on to the graphics
     * until we can rendevous with the application's thread and
     * hand over the graphics. The application then does all the
     * drawing. When the application is done drawing we rendevous
     * again with the PrinterJob thread and release the Graphics
     * so that it knows we are done.
     */

    /* Add the graphics to the message queue of graphics to
     * be rendered. This is really a one slot queue. The
     * application's thread will come along and remove the
     * graphics from the queue when the app asks for a graphics.
     */
    graphicsToBeDrawn.append( (Graphics2D) graphics);

    /* We now wait for the app's thread to finish drawing on
     * the Graphics. This thread will sleep until the application
     * release the graphics by placing it in the graphics drawn
     * message queue. If the application signals that it is
     * finished drawing the entire document then we'll get null
     * returned when we try and pop a finished graphic.
     */
    if (graphicsDrawn.pop() != null) {
        result = PAGE_EXISTS;
    } else {
        result = NO_SUCH_PAGE;
    }

    return result;
}
 
源代码28 项目: openjdk-jdk8u   文件: DlgAttrsBug.java
public int print(Graphics g, PageFormat pf, int pi)
        throws PrinterException {
    System.out.println("pi = " + pi);
    if (pi >= 5) {
        return NO_SUCH_PAGE;
    }
    g.drawString("Page : " + (pi+1), 200, 200);
    return PAGE_EXISTS;
}
 
源代码29 项目: megan-ce   文件: ClusterViewer.java
/**
 * Print the graph associated with this viewer.
 *
 * @param gc0        the graphics context.
 * @param format     page format
 * @param pagenumber page index
 */
public int print(Graphics gc0, PageFormat format, int pagenumber) throws PrinterException {
    JPanel panel = getPanel();

    if (panel != null && pagenumber == 0) {
        if (panel instanceof GraphView) {
            return ((GraphView) panel).print(gc0, format, pagenumber);
        } else {
            Graphics2D gc = ((Graphics2D) gc0);
            Dimension dim = panel.getSize();
            int image_w = dim.width;
            int image_h = dim.height;

            double paper_x = format.getImageableX() + 1;
            double paper_y = format.getImageableY() + 1;
            double paper_w = format.getImageableWidth() - 2;
            double paper_h = format.getImageableHeight() - 2;

            double scale_x = paper_w / image_w;
            double scale_y = paper_h / image_h;
            double scale = Math.min(scale_x, scale_y);

            double shift_x = paper_x + (paper_w - scale * image_w) / 2.0;
            double shift_y = paper_y + (paper_h - scale * image_h) / 2.0;

            gc.translate(shift_x, shift_y);
            gc.scale(scale, scale);

            panel.print(gc0);
            return Printable.PAGE_EXISTS;
        }
    }
    return Printable.NO_SUCH_PAGE;
}
 
源代码30 项目: pentaho-reporting   文件: MasterReport.java
private PageDefinition createDefaultPageDefinition() {
  final PageDefinition format;
  final ExtendedConfiguration config = ClassicEngineBoot.getInstance().getExtendedConfig();
  if ( config.getBoolProperty( ClassicEngineCoreModule.NO_PRINTER_AVAILABLE_KEY ) ) {
    format = new SimplePageDefinition( new PageFormat() );
  } else {
    format = new SimplePageDefinition( PrinterJob.getPrinterJob().defaultPage() );
  }
  return format;
}
 
 类所在包
 同包方法