Source Code Cross Referenced for PagePrinter.java in  » UML » jrefactory » org » acm » seguin » print » 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 » UML » jrefactory » org.acm.seguin.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.print;
010:
011:        import java.awt.Color;
012:        import java.awt.Font;
013:        import java.awt.FontMetrics;
014:        import java.awt.Graphics;
015:        import java.awt.print.*;
016:        import java.text.DateFormat;
017:        import java.util.Date;
018:        import org.acm.seguin.util.FileSettings;
019:        import org.acm.seguin.util.MissingSettingsException;
020:        import org.acm.seguin.awt.ExceptionPrinter;
021:
022:        /**
023:         *  Handles printing the page
024:         *
025:         *@author     Chris Seguin
026:         *@created    August 8, 1999
027:         */
028:        public abstract class PagePrinter implements  Printable {
029:            private int filenameFontSize = 14;
030:            private int datePageFontSize = 8;
031:
032:            /**
033:             *  Description of the Field
034:             */
035:            protected static int headerHeight = 30;
036:            /**
037:             *  Description of the Field
038:             */
039:            protected static PageFormat pf;
040:            private static double scale = 1.0;
041:
042:            /**
043:             *  Description of the Method
044:             *
045:             *@param  value  Description of Parameter
046:             */
047:            public void setFilenameFontSize(int value) {
048:                filenameFontSize = value;
049:            }
050:
051:            /**
052:             *  Description of the Method
053:             *
054:             *@param  value  Description of Parameter
055:             */
056:            public void setDatePageCountFontSize(int value) {
057:                datePageFontSize = value;
058:            }
059:
060:            /**
061:             *  Prints the header at the top of the page
062:             *
063:             *@param  g           The graphics object
064:             *@param  title       the title
065:             *@param  pageNumber  the number of pages
066:             *@param  pageCount   the page count
067:             */
068:            protected void printHeader(Graphics g, String title,
069:                    String pageNumber, String pageCount) {
070:                //  Draw the frame
071:                int x = (int) pf.getImageableX();
072:                int y = (int) pf.getImageableY();
073:                int wide = (int) pf.getImageableWidth();
074:                int high = headerHeight;
075:                g.setColor(Color.white);
076:                g.fillRect(x, y, wide - 1, high - 1);
077:                g.setColor(Color.black);
078:                g.drawRect(x, y, wide - 1, high - 1);
079:                int quarterWide = wide / 4;
080:                g.drawLine(x + 2 * quarterWide, y, x + 2 * quarterWide, y
081:                        + headerHeight - 1);
082:                g.drawLine(x + 3 * quarterWide, y, x + 3 * quarterWide, y
083:                        + headerHeight - 1);
084:
085:                int centerY = y + headerHeight / 2;
086:
087:                //  Draw the filename
088:                g.setFont(new Font("Serif", Font.BOLD, filenameFontSize));
089:                FontMetrics fm = g.getFontMetrics();
090:                int tempY = y
091:                        + (headerHeight + fm.getAscent() + fm.getDescent()) / 2
092:                        - fm.getDescent();
093:                if ((title != null) && (title.length() > 0)) {
094:                    g.drawString(title, x + 10, tempY);
095:                }
096:
097:                //  Draw the date
098:                g.setFont(new Font("Serif", Font.BOLD, datePageFontSize));
099:                fm = g.getFontMetrics();
100:
101:                String now = DateFormat.getDateTimeInstance()
102:                        .format(new Date());
103:                tempY = y + (headerHeight + fm.getAscent() + fm.getDescent())
104:                        / 2 - fm.getDescent();
105:                g.drawString(now, x + 5 * quarterWide / 2 - fm.stringWidth(now)
106:                        / 2, tempY);
107:
108:                //  Draw the page count
109:                String pages = pageNumber + " of " + pageCount;
110:                g.drawString(pages, x + 7 * quarterWide / 2
111:                        - fm.stringWidth(pages) / 2, tempY);
112:            }
113:
114:            /**
115:             *  Sets the size of the header box
116:             *
117:             *@param  value  The size of the header box
118:             */
119:            public static void setHeaderHeight(int value) {
120:                headerHeight = value;
121:            }
122:
123:            /**
124:             *  Returns the page
125:             *
126:             *@param  dialog  present a dialog screen if none
127:             *@return         the current page format
128:             */
129:            public static PageFormat getPageFormat(boolean dialog) {
130:                if (dialog) {
131:                    PrinterJob job = PrinterJob.getPrinterJob();
132:                    pf = job.pageDialog(job.defaultPage());
133:                }
134:
135:                //  Get the header height
136:                try {
137:                    FileSettings bundle = FileSettings
138:                            .getRefactorySettings("printing");
139:                    setHeaderHeight(Integer.parseInt(bundle
140:                            .getString("header.space")));
141:                } catch (MissingSettingsException mre) {
142:                    ExceptionPrinter.print(mre, true);
143:                } catch (NumberFormatException inf) {
144:                    ExceptionPrinter.print(inf, true);
145:                }
146:
147:                return pf;
148:            }
149:
150:            /**
151:             *  Return the width of the page
152:             *
153:             *@return    Description of the Returned Value
154:             */
155:            public static int getPageWidth() {
156:                if (pf == null) {
157:                    return -1;
158:                }
159:
160:                return (int) (pf.getImageableWidth() / scale);
161:            }
162:
163:            /**
164:             *  Return the width of the page
165:             *
166:             *@return    Description of the Returned Value
167:             */
168:            public static int getPageHeight() {
169:                if (pf == null) {
170:                    return -1;
171:                }
172:
173:                return (int) (pf.getImageableHeight() / scale);
174:            }
175:
176:            /**
177:             *  Sets the scaling
178:             *
179:             *@param  value  the scaled value
180:             */
181:            protected static void setScale(double value) {
182:                scale = value;
183:            }
184:
185:            /**
186:             *  Returns the scaling
187:             *
188:             *@return    The scale size
189:             */
190:            protected static double getScale() {
191:                return scale;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.