001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * PageSize.java
028: *
029: * Created on 8 febbraio 2003, 18.20
030: *
031: */
032:
033: package it.businesslogic.ireport.util;
034:
035: import java.awt.Point;
036:
037: import java.util.HashMap;
038: import java.util.Iterator;
039: import java.util.Map;
040:
041: public class PageSize {
042: private PageSize() {
043:
044: // This class can not be instantiated
045: }
046:
047: /**
048: * To hold pageFormats required to deduct the pageFormat based on given
049: * Size It is also used for the method getFormatSize()
050: */
051: public static HashMap pageFormats;
052:
053: /** This is the letter format */
054: public static final Point LETTER = new Point(612, 792);
055:
056: /** This is the note format */
057: public static final Point NOTE = new Point(540, 720);
058:
059: /** This is the legal format */
060: public static final Point LEGAL = new Point(612, 1008);
061:
062: /** This is the a0 format */
063: public static final Point A0 = new Point(2380, 3368);
064:
065: /** This is the a1 format */
066: public static final Point A1 = new Point(1684, 2380);
067:
068: /** This is the a2 format */
069: public static final Point A2 = new Point(1190, 1684);
070:
071: /** This is the a3 format */
072: public static final Point A3 = new Point(842, 1190);
073:
074: /** This is the a4 format */
075: public static final Point A4 = new Point(595, 842);
076:
077: /** This is the a5 format */
078: public static final Point A5 = new Point(421, 595);
079:
080: /** This is the a6 format */
081: public static final Point A6 = new Point(297, 421);
082:
083: /** This is the a7 format */
084: public static final Point A7 = new Point(210, 297);
085:
086: /** This is the a8 format */
087: public static final Point A8 = new Point(148, 210);
088:
089: /** This is the a9 format */
090: public static final Point A9 = new Point(105, 148);
091:
092: /** This is the a10 format */
093: public static final Point A10 = new Point(74, 105);
094:
095: /** This is the b0 format */
096: public static final Point B0 = new Point(2836, 4008);
097:
098: /** This is the b1 format */
099: public static final Point B1 = new Point(2004, 2836);
100:
101: /** This is the b2 format */
102: public static final Point B2 = new Point(1418, 2004);
103:
104: /** This is the b3 format */
105: public static final Point B3 = new Point(1002, 1418);
106:
107: /** This is the b4 format */
108: public static final Point B4 = new Point(709, 1002);
109:
110: /** This is the b5 format */
111: public static final Point B5 = new Point(501, 709);
112:
113: /** This is the archE format */
114: public static final Point ARCH_E = new Point(2592, 3456);
115:
116: /** This is the archD format */
117: public static final Point ARCH_D = new Point(1728, 2592);
118:
119: /** This is the archC format */
120: public static final Point ARCH_C = new Point(1296, 1728);
121:
122: /** This is the archB format */
123: public static final Point ARCH_B = new Point(864, 1296);
124:
125: /** This is the archA format */
126: public static final Point ARCH_A = new Point(648, 864);
127:
128: /** This is the flsa format */
129: public static final Point FLSA = new Point(612, 936);
130:
131: /** This is the flse format */
132: public static final Point FLSE = new Point(612, 936);
133:
134: /** This is the halfletter format */
135: public static final Point HALFLETTER = new Point(396, 612);
136:
137: /** This is the 11x17 format */
138: public static final Point _11X17 = new Point(792, 1224);
139:
140: /** This is the ledger format */
141: public static final Point LEDGER = new Point(1224, 792);
142:
143: /**
144: * Class constructor: Initialize pageFormats
145: */
146: static {
147:
148: HashMap pageFormats = new HashMap();
149:
150: pageFormats.put("LETTER", LETTER);
151: pageFormats.put("NOTE", NOTE);
152: pageFormats.put("LEGAL", LEGAL);
153: pageFormats.put("A0", A0);
154: pageFormats.put("A1", A1);
155: pageFormats.put("A2", A2);
156: pageFormats.put("A3", A3);
157: pageFormats.put("A4", A4);
158: pageFormats.put("A5", A5);
159: pageFormats.put("A6", A6);
160: pageFormats.put("A7", A7);
161: pageFormats.put("A8", A8);
162: pageFormats.put("A9", A9);
163: pageFormats.put("A10", A10);
164:
165: pageFormats.put("B0", B0);
166: pageFormats.put("B1", B1);
167: pageFormats.put("B2", B2);
168: pageFormats.put("B3", B3);
169: pageFormats.put("B4", B4);
170: pageFormats.put("B5", B5);
171:
172: pageFormats.put("ARCHE_E", ARCH_E);
173: pageFormats.put("ARCHE_D", ARCH_D);
174: pageFormats.put("ARCHE_C", ARCH_C);
175: pageFormats.put("ARCHE_B", ARCH_B);
176: pageFormats.put("ARCHE_A", ARCH_A);
177:
178: pageFormats.put("FLSA", FLSA);
179: pageFormats.put("FLSE", FLSE);
180:
181: pageFormats.put("HALFLETTER", HALFLETTER);
182: pageFormats.put("11x17", _11X17);
183: pageFormats.put("LEDGER", LEDGER);
184:
185: PageSize.pageFormats = pageFormats;
186:
187: }
188:
189: /**
190: * DOCUMENT ME!
191: *
192: * @param format DOCUMENT ME!
193: * @return DOCUMENT ME!
194: */
195: public static Point getFormatSize(String format) {
196:
197: Point point = (Point) pageFormats.get(format);
198:
199: if (point == null) {
200: point = A4; // A european default... :-)
201: }
202:
203: return point;
204: }
205:
206: /**
207: * Try to find the PageFormat based on the width and height.
208: *
209: * @param pageWidth DOCUMENT ME!
210: * @param pageHeight DOCUMENT ME!
211: * @return DOCUMENT ME!
212: * @since July 3, 2004
213: */
214: public static String deductPageFormat(int pageWidth, int pageHeight) {
215:
216: // Set width and height according to PORTRAIT orientation.
217: // All the page format defined in this class are in this format.
218: int width = pageWidth < pageHeight ? pageWidth : pageHeight; // minimum
219: int height = pageWidth > pageHeight ? pageWidth : pageHeight; // maximum
220: String format = "Custom";
221:
222: // Go through the hashmap and compare width and height with the point pair.
223: // If found, return the hashmap key.
224: // else return empty string.
225: for (Iterator i = pageFormats.entrySet().iterator(); i
226: .hasNext();) {
227:
228: Map.Entry entry = (Map.Entry) i.next();
229:
230: if (((Point) entry.getValue()).x == width) {
231:
232: if (((Point) entry.getValue()).y == height) {
233:
234: //correct pageFormat found.
235: format = (String) entry.getKey();
236: }
237: }
238: }
239:
240: return format;
241: }
242:
243: public static String findOneDown(int pageWidth, int pageHeight) {
244: /** variable height: the width of the current page is the height
245: * of the pageformat we are looking for
246: */
247: int height = pageWidth < pageHeight ? pageWidth : pageHeight; // minimum
248: /**
249: * variable width: the width we are looking for is the height of
250: * the current page divided by 2
251: */
252: int width = (pageWidth > pageHeight ? pageWidth : pageHeight) / 2;
253: String format = "Custom";
254:
255: // Go through the hashmap and compare width and height with the point pair.
256: // If found, return the hashmap key.
257: // else return empty string.
258: for (Iterator i = pageFormats.entrySet().iterator(); i
259: .hasNext();) {
260:
261: Map.Entry entry = (Map.Entry) i.next();
262:
263: if (((Point) entry.getValue()).x == width) {
264:
265: if (((Point) entry.getValue()).y == height) {
266:
267: //correct pageFormat found.
268: format = (String) entry.getKey();
269: }
270: }
271: }
272: return format;
273:
274: }
275:
276: }
|