From: Olivier G. <og...@us...> - 2008-02-17 22:11:48
|
Update of /cvsroot/osmose-dev/osmose/src/osmose/application/slideprinter In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6501/src/osmose/application/slideprinter Modified Files: OSMSlidePrinter.java Log Message: Added choice for putting bullet lists in notes (by Fatimatou) Index: OSMSlidePrinter.java =================================================================== RCS file: /cvsroot/osmose-dev/osmose/src/osmose/application/slideprinter/OSMSlidePrinter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OSMSlidePrinter.java 3 Oct 2007 21:31:15 -0000 1.2 --- OSMSlidePrinter.java 17 Feb 2008 22:11:51 -0000 1.3 *************** *** 38,228 **** ! /** ! * To get the Printable instance responsible for rendering the page specified ! * by pageIndex. ! * @param pageIndex Index of page. ! * @return Printable instance associated to the page. ! */ ! public Printable getPrintable(int pageIndex) { ! return this; ! } ! ! ! /** ! * Constructs a slide printer that implement the Printable interface and ! * that will print each page of the presentation in a graphics thanks to the ! * print() method. ! * @param doc The document to print. ! */ ! public OSMSlidePrinter(OSMDocument doc) { ! super(null, doc, 711, 533); ! ! ! // Set this panel as for printing. ! setForPrinting(); ! ! ! // Sort pages before printing ! m_Document.getPresentation().sortPages(); ! ! ! // Get pages list ! m_PagesNumber = m_Document.getPresentation().getNumberOfPages(); ! ! ! // Create a new printer job ! m_PrinterJob = PrinterJob.getPrinterJob(); ! m_PrinterJob.setPageable(this); ! } ! ! ! /** ! * To draw a page in a given graphic context. ! * @param g The graphic context. ! * @param pf The page format. ! * @param pageIndex The index of page to print. ! * @return PAGE_EXISTS if Ok, NO_SUCH_PAGE if page not exist. ! */ ! public int print(Graphics g, PageFormat pf, int pageIndex) { ! ! ! // Checks if the specified index of page is a valid index. ! if((pageIndex >= m_PagesNumber) || (pageIndex < 0)) ! return Printable.NO_SUCH_PAGE; // Index out of range... ! else { ! ! ! // Convert Graphics to Graphics2D ! Graphics2D g2d = (Graphics2D)g; ! ! ! // Keep old transform ! AffineTransform oldAt = g2d.getTransform(); ! ! ! /** ! * size properties of the page : ! * - iW = integer corresponding to available width of the content ! * - iH = integer corresponding to available height of the content ! * - iX = integer corresponding to left and right insets ! * - iY = integer corresponding to top and bottom insets ! */ ! int iW = (int)pf.getImageableWidth(); ! int iH = (int)pf.getImageableHeight(); ! int iX = (int)pf.getImageableX(); ! int iY = (int)pf.getImageableY(); ! ! ! // constructs the content of the specified page in the panel. ! goPage(pageIndex + 1, false, false); ! repaint(); ! ! ! // Translate graphics to printable area ! g2d.translate(iX, iY); ! // Paint the current page in the printable graphics. ! JFrame invisibleContainer = new JFrame(); ! invisibleContainer.getContentPane().add(this); ! invisibleContainer.pack(); ! invisibleContainer.setVisible(false); ! paint(g); - // Restores the graphics transformation for further draw. - g2d.setTransform(oldAt); - // Draws a rectangles to show the page limits (size). - g2d.setColor(Color.BLACK); - g2d.drawRect(iX, iY, iW - 1, iH - 1); - // Indicates to java that the specified page has been drawn - return Printable.PAGE_EXISTS; - } - } ! /** ! * To get the number of pages in the presentation. ! * @return Total number of pages. ! */ ! public int getNumberOfPages() { ! return m_PagesNumber; ! } ! /** ! * To get the PageFormat of the page specified by pageIndex. ! * @param pageIndex Index of page. ! * @return Page format of associated page. ! */ ! public PageFormat getPageFormat(int pageIndex) { ! // picks the default page format. ! PageFormat p = this.m_PrinterJob.defaultPage(); ! /** ! * creates a new paper format, that sets : ! * - A4 size (21 * 29.7 cm = 594 * 842 px) ! * - printable area of 534 * 712 px ! * - left and right inset of 842-712 / 2 ! * - up and down inset of 595-534 / 2 ! */ ! Paper paper = new Paper(); ! paper.setSize(594, 842); // A4 format ! int lrinset = 65; ! int udinset = 30; ! paper.setImageableArea(udinset, lrinset, (int)paper.getWidth() - 2 * udinset, (int)paper.getHeight() - 2 * lrinset); ! p.setPaper(paper); ! /** ! * sets the orientation of the page to Landscape. ! * NB: in the next version of the application, we'll have to checks if the ! * user wants a printed slide with graphics or not, if yes, the page will be ! * printed in Normal mode. ! */ ! p.setOrientation(PageFormat.LANDSCAPE); ! return p; ! } ! /** ! * To print the presentation. ! * @return True if ok, false if not. ! */ ! public boolean printPresentation() { ! try { ! // displays of dialog that permits to the user to sets print format. ! if(m_PrinterJob.printDialog()) { ! // prints the presentation with the user choosen print format ! m_PrinterJob.print(); ! return true; ! } ! } ! catch(Throwable e) { ! } ! return false; ! } ! /** ! * Printer Job. ! */ ! private PrinterJob m_PrinterJob; ! /** ! * pages/slides containing the content of all the slides. ! */ ! private int m_PagesNumber; ! } --- 38,229 ---- ! /** ! * To get the Printable instance responsible for rendering the page specified ! * by pageIndex. ! * @param pageIndex Index of page. ! * @return Printable instance associated to the page. ! */ ! public Printable getPrintable(int pageIndex) { ! return this; ! } ! /** ! * Constructs a slide printer that implement the Printable interface and ! * that will print each page of the presentation in a graphics thanks to the ! * print() method. ! * @param doc The document to print. ! */ ! public OSMSlidePrinter(OSMDocument doc) { ! super(null, doc, 533, 400, false); ! ! // Set this panel as for printing. ! setForPrinting(); + // Sort pages before printing + m_Document.getPresentation().sortPages(); + // Get pages list + m_PagesNumber = m_Document.getPresentation().getNumberOfPages(); + // Create a new printer job + m_PrinterJob = PrinterJob.getPrinterJob(); + m_PrinterJob.setPageable(this); + } + /** + * To draw a page in a given graphic context. + * @param g The graphic context. + * @param pf The page format. + * @param pageIndex The index of page to print. + * @return PAGE_EXISTS if Ok, NO_SUCH_PAGE if page not exist. + */ + public int print(Graphics g, PageFormat pf, int pageIndex) { ! // Checks if the specified index of page is a valid index. ! if((pageIndex >= m_PagesNumber) || (pageIndex < 0)) ! return Printable.NO_SUCH_PAGE; // Index out of range... ! else { + // Convert Graphics to Graphics2D + Graphics2D g2d = (Graphics2D)g; ! // Keep old transform ! AffineTransform oldAt = g2d.getTransform(); ! /** ! * size properties of the page : ! * - iW = integer corresponding to available width of the content ! * - iH = integer corresponding to available height of the content ! * - iX = integer corresponding to left and right insets ! * - iY = integer corresponding to top and bottom insets ! */ ! ! int iW = (int)pf.getImageableWidth()*3/4; ! int iH = (int)pf.getImageableHeight()*3/4; ! int iX = (int)pf.getImageableX(); ! int iY = (int)pf.getImageableY(); ! int iY2 = (int)pf.getImageableHeight()*3/4; ! int iX2 = (int)pf.getImageableX()/6; ! ! // constructs the content of the specified page in the panel. ! goPage(pageIndex + 1, false, false); ! repaint(); ! ! // Translate graphics to printable area ! g2d.translate(iX, iY); + // Paint the current page in the printable graphics. + JFrame invisibleContainer = new JFrame(); + invisibleContainer.getContentPane().add(this); + invisibleContainer.pack(); + invisibleContainer.setVisible(false); + paint(g); + + g2d.setColor(Color.BLACK); + + + //Translate graphics to printable area for notes + g2d.translate(iX2, iY2); + + goPageNotes(pageIndex+1); + invisibleContainer.getContentPane().add(this); + invisibleContainer.setVisible(false); + paint(g); + + //Restores the graphics transformation for further draw. + g2d.setTransform(oldAt); + + // Draws a rectangles to show the frame limits (size) for the slide. + g2d.setColor(Color.BLACK); + g2d.drawRect(iX, iY, iW - 1, iH); + + // Indicates to java that the specified page has been drawn + return Printable.PAGE_EXISTS; + } + } + + + /** + * To get the number of pages in the presentation. + * @return Total number of pages. + */ + public int getNumberOfPages() { + return m_PagesNumber; + } ! /** ! * To get the PageFormat of the page specified by pageIndex. ! * @param pageIndex Index of page. ! * @return Page format of associated page. ! */ ! public PageFormat getPageFormat(int pageIndex) { ! // picks the default page format. ! PageFormat p = this.m_PrinterJob.defaultPage(); ! /** ! * creates a new paper format, that sets : ! * - A4 size (21 * 29.7 cm = 594 * 842 px) ! * - printable area of 534 * 712 px ! * - left and right inset of 842-712 / 2 ! * - up and down inset of 595-534 / 2 ! */ ! Paper paper = new Paper(); ! paper.setSize(594, 842); // A4 format ! int lrinset = 65; ! int udinset = 30; ! paper.setImageableArea(udinset, lrinset, (int)paper.getWidth() - 2 * udinset, (int)paper.getHeight() - 2 * lrinset); ! p.setPaper(paper); ! /** ! * sets the orientation of the page to Landscape. ! * NB: in the next version of the application, we'll have to checks if the ! * user wants a printed slide with graphics or not, if yes, the page will be ! * printed in Normal mode. ! */ ! p.setOrientation(PageFormat.LANDSCAPE); ! ! return p; ! } ! /** ! * To print the presentation. ! * @return True if ok, false if not. ! */ ! public boolean printPresentation() { ! ! try { ! ! // displays of dialog that permits to the user to sets print format. ! if(m_PrinterJob.printDialog()) { ! // prints the presentation with the user choosen print format ! m_PrinterJob.print(); ! return true; ! } ! } ! catch(Throwable e) { ! } ! return false; ! } ! /** ! * Printer Job. ! */ ! private PrinterJob m_PrinterJob; ! /** ! * pages/slides containing the content of all the slides. ! */ ! private int m_PagesNumber; ! } |