KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > Print


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
26  * Printer interface
27  *
28  * @author Jorg Janke
29  * @version $Id: Print.java,v 1.8 2002/09/01 00:55:05 jjanke Exp $
30  */

31 public class Print implements Pageable, Printable, Doc
32 {
33     /**
34      * Printer interface constructor
35      * @param layout layout
36      * @param isCopy is not the original
37      */

38     public Print (LayoutEngine layout, boolean isCopy)
39     {
40         m_layout = layout;
41         m_isCopy = isCopy;
42     // m_id = s_id++;
43
// Log.trace(Log.l4_Data, "Print #" + m_id, "Copy=" + m_isCopy);
44
} // layout
45

46     /** Layout */
47     private LayoutEngine m_layout;
48     /** Is a Copy */
49     private boolean m_isCopy;
50
51 // private int m_id;
52
// private static int s_id=0;
53

54     /*************************************************************************/
55
56     /**
57      * Get number of pages
58      * @return number of pages
59      */

60     public int getNumberOfPages()
61     {
62         return m_layout.getPageCount();
63     } // getNumberOfPages
64

65     /**
66      * Do we have the page
67      * @param pageIndex page index
68      * @return true if page exists
69      */

70     private boolean havePage (int pageIndex)
71     {
72         if (pageIndex < 0 || pageIndex >= m_layout.getPageCount())
73             return false;
74         return true;
75     } // havePage
76

77     /**
78      * Get Page Format
79      * @param pageIndex page index
80      * @return Page Format
81      * @throws IndexOutOfBoundsException
82      */

83     public PageFormat getPageFormat (int pageIndex) throws IndexOutOfBoundsException JavaDoc
84     {
85         if (!havePage(pageIndex))
86             throw new IndexOutOfBoundsException JavaDoc("Print.getPageFormat - no page index" + pageIndex);
87         return m_layout.getPageFormat();
88     } // getPageFormat
89

90     /**
91      * Get Printable
92      * @param pageIndex page index
93      * @return this
94      * @throws IndexOutOfBoundsException
95      */

96     public Printable getPrintable (int pageIndex) throws IndexOutOfBoundsException JavaDoc
97     {
98         if (!havePage(pageIndex))
99             throw new IndexOutOfBoundsException JavaDoc("Print.getPrintable - no page index " + pageIndex);
100         return this;
101     } // getPrintable
102

103     /**
104      * Print Page
105      * @param graphics graphics
106      * @param pageFormat page format (ignored)
107      * @param pageIndex page index
108      * @return PageExists/NoSuchPage
109      * @throws PrinterException
110      */

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         //
117
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         //
120
// Log.trace(Log.l5_DData, "Print #" + m_id, "PageIndex=" + pageIndex + ", Copy=" + m_isCopy);
121
page.paint((Graphics2D)graphics, r, false, m_isCopy); // sets context
122
m_layout.getHeaderFooter().paint((Graphics2D)graphics, r, false);
123         //
124
return Printable.PAGE_EXISTS;
125     } // print
126

127     /*************************************************************************/
128
129     /**
130      * Get the doc flavor
131      * @return SERVICE_FORMATTED.PAGEABLE
132      */

133     public DocFlavor getDocFlavor()
134     {
135         return DocFlavor.SERVICE_FORMATTED.PAGEABLE;
136     } // getDocFlavor
137

138     /**
139      * Get Print Data
140      * @return this
141      * @throws IOException
142      */

143     public Object JavaDoc getPrintData() throws IOException
144     {
145         return this;
146     } // getPrintData
147

148     /**
149      * Obtains the set of printing attributes for this doc object. If the
150      * returned attribute set includes an instance of a particular attribute
151      * <I>X,</I> the printer must use that attribute value for this doc,
152      * overriding any value of attribute <I>X</I> in the job's attribute set.
153      * If the returned attribute set does not include an instance
154      * of a particular attribute <I>X</I> or if null is returned, the printer
155      * must consult the job's attribute set to obtain the value for
156      * attribute <I>X,</I> and if not found there, the printer must use an
157      * implementation-dependent default value. The returned attribute set is
158      * unmodifiable.
159      *
160      * @return Unmodifiable set of printing attributes for this doc, or null
161      * to obtain all attribute values from the job's attribute
162      * set.
163      */

164     public DocAttributeSet getAttributes()
165     {
166         return null;
167     } // getAttributes
168

169     /**
170      * Obtains a reader for extracting character print data from this doc.
171      * @return null
172      * @exception IOException
173      */

174     public Reader getReaderForText() throws IOException
175     {
176         return null;
177     } // getReaderForText
178

179     /**
180      * Obtains an input stream for extracting byte print data from this doc.
181      * @return null
182      * @exception IOException
183      */

184     public InputStream getStreamForBytes() throws IOException
185     {
186         return null;
187     } // getStreamForBytes
188

189 } // Print
190
Popular Tags