KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > util > PageSize


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * PageSize.java
28  *
29  * Created on 8 febbraio 2003, 18.20
30  *
31  */

32
33 package it.businesslogic.ireport.util;
34
35 import java.awt.Point JavaDoc;
36
37 import java.util.HashMap JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Map JavaDoc;
40
41
42 public class PageSize
43 {
44     private PageSize()
45     {
46         
47         // This class can not be instantiated
48
}
49     
50     /**
51      * To hold pageFormats required to deduct the pageFormat based on given
52      * Size It is also used for the method getFormatSize()
53      */

54     public static HashMap JavaDoc pageFormats;
55     
56     /** This is the letter format */
57     public static final Point JavaDoc LETTER = new Point JavaDoc(612, 792);
58     
59     /** This is the note format */
60     public static final Point JavaDoc NOTE = new Point JavaDoc(540, 720);
61     
62     /** This is the legal format */
63     public static final Point JavaDoc LEGAL = new Point JavaDoc(612, 1008);
64     
65     /** This is the a0 format */
66     public static final Point JavaDoc A0 = new Point JavaDoc(2380, 3368);
67     
68     /** This is the a1 format */
69     public static final Point JavaDoc A1 = new Point JavaDoc(1684, 2380);
70     
71     /** This is the a2 format */
72     public static final Point JavaDoc A2 = new Point JavaDoc(1190, 1684);
73     
74     /** This is the a3 format */
75     public static final Point JavaDoc A3 = new Point JavaDoc(842, 1190);
76     
77     /** This is the a4 format */
78     public static final Point JavaDoc A4 = new Point JavaDoc(595, 842);
79     
80     /** This is the a5 format */
81     public static final Point JavaDoc A5 = new Point JavaDoc(421, 595);
82     
83     /** This is the a6 format */
84     public static final Point JavaDoc A6 = new Point JavaDoc(297, 421);
85     
86     /** This is the a7 format */
87     public static final Point JavaDoc A7 = new Point JavaDoc(210, 297);
88     
89     /** This is the a8 format */
90     public static final Point JavaDoc A8 = new Point JavaDoc(148, 210);
91     
92     /** This is the a9 format */
93     public static final Point JavaDoc A9 = new Point JavaDoc(105, 148);
94     
95     /** This is the a10 format */
96     public static final Point JavaDoc A10 = new Point JavaDoc(74, 105);
97     
98     /** This is the b0 format */
99     public static final Point JavaDoc B0 = new Point JavaDoc(2836, 4008);
100     
101     /** This is the b1 format */
102     public static final Point JavaDoc B1 = new Point JavaDoc(2004, 2836);
103     
104     /** This is the b2 format */
105     public static final Point JavaDoc B2 = new Point JavaDoc(1418, 2004);
106     
107     /** This is the b3 format */
108     public static final Point JavaDoc B3 = new Point JavaDoc(1002, 1418);
109     
110     /** This is the b4 format */
111     public static final Point JavaDoc B4 = new Point JavaDoc(709, 1002);
112     
113     /** This is the b5 format */
114     public static final Point JavaDoc B5 = new Point JavaDoc(501, 709);
115     
116     /** This is the archE format */
117     public static final Point JavaDoc ARCH_E = new Point JavaDoc(2592, 3456);
118     
119     /** This is the archD format */
120     public static final Point JavaDoc ARCH_D = new Point JavaDoc(1728, 2592);
121     
122     /** This is the archC format */
123     public static final Point JavaDoc ARCH_C = new Point JavaDoc(1296, 1728);
124     
125     /** This is the archB format */
126     public static final Point JavaDoc ARCH_B = new Point JavaDoc(864, 1296);
127     
128     /** This is the archA format */
129     public static final Point JavaDoc ARCH_A = new Point JavaDoc(648, 864);
130     
131     /** This is the flsa format */
132     public static final Point JavaDoc FLSA = new Point JavaDoc(612, 936);
133     
134     /** This is the flse format */
135     public static final Point JavaDoc FLSE = new Point JavaDoc(612, 936);
136     
137     /** This is the halfletter format */
138     public static final Point JavaDoc HALFLETTER = new Point JavaDoc(396, 612);
139     
140     /** This is the 11x17 format */
141     public static final Point JavaDoc _11X17 = new Point JavaDoc(792, 1224);
142     
143     /** This is the ledger format */
144     public static final Point JavaDoc LEDGER = new Point JavaDoc(1224, 792);
145     
146     /**
147      * Class constructor: Initialize pageFormats
148      */

149     static
150     {
151         
152         HashMap JavaDoc pageFormats = new HashMap JavaDoc();
153         
154         pageFormats.put("LETTER", LETTER);
155         pageFormats.put("NOTE", NOTE);
156         pageFormats.put("LEGAL", LEGAL);
157         pageFormats.put("A0", A0);
158         pageFormats.put("A1", A1);
159         pageFormats.put("A2", A2);
160         pageFormats.put("A3", A3);
161         pageFormats.put("A4", A4);
162         pageFormats.put("A5", A5);
163         pageFormats.put("A6", A6);
164         pageFormats.put("A7", A7);
165         pageFormats.put("A8", A8);
166         pageFormats.put("A9", A9);
167         pageFormats.put("A10", A10);
168         
169         pageFormats.put("B0", B0);
170         pageFormats.put("B1", B1);
171         pageFormats.put("B2", B2);
172         pageFormats.put("B3", B3);
173         pageFormats.put("B4", B4);
174         pageFormats.put("B5", B5);
175         
176         pageFormats.put("ARCHE_E", ARCH_E);
177         pageFormats.put("ARCHE_D", ARCH_D);
178         pageFormats.put("ARCHE_C", ARCH_C);
179         pageFormats.put("ARCHE_B", ARCH_B);
180         pageFormats.put("ARCHE_A", ARCH_A);
181         
182         pageFormats.put("FLSA", FLSA);
183         pageFormats.put("FLSE", FLSE);
184         
185         pageFormats.put("HALFLETTER", HALFLETTER);
186         pageFormats.put("11x17", _11X17);
187         pageFormats.put("LEDGER", LEDGER);
188         
189         PageSize.pageFormats = pageFormats;
190         
191     }
192     
193     /**
194      * DOCUMENT ME!
195      *
196      * @param format DOCUMENT ME!
197      * @return DOCUMENT ME!
198      */

199     public static Point JavaDoc getFormatSize(String JavaDoc format)
200     {
201         
202         Point JavaDoc point = (Point JavaDoc) pageFormats.get(format);
203         
204         if (point == null)
205         {
206             point = A4; // A european default... :-)
207
}
208         
209         return point;
210     }
211     
212     /**
213      * Try to find the PageFormat based on the width and height.
214      *
215      * @param pageWidth DOCUMENT ME!
216      * @param pageHeight DOCUMENT ME!
217      * @return DOCUMENT ME!
218      * @since July 3, 2004
219      */

220     public static String JavaDoc deductPageFormat(int pageWidth, int pageHeight)
221     {
222         
223         // Set width and height according to PORTRAIT orientation.
224
// All the page format defined in this class are in this format.
225
int width = pageWidth < pageHeight
226                 ? pageWidth
227                 : pageHeight; // minimum
228
int height = pageWidth > pageHeight
229                 ? pageWidth
230                 : pageHeight; // maximum
231
String JavaDoc format = "Custom";
232         
233         // Go through the hashmap and compare width and height with the point pair.
234
// If found, return the hashmap key.
235
// else return empty string.
236
for (Iterator JavaDoc i = pageFormats.entrySet().iterator(); i.hasNext();)
237         {
238             
239             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
240             
241             if (((Point JavaDoc) entry.getValue()).x == width)
242             {
243                 
244                 if (((Point JavaDoc) entry.getValue()).y == height)
245                 {
246                     
247                     //correct pageFormat found.
248
format = (String JavaDoc) entry.getKey();
249                 }
250             }
251         }
252         
253         return format;
254     }
255     
256     public static String JavaDoc findOneDown(int pageWidth, int pageHeight)
257     {
258         /** variable height: the width of the current page is the height
259          * of the pageformat we are looking for
260          */

261         int height = pageWidth < pageHeight
262                 ? pageWidth
263                 : pageHeight; // minimum
264
/**
265          * variable width: the width we are looking for is the height of
266          * the current page divided by 2
267          */

268         int width = (pageWidth > pageHeight
269                 ? pageWidth
270                 : pageHeight) / 2 ;
271         String JavaDoc format = "Custom";
272         
273         // Go through the hashmap and compare width and height with the point pair.
274
// If found, return the hashmap key.
275
// else return empty string.
276
for (Iterator JavaDoc i = pageFormats.entrySet().iterator(); i.hasNext();)
277         {
278             
279             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
280             
281             if (((Point JavaDoc) entry.getValue()).x == width)
282             {
283                 
284                 if (((Point JavaDoc) entry.getValue()).y == height)
285                 {
286                     
287                     //correct pageFormat found.
288
format = (String JavaDoc) entry.getKey();
289                 }
290             }
291         }
292         return format;
293         
294         
295         
296         
297     }
298     
299     
300 }
301
Popular Tags