Source Code Cross Referenced for PrintablePage.java in  » XML-UI » xui32 » com » xoetrope » 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 » XML UI » xui32 » com.xoetrope.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.print;
002:
003:        import java.awt.Container;
004:        import java.awt.Font;
005:        import java.awt.FontMetrics;
006:        import java.awt.Graphics;
007:        import java.awt.Graphics2D;
008:        import java.awt.print.PageFormat;
009:        import java.awt.print.Printable;
010:        import java.awt.print.PrinterException;
011:        import net.xoetrope.xui.XProject;
012:
013:        import net.xoetrope.xui.XProjectManager;
014:        import net.xoetrope.xui.style.XStyle;
015:
016:        /**
017:         * A decoration of the XPage to allow printing. The class can also support printing in panels or other containers.
018:         *
019:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
020:         * the GNU Public License (GPL), please see license.txt for more details. If
021:         * you make commercial use of this software you must purchase a commercial
022:         * license from Xoetrope.</p>
023:         * <p> $Revision: 1.4 $</p>
024:         */
025:        public class PrintablePage implements  Printable {
026:            /**
027:             * The current page or container being printed
028:             */
029:            protected Container currentPage;
030:            /**
031:             * The PrintOut class to which this printable page belongs
032:             */
033:            protected Printout printout;
034:
035:            /**
036:             * The owner project and the context in which this object operates.
037:             */
038:            protected XProject currentProject = XProjectManager
039:                    .getCurrentProject();
040:
041:            /**
042:             * Create a new printable page
043:             * @param page The page or container to be printed
044:             * @param po The printout that will 'own' the printable page
045:             */
046:            public PrintablePage(Container page, Printout po) {
047:                currentPage = page;
048:                printout = po;
049:            }
050:
051:            /**
052:             * Print the page
053:             * @param g The graphics context
054:             * @param pf the page format
055:             * @param pageIndex the index of the page within the printout page set
056:             * @throws java.awt.print.PrinterException Some printing exception occured
057:             * @return Printable.PAGE_EXISTS on success
058:             */
059:            public int print(Graphics g, PageFormat pf, int pageIndex)
060:                    throws PrinterException {
061:                Font f = currentProject.getStyleManager().getFont("base");
062:                g.setFont(f);
063:                g.setColor(currentProject.getStyleManager().getStyle("base")
064:                        .getStyleAsColor(XStyle.COLOR_FORE));
065:                FontMetrics fm = g.getFontMetrics();
066:
067:                double imageableX = pf.getImageableX();
068:                double imageableY = pf.getImageableY();
069:                double imageableW = pf.getImageableWidth();
070:                double imageableH = pf.getImageableHeight();
071:
072:                Graphics2D g2 = (Graphics2D) g;
073:                int headerHeight = 0, footerHeight = 0;
074:                for (int i = 0; i < 3; i++)
075:                    headerHeight = Math.max(headerHeight, printout
076:                            .printDecoration(g2, pf, true, i, imageableX + i
077:                                    * imageableW / 3.0, imageableY, fm));
078:
079:                for (int i = 0; i < 3; i++)
080:                    footerHeight = Math.max(footerHeight, printout
081:                            .printDecoration(g2, pf, false, i, imageableX + i
082:                                    * imageableW / 3.0, imageableY + imageableH
083:                                    - (headerHeight + footerHeight), fm));
084:
085:                g2.translate(imageableX, imageableY);
086:                g2.setClip(0, 0, currentPage.getWidth(), currentPage
087:                        .getHeight());
088:
089:                // Setup the scaling
090:                double scale;
091:                imageableH -= (headerHeight + footerHeight);
092:                if (pf.getOrientation() == PageFormat.LANDSCAPE)
093:                    scale = imageableH / currentPage.getHeight();
094:                else
095:                    scale = imageableW / currentPage.getWidth();
096:
097:                g2.translate(imageableX, imageableY + headerHeight);
098:                g2.scale(scale, scale);
099:                g2.setClip(0, 0, currentPage.getWidth(), currentPage
100:                        .getHeight());
101:
102:                currentPage.print(g);
103:                currentPage.printComponents(g);
104:
105:                return Printable.PAGE_EXISTS;
106:            }
107:
108:            /**
109:             * Get the page or container wrapped by this class.
110:             * @return the wrapped container
111:             */
112:            public Container getPage() {
113:                return currentPage;
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.