Source Code Cross Referenced for PageFormat.java in  » PDF » PDFClown-0.0.5 » it » stefanochizzolini » clown » documents » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » PDFClown 0.0.5 » it.stefanochizzolini.clown.documents 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          Copyright © 2007 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004:          Contributors:
005:         * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006:              contributed code is Copyright © 2007 by Stefano Chizzolini.
007:
008:          This file should be part of the source code distribution of "PDF Clown library"
009:          (the Program): see the accompanying README files for more info.
010:
011:          This Program is free software; you can redistribute it and/or modify it under
012:          the terms of the GNU General Public License as published by the Free Software
013:          Foundation; either version 2 of the License, or (at your option) any later version.
014:
015:          This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016:          WARRANTY, either expressed or implied; without even the implied warranty of
017:          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019:          You should have received a copy of the GNU General Public License along with this
020:          Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022:          Redistribution and use, with or without modification, are permitted provided that such
023:          redistributions retain the above copyright notice, license and disclaimer, along with
024:          this list of conditions.
025:         */
026:
027:        package it.stefanochizzolini.clown.documents;
028:
029:        import it.stefanochizzolini.clown.util.NotImplementedException;
030:
031:        import java.awt.Dimension;
032:        import java.util.regex.Matcher;
033:        import java.util.regex.Pattern;
034:
035:        /**
036:         Page format.
037:         <p>This utility provides an easy access to the dimension of common page formats.</p>
038:
039:         @author Stefano Chizzolini
040:         @version 0.0.4, 07/27/07
041:         @since 0.0.3
042:         @see Document#setPageSize(Dimension2D)
043:         @see Page#setSize(Dimension2D)
044:         */
045:        public class PageFormat {
046:            // <class>
047:            // <classes>
048:            /**
049:              Paper size.
050:              <h3>Remarks</h3>
051:              <p>References:</p>
052:              <ul>
053:                <li>{ 'A' digit+ }: [ISO 216] "A" series: Paper and boards, trimmed sizes.</li>
054:                <li>{ 'B' digit+ }: [ISO 216] "B" series: Posters, wall charts and similar items.</li>
055:                <li>{ 'C' digit+ }: [ISO 269] "C" series: Envelopes or folders suitable for A-size
056:                stationery.</li>
057:                <li>{ 'Ansi' letter }: [ANSI/ASME Y14.1] ANSI series: US engineering drawing series.</li>
058:                <li>{ 'Arch' letter }: Architectural series.</li>
059:                <li>{ "Letter", "Legal", "Executive", "Statement", "Tabloid" }: Traditional north-american
060:                sizes.</li>
061:              </ul>
062:             */
063:            public enum SizeEnum {
064:                A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, Letter, Legal, Executive, Statement, Tabloid, ArchA, ArchB, ArchC, ArchD, ArchE, AnsiA, AnsiB, AnsiC, AnsiD, AnsiE
065:            };
066:
067:            /**
068:              Page orientation.
069:             */
070:            public enum OrientationEnum {
071:                Portrait, Landscape
072:            }
073:
074:            // </classes>
075:
076:            // <static>
077:            // <fields>
078:            private static final String IsoSeriesSize_A = "A";
079:            private static final String IsoSeriesSize_B = "B";
080:            private static final String IsoSeriesSize_C = "C";
081:
082:            private static final Pattern IsoSeriesSizePattern = Pattern
083:                    .compile("([" + IsoSeriesSize_A + IsoSeriesSize_B
084:                            + IsoSeriesSize_C + "])([\\d]+)");
085:
086:            // </fields>
087:
088:            // <interface>
089:            // <public>
090:            /**
091:              Gets the default page size.
092:              <h3>Remarks</h3>
093:              <p>The returned dimension corresponds to the widely-established ISO A4 standard paper format,
094:              portrait orientation.</p>
095:             */
096:            public static Dimension getSize() {
097:                return getSize(SizeEnum.A4);
098:            }
099:
100:            /**
101:              Gets the page size of the given format, portrait orientation.
102:              @param size Page size.
103:             */
104:            public static Dimension getSize(SizeEnum size) {
105:                return getSize(size, OrientationEnum.Portrait);
106:            }
107:
108:            /**
109:              Gets the page size of the given format and orientation.
110:              @param size Page size.
111:              @param orientation Page orientation.
112:             */
113:            public static Dimension getSize(SizeEnum size,
114:                    OrientationEnum orientation) {
115:                int width, height = 0;
116:
117:                // Size.
118:                {
119:                    String sizeName = size.name();
120:                    Matcher matcher = IsoSeriesSizePattern.matcher(sizeName);
121:                    // Is it an ISO standard size?
122:                    if (matcher.matches()) {
123:                        int baseWidth, baseHeight = 0;
124:                        String isoSeriesSize = matcher.group(1);
125:                        if (isoSeriesSize.equals(IsoSeriesSize_A)) {
126:                            baseWidth = 2384;
127:                            baseHeight = 3370;
128:                        } else if (isoSeriesSize.equals(IsoSeriesSize_B)) {
129:                            baseWidth = 2834;
130:                            baseHeight = 4008;
131:                        } else if (isoSeriesSize.equals(IsoSeriesSize_C)) {
132:                            baseWidth = 2599;
133:                            baseHeight = 3676;
134:                        } else {
135:                            throw new NotImplementedException("Paper format "
136:                                    + size + " not supported yet.");
137:                        }
138:
139:                        int isoSeriesSizeIndex = Integer.parseInt(matcher
140:                                .group(2));
141:                        double isoSeriesSizeFactor = 1 / Math.pow(2,
142:                                isoSeriesSizeIndex / 2d);
143:
144:                        width = (int) Math.floor(baseWidth
145:                                * isoSeriesSizeFactor);
146:                        height = (int) Math.floor(baseHeight
147:                                * isoSeriesSizeFactor);
148:                    } else // Non-ISO size.
149:                    {
150:                        switch (size) {
151:                        case ArchA:
152:                            width = 648;
153:                            height = 864;
154:                            break;
155:                        case ArchB:
156:                            width = 864;
157:                            height = 1296;
158:                            break;
159:                        case ArchC:
160:                            width = 1296;
161:                            height = 1728;
162:                            break;
163:                        case ArchD:
164:                            width = 1728;
165:                            height = 2592;
166:                            break;
167:                        case ArchE:
168:                            width = 2592;
169:                            height = 3456;
170:                            break;
171:                        case AnsiA:
172:                        case Letter:
173:                            width = 612;
174:                            height = 792;
175:                            break;
176:                        case AnsiB:
177:                        case Tabloid:
178:                            width = 792;
179:                            height = 1224;
180:                            break;
181:                        case AnsiC:
182:                            width = 1224;
183:                            height = 1584;
184:                            break;
185:                        case AnsiD:
186:                            width = 1584;
187:                            height = 2448;
188:                            break;
189:                        case AnsiE:
190:                            width = 2448;
191:                            height = 3168;
192:                            break;
193:                        case Legal:
194:                            width = 612;
195:                            height = 1008;
196:                            break;
197:                        case Executive:
198:                            width = 522;
199:                            height = 756;
200:                            break;
201:                        case Statement:
202:                            width = 396;
203:                            height = 612;
204:                            break;
205:                        default:
206:                            throw new NotImplementedException("Paper format "
207:                                    + size + " not supported yet.");
208:                        }
209:                    }
210:                }
211:
212:                // Orientation.
213:                switch (orientation) {
214:                case Portrait:
215:                    return new Dimension(width, height);
216:                case Landscape:
217:                    return new Dimension(height, width);
218:                default:
219:                    throw new NotImplementedException("Orientation "
220:                            + orientation + " not supported yet.");
221:                }
222:            }
223:
224:            // </public>
225:            // </interface>
226:            // </static>
227:
228:            // <dynamic>
229:            // <constructors>
230:            private PageFormat() {
231:            }
232:            // </constructors>
233:            // </dynamic>
234:            // </class>
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.