Source Code Cross Referenced for PaperFormat.java in  » Report » datavision-1.1.0 » jimm » datavision » 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 » Report » datavision 1.1.0 » jimm.datavision 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision;
002:
003:        import jimm.util.XMLWriter;
004:        import java.awt.print.Paper;
005:        import java.awt.print.PageFormat;
006:        import java.util.*;
007:
008:        /**
009:         * The class manages lists of paper sizes and instances represents specific
010:         * paper sizes and orientations. Instances are immutable.
011:         *
012:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
013:         */
014:        public class PaperFormat extends Paper implements  Nameable, Writeable {
015:
016:            public static final int PORTRAIT = 0;
017:            public static final int LANDSCAPE = 1;
018:
019:            protected static final String RESOURCE_FILE_PREFIX = "paper";
020:
021:            protected static HashMap[] orientations;
022:            protected static TreeSet names;
023:            protected static PaperFormat defaultPaper;
024:
025:            protected String name; // Immutable
026:            protected int orientation; // PORTRAIT or LANDSCAPE; immutable
027:            protected PageFormat pageFormat;
028:            protected String latexPaperSizeString;
029:
030:            static {
031:                orientations = new HashMap[2];
032:                orientations[PORTRAIT] = new HashMap();
033:                orientations[LANDSCAPE] = new HashMap();
034:                ArrayList nameList = new ArrayList();
035:
036:                ResourceBundle bundle = ResourceBundle.getBundle(
037:                        RESOURCE_FILE_PREFIX, Locale.getDefault());
038:                try {
039:                    int numPaperSizes = Integer.parseInt(bundle
040:                            .getString("num_paper_sizes"));
041:                    for (int i = 0; i < numPaperSizes; ++i) {
042:                        String vals = bundle.getString("paper" + i);
043:                        int pos1 = vals.indexOf(',');
044:                        int pos2 = vals.indexOf(',', pos1 + 1);
045:                        int pos3 = vals.indexOf(',', pos2 + 1);
046:                        int pos4 = vals.indexOf(',', pos3 + 1);
047:                        int pos5 = vals.indexOf(',', pos4 + 1);
048:                        if (pos1 == -1 || pos2 == -1 || pos3 == -1
049:                                || pos4 == -1)
050:                            continue; // pos5 is optional
051:
052:                        double w = Double.parseDouble(vals.substring(pos1 + 1,
053:                                pos2));
054:                        double h = Double.parseDouble(vals.substring(pos2 + 1,
055:                                pos3));
056:                        double hMargin = Double.parseDouble(vals.substring(
057:                                pos3 + 1, pos4));
058:                        double vMargin = 0;
059:                        String latexPaperSizeString = null;
060:                        if (pos5 == -1)
061:                            vMargin = Double.parseDouble(vals
062:                                    .substring(pos4 + 1));
063:                        else {
064:                            vMargin = Double.parseDouble(vals.substring(
065:                                    pos4 + 1, pos5));
066:                            latexPaperSizeString = vals.substring(pos5 + 1);
067:                        }
068:
069:                        String name = vals.substring(0, pos1);
070:                        nameList.add(name);
071:                        PaperFormat p = addPaper(PORTRAIT, name, w, h, hMargin,
072:                                vMargin, latexPaperSizeString);
073:                        addPaper(LANDSCAPE, name, h, w, vMargin, hMargin,
074:                                latexPaperSizeString);
075:                        if (i == 0) // Zero'th one is the default
076:                            defaultPaper = p;
077:                    }
078:                } catch (Exception e) { // Number format exceptions, mostly
079:                    ErrorHandler.error(e);
080:                } finally {
081:                    // Copy list of names to a sorted set
082:                    names = new TreeSet(nameList);
083:                }
084:            }
085:
086:            private static PaperFormat addPaper(int orientation, String name,
087:                    double w, double h, double hMargin, double vMargin,
088:                    String latexPaperSizeString) {
089:                PaperFormat p = new PaperFormat(orientation, name, w, h,
090:                        hMargin, vMargin, latexPaperSizeString);
091:                orientations[orientation].put(name, p);
092:                return p;
093:            }
094:
095:            public static PaperFormat get(int orientation, String name) {
096:                return (PaperFormat) orientations[orientation].get(name);
097:            }
098:
099:            public static PaperFormat getDefault() {
100:                return defaultPaper;
101:            }
102:
103:            public static Iterator names() {
104:                return names.iterator();
105:            }
106:
107:            PaperFormat(int orientation, String name, double w, double h,
108:                    double hMargin, double vMargin, String latexPaperSizeString) {
109:                this .orientation = orientation;
110:                this .name = name;
111:                this .latexPaperSizeString = latexPaperSizeString;
112:                setSize(w, h);
113:                setImageableArea(hMargin, vMargin, w - hMargin / 2.0, h
114:                        - vMargin / 2.0);
115:            }
116:
117:            public int getOrientation() {
118:                return orientation;
119:            }
120:
121:            public String getName() {
122:                return name;
123:            }
124:
125:            /** A paper format's name is immutable. */
126:            public void setName(String name) {
127:            }
128:
129:            public String getLaTeXPaperSizeString() {
130:                return latexPaperSizeString;
131:            }
132:
133:            /**
134:             * Returns a <code>java.awt.print.PageFormat</code> that describes
135:             * our orientation, size, and margins. Used by print jobs.
136:             *
137:             * @return a page format
138:             * @see jimm.datavision.layout.swing.SwingLE#printReport
139:             */
140:            public PageFormat getPageFormat() {
141:                if (pageFormat == null) {
142:                    pageFormat = new PageFormat();
143:                    if (orientation == PORTRAIT) {
144:                        pageFormat.setOrientation(PageFormat.PORTRAIT);
145:                        pageFormat.setPaper(this );
146:                    } else {
147:                        pageFormat.setOrientation(PageFormat.LANDSCAPE);
148:                        // Apparently the paper object given to the page format needs
149:                        // to have the x, w, width, and height values be the same as
150:                        // the portrait values, not rotated.
151:                        pageFormat.setPaper(get(PORTRAIT, getName()));
152:                    }
153:                }
154:                return pageFormat;
155:            }
156:
157:            public void writeXML(XMLWriter out) {
158:                out.startElement("paper");
159:                out.attr("name", name);
160:                out.attr("orientation", orientation == PORTRAIT ? "portrait"
161:                        : "landscape");
162:                out.endElement();
163:            }
164:
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.