/*============================================================================= | | NAME | | PrenticePrint.java | | DESCRIPTION | | PUBLIC MEMBER FUNCTIONS | | EXCEPTIONS | | Description | | NOTES | | Algorithm_References_Tricks | | BUGS | | Bugs_Enhancements | | AUTHOR | | Sean E. O'Connor | | LEGAL | | Prentice Version 1.1 - An Artist's Software Apprentice. | Copyright (C) 2003-2008 by Sean Erik O'Connor. All Rights Reserved. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License | as published by the Free Software Foundation; version 2 | of the License. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU General Public License | along with this program; if not, write to the Free Software | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | | The author's address is artifex@seanerikoconnor.freeservers.com. | +============================================================================*/ package View ; // Package name for this project. import java.awt.* ; // AWT basic window handling. import java.awt.event.* ; // AWT basic event handling. import java.awt.geom.* ; // 2D graphics. import java.awt.image.* ; // Images and operations. import javax.swing.* ; // Swing main GUI package. import javax.swing.event.* ; // Swing GUI event handling. import java.awt.print.* ; // Printing. import Prentice.* ; // Prentice stuff. import Model.* ; class PrenticePrint { public static void print() { // Get a print job object. PrinterJob printJob = PrinterJob.getPrinterJob() ; // Create a page format object; make it landscape orientation. PageFormat pageFormat = printJob.defaultPage() ; pageFormat.setOrientation( PageFormat.LANDSCAPE ) ; // Set up a book. Book book = new Book() ; book.append( new paintCover(), pageFormat ) ; // ??? book.append( new paintContent(), pageFormat, 1 ) ; // Pass the book to the print job object. printJob.setPageable( book ) ; // Set name of the print job. printJob.setJobName( "Test print a book" ) ; // Put up print dialog box. if (printJob.printDialog()) { // Print the job unless user has cancelled it. try { printJob.print() ; } catch (PrinterException e) { System.out.println( e ) ; } } System.exit( 0 ) ; } // end main } class paintContent implements Printable { public int print( Graphics g, PageFormat pageFormat, int pageIndex ) throws PrinterException { System.out.println( "Page index = " + pageIndex ) ; if (pageIndex > 2) return Printable.NO_SUCH_PAGE ; Graphics2D g2D = (Graphics2D) g ; double printWidth = pageFormat.getImageableWidth() ; double printHeight = pageFormat.getImageableHeight() ; int upperLeftCornerX = (int) pageFormat.getImageableX() ; int upperLeftCornerY = (int) pageFormat.getImageableY() ; // Draw rectangle surrounding the printable area on the page. Rectangle2D rect = new Rectangle2D.Double( upperLeftCornerX, upperLeftCornerY, printWidth, printHeight ) ; g2D.setColor( Color.red ) ; g2D.draw( rect ) ; // Draw ellipses within the printable area. for (int x = 0 ; x < printWidth - 32 ; x += 50) { for (int y = 0 ; y < printHeight - 32 ; y += 50) { g2D.setColor( new Color( 100, 100, 100 ) ) ; Shape e = new Ellipse2D.Double( upperLeftCornerX + x, upperLeftCornerY + y, 32, 32 ) ; g2D.draw( e ) ; } } return Printable.PAGE_EXISTS ; } // end print } // end class paintContent class paintCover implements Printable { public int print( Graphics g, PageFormat pageFormat, int pageIndex ) throws PrinterException { if (pageIndex > 2) return Printable.NO_SUCH_PAGE ; Graphics2D g2D = (Graphics2D) g ; double printWidth = pageFormat.getImageableWidth() ; double printHeight = pageFormat.getImageableHeight() ; int upperLeftCornerX = (int) pageFormat.getImageableX() ; int upperLeftCornerY = (int) pageFormat.getImageableY() ; // Draw rectangle surrounding the printable area on the page. Rectangle2D rect = new Rectangle2D.Double( upperLeftCornerX, upperLeftCornerY, printWidth, printHeight ) ; g2D.setColor( Color.red ) ; g2D.draw( rect ) ; g2D.setPaint( Color.black ) ; String s = "Test print" ; g2D.drawString( s, upperLeftCornerX, upperLeftCornerY ) ; return Printable.PAGE_EXISTS ; } } // end class paintCover