1 14 package org.compiere.print; 15 16 import java.io.*; 17 import java.awt.*; 18 import java.awt.print.*; 19 import javax.print.*; 20 import javax.print.attribute.*; 21 22 import org.compiere.print.layout.*; 23 import org.compiere.util.*; 24 25 31 public class Print implements Pageable, Printable, Doc 32 { 33 38 public Print (LayoutEngine layout, boolean isCopy) 39 { 40 m_layout = layout; 41 m_isCopy = isCopy; 42 } 46 47 private LayoutEngine m_layout; 48 49 private boolean m_isCopy; 50 51 54 55 56 60 public int getNumberOfPages() 61 { 62 return m_layout.getPageCount(); 63 } 65 70 private boolean havePage (int pageIndex) 71 { 72 if (pageIndex < 0 || pageIndex >= m_layout.getPageCount()) 73 return false; 74 return true; 75 } 77 83 public PageFormat getPageFormat (int pageIndex) throws IndexOutOfBoundsException 84 { 85 if (!havePage(pageIndex)) 86 throw new IndexOutOfBoundsException ("Print.getPageFormat - no page index" + pageIndex); 87 return m_layout.getPageFormat(); 88 } 90 96 public Printable getPrintable (int pageIndex) throws IndexOutOfBoundsException 97 { 98 if (!havePage(pageIndex)) 99 throw new IndexOutOfBoundsException ("Print.getPrintable - no page index " + pageIndex); 100 return this; 101 } 103 111 public int print (Graphics graphics, PageFormat pageFormat, int pageIndex) 112 throws PrinterException 113 { 114 if (!havePage(pageIndex)) 115 return Printable.NO_SUCH_PAGE; 116 Rectangle r = new Rectangle (0, 0, (int)m_layout.getPaper().getWidth(true), (int)m_layout.getPaper().getHeight(true)); 118 Page page = m_layout.getPage(pageIndex+1); 119 page.paint((Graphics2D)graphics, r, false, m_isCopy); m_layout.getHeaderFooter().paint((Graphics2D)graphics, r, false); 123 return Printable.PAGE_EXISTS; 125 } 127 128 129 133 public DocFlavor getDocFlavor() 134 { 135 return DocFlavor.SERVICE_FORMATTED.PAGEABLE; 136 } 138 143 public Object getPrintData() throws IOException 144 { 145 return this; 146 } 148 164 public DocAttributeSet getAttributes() 165 { 166 return null; 167 } 169 174 public Reader getReaderForText() throws IOException 175 { 176 return null; 177 } 179 184 public InputStream getStreamForBytes() throws IOException 185 { 186 return null; 187 } 189 } | Popular Tags |