View Javadoc

1   /********************************************************************************
2    * $Id: Pagesize.java 98 2008-02-27 06:11:26Z sjardine $
3    * 
4    * Copyright 2003 Innovation Software Group, LLC - http://www.innovationsw.com
5    * Copyright 2003 Joe Phillips <jaiger@innovationsw.com>
6    * Copyright 2008 Steven Jardine, MJN Services, Inc. <steve@mjnservices.com>
7    * 
8    * All rights reserved. This program and the accompanying materials are made
9    * available under the terms of the GNU Lesser Public License v2.1 which 
10   * accompanies this distribution, and is available at
11   * 	http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
12   *
13   * For more information on the HylaFAX Fax Server please see
14   * 	HylaFAX  - http://www.hylafax.org or 
15   * 	Hylafax+ - http://hylafax.sourceforge.net
16   * 
17   * Contributors:
18   * 	Joe Phillips - Initial API and implementation
19   * 	Steven Jardine - Code formatting, rework of license header, javadoc 
20   ******************************************************************************/
21  package gnu.hylafax;
22  
23  import java.awt.Dimension;
24  import java.util.HashMap;
25  
26  /***
27   * This class serves as a store of common pagesizes, or create your own!
28   * 
29   * @version $Revision: 98 $
30   * @author Joe Phillips <jaiger@innovationsw.com>
31   * @author Steven Jardine <steve@mjnservices.com>
32   */
33  public class Pagesize extends Dimension {
34  
35      private static HashMap sizes = new HashMap();
36  
37      /*** a US Letter size page */
38      public static final Pagesize letter = new Pagesize(216, 279);
39  
40      /*** a US Letter size page */
41      public static final Pagesize LETTER = letter;
42  
43      /*** North American Letter size page */
44      public static final Pagesize naletter = letter;
45  
46      /*** North American Letter size page */
47      public static final Pagesize NALETTER = letter;
48  
49      /*** US Letter size page */
50      public static final Pagesize usletter = letter;
51  
52      /*** US Letter size page */
53      public static final Pagesize USLETTER = letter;
54  
55      /*** a US Legal size page */
56      public static final Pagesize legal = new Pagesize(216, 356);
57  
58      /*** a US Legal size page */
59      public static final Pagesize LEGAL = legal;
60  
61      /*** a US Legal size page */
62      public static final Pagesize uslegal = legal;
63  
64      /*** a US Legal size page */
65      public static final Pagesize USLEGAL = legal;
66  
67      /*** a US Ledger size page */
68      public static final Pagesize ledger = new Pagesize(279, 432);
69  
70      /*** a US Ledger size page */
71      public static final Pagesize LEDGER = ledger;
72  
73      /*** a US Ledger size page */
74      public static final Pagesize usledger = ledger;
75  
76      /*** a US Ledger size page */
77      public static final Pagesize USLEDGER = ledger;
78  
79      /*** an A3 size page */
80      public static final Pagesize a3 = new Pagesize(297, 420);
81  
82      /*** an A3 size page */
83      public static final Pagesize A3 = a3;
84  
85      /*** an A4 size page */
86      public static final Pagesize a4 = new Pagesize(210, 297);
87  
88      /*** an A4 size page */
89      public static final Pagesize A4 = a4;
90  
91      /*** an A5 size page */
92      public static final Pagesize a5 = new Pagesize(148, 210);
93  
94      /*** an A5 size page */
95      public static final Pagesize A5 = a5;
96  
97      /*** an A6 size page */
98      public static final Pagesize a6 = new Pagesize(105, 148);
99  
100     /*** an A6 size page */
101     public static final Pagesize A6 = a6;
102 
103     /*** an B4 size page */
104     public static final Pagesize b4 = new Pagesize(250, 353);
105 
106     /*** an B4 size page */
107     public static final Pagesize B4 = b4;
108 
109     /*** a US Executive size page */
110     public static final Pagesize executive = new Pagesize(190, 254);
111 
112     /*** a US Executive size page */
113     public static final Pagesize EXECUTIVE = executive;
114 
115     /*** a US Executive size page */
116     public static final Pagesize usexecutive = executive;
117 
118     /*** a US Executive size page */
119     public static final Pagesize USEXECUTIVE = executive;
120 
121     static {
122 	sizes.put("letter", letter);
123 	sizes.put("us-letter", letter);
124 	sizes.put("us-let", letter);
125 	sizes.put("na-let", letter);
126 
127 	sizes.put("legal", legal);
128 	sizes.put("us-legal", legal);
129 	sizes.put("us-leg", legal);
130 	sizes.put("na-leg", legal);
131 
132 	sizes.put("ledger", ledger);
133 	sizes.put("us-ledger", ledger);
134 	sizes.put("us-led", ledger);
135 	sizes.put("na-led", ledger);
136 
137 	sizes.put("executive", executive);
138 	sizes.put("us-executive", executive);
139 	sizes.put("us-exe", executive);
140 	sizes.put("na-exe", executive);
141 
142 	sizes.put("a3", a3);
143 	sizes.put("a4", a4);
144 	sizes.put("a5", a5);
145 	sizes.put("a6", a6);
146 	sizes.put("b4", b4);
147     }
148 
149     /*
150      * The following values are currently not implemented ...
151      * pagesizes.put("jp-leg", new Dimension()); pagesizes.put("jp-let", new
152      * Dimension());
153      */
154 
155     /***
156      * default constructor
157      */
158     public Pagesize() {
159 	super();
160     }
161 
162     /***
163      * copy constructor
164      */
165     public Pagesize(Dimension d) {
166 	super(d);
167     }
168 
169     /***
170      * constructor specifying width and height respectively
171      */
172     public Pagesize(int width, int height) {
173 	super(width, height);
174     }
175 
176     //
177     // static methods
178     //
179 
180     /***
181      * lookup a pagesize by its name
182      */
183     public static Pagesize getPagesize(String key) {
184 	return (Pagesize) sizes.get(key.toLowerCase());
185     }
186 
187     /***
188      * add a (non-null) mapping from name to pagesize
189      */
190     public static void putPagesize(String key, Pagesize p) {
191 	if ((p == null) || (key == null))
192 	    return;
193 	sizes.put(key.toLowerCase(), p);
194     }
195 
196 }
197 // Pagesize.java