KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > layout > Page


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.layout;
15
16 import java.awt.*;
17 import java.util.*;
18
19 import org.compiere.model.*;
20 import org.compiere.util.*;
21
22 /**
23  * Layout Page
24  *
25  * @author Jorg Janke
26  * @version $Id: Page.java,v 1.13 2002/09/03 05:15:35 jjanke Exp $
27  */

28 public class Page
29 {
30     /**
31      * Layout for Page
32      * @param pageNo page
33      * @param ctx context
34      */

35     public Page (Properties ctx, int pageNo)
36     {
37         m_ctx = ctx;
38         m_pageNo = pageNo;
39         if (m_pageInfo == null || m_pageInfo.length() == 0)
40             m_pageInfo = String.valueOf(m_pageNo);
41     } // Page
42

43     /** Current Page No (set here) */
44     public static final String JavaDoc CONTEXT_PAGE = "*Page";
45     /** Page Count (set in Layout Emgine */
46     public static final String JavaDoc CONTEXT_PAGECOUNT = "*PageCount";
47     /** Multi Page Info (set here) */
48     public static final String JavaDoc CONTEXT_MULTIPAGE = "*MultiPageInfo";
49     /** Copy Info (set here) */
50     public static final String JavaDoc CONTEXT_COPY = "*CopyInfo";
51
52     /** Report Name (set in Layout Engine) */
53     public static final String JavaDoc CONTEXT_REPORTNAME = "*ReportName";
54     /** Report Header (set in Layout Engine) */
55     public static final String JavaDoc CONTEXT_HEADER = "*Header";
56     /** Current Date (set in Layout Engine) */
57     public static final String JavaDoc CONTEXT_DATE = "*CurrentDate";
58     /** Current Time (set in Layout Engine) */
59     public static final String JavaDoc CONTEXT_TIME = "*CurrentDateTime";
60
61     /** Page Number */
62     private int m_pageNo;
63     /** Page Number */
64     private int m_pageCount = 1;
65     /** Page Count */
66     private String JavaDoc m_pageInfo;
67     /** Context */
68     private Properties m_ctx;
69     /** Page content */
70     private ArrayList m_elements = new ArrayList();
71
72     /**
73      * Get Page No
74      * @return page no
75      */

76     public int getPageNo()
77     {
78         return m_pageNo;
79     } // getPageNo
80

81     /**
82      * Get Page Info
83      * @return page info
84      */

85     public String JavaDoc getPageInfo()
86     {
87         return m_pageInfo;
88     } // getPageInfo
89

90     /**
91      * Set Page Info.
92      * Enhanced pagae no, e.g., 7(2,3)
93      * @param pageInfo page info
94      */

95     public void setPageInfo (String JavaDoc pageInfo)
96     {
97         if (m_pageInfo == null || m_pageInfo.length() == 0)
98             m_pageInfo = String.valueOf(m_pageNo);
99         m_pageInfo = pageInfo;
100     } // getPageInfo
101

102     /**
103      * Set Page Info
104      * @param pageCount page count
105      */

106     public void setPageCount (int pageCount)
107     {
108         m_pageCount = pageCount;
109     } // setPageCount
110

111     /**
112      * Add Print Element to Page
113      * @param element print element
114      */

115     public void addElement (PrintElement element)
116     {
117         if (element != null)
118             m_elements.add(element);
119     } // addElement
120

121     /*************************************************************************/
122
123     /**
124      * Paint Page on Graphics in Bounds
125      *
126      * @param g2D graphics
127      * @param bounds page bounds
128      * @param isView true if online view (IDs are links)
129      * @param isCopy this print is a copy
130      */

131     public void paint (Graphics2D g2D, Rectangle bounds, boolean isView, boolean isCopy)
132     {
133         m_ctx.put (CONTEXT_PAGE, m_pageInfo);
134     // Log.trace(9, "PrintContext", CONTEXT_PAGE + "=" + m_pageInfo);
135
//
136
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
137         if (m_pageCount != 1) // set to "Page 1 of 2"
138
sb.append(Msg.getMsg(m_ctx, "Page")).append(" ")
139                 .append(m_pageNo)
140                 .append(" ").append(Msg.getMsg(m_ctx, "of")).append(" ")
141                 .append(m_pageCount);
142         else
143             sb.append(" ");
144         m_ctx.put(CONTEXT_MULTIPAGE, sb.toString());
145     // Log.trace(9, "PrintContext", CONTEXT_MULTIPAGE + "=" + sb.toString());
146
//
147
sb = new StringBuffer JavaDoc();
148         if (isCopy) // set to "(Copy)"
149
sb.append("(")
150                 .append(Msg.getMsg(m_ctx, "DocumentCopy"))
151                 .append(")");
152         else
153             sb.append(" ");
154         m_ctx.put(CONTEXT_COPY, sb.toString());
155     // Log.trace(9, "PrintContext copy=" + isCopy, CONTEXT_COPY + "=" + sb.toString());
156

157         // Paint Background
158
g2D.setColor(Color.white);
159         g2D.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
160         //
161
Point pageStart = new Point(bounds.getLocation());
162         for (int i = 0; i < m_elements.size(); i++)
163         {
164             PrintElement e = (PrintElement)m_elements.get(i);
165             e.paint(g2D, m_pageNo, pageStart, m_ctx, isView);
166         }
167     } // paint
168

169     /*************************************************************************/
170
171     /**
172      * Get DrillDown value
173      * @param relativePoint relative Point
174      * @return if found NamePait or null
175      */

176     public MQuery getDrillDown (Point relativePoint)
177     {
178         MQuery retValue = null;
179         for (int i = 0; i < m_elements.size() && retValue == null; i++)
180         {
181             PrintElement element = (PrintElement)m_elements.get(i);
182             retValue = element.getDrillDown (relativePoint, m_pageNo);
183         }
184         return retValue;
185     } // getDrillDown
186

187     /**
188      * Get DrillAcross value
189      * @param relativePoint relative Point
190      * @return if found Query or null
191      */

192     public MQuery getDrillAcross (Point relativePoint)
193     {
194         MQuery retValue = null;
195         for (int i = 0; i < m_elements.size() && retValue == null; i++)
196         {
197             PrintElement element = (PrintElement)m_elements.get(i);
198             retValue = element.getDrillAcross (relativePoint, m_pageNo);
199         }
200         return retValue;
201     } // getDrillAcross
202

203     /**
204      * String Representation
205      * @return info
206      */

207     public String JavaDoc toString()
208     {
209         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Page[");
210         sb.append(m_pageNo).append(",Elements=").append(m_elements.size());
211         sb.append("]");
212         return sb.toString();
213     } // toString
214

215 } // Page
216
Popular Tags